@umbraco-cms/mcp-editor 18.0.0-beta.7 → 18.0.0-beta.9
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 +711 -645
- package/dist/collections.js.map +1 -1
- package/dist/index.js +719 -654
- 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
|
|
|
@@ -87,6 +86,12 @@ function extractInnerProblemDetails(result) {
|
|
|
87
86
|
return parsed;
|
|
88
87
|
}
|
|
89
88
|
} catch {
|
|
89
|
+
return {
|
|
90
|
+
type: "Error",
|
|
91
|
+
title: "Chained tool error",
|
|
92
|
+
status: 500,
|
|
93
|
+
detail: `Chained CMS tool returned a non-JSON error: ${text}`
|
|
94
|
+
};
|
|
90
95
|
}
|
|
91
96
|
}
|
|
92
97
|
}
|
|
@@ -97,8 +102,30 @@ function extractInnerProblemDetails(result) {
|
|
|
97
102
|
detail: "Chained CMS tool returned an error with no structured details."
|
|
98
103
|
};
|
|
99
104
|
}
|
|
105
|
+
function truncateAvailableTools(message) {
|
|
106
|
+
const availableToolsIndex = message.indexOf(". Available tools");
|
|
107
|
+
if (availableToolsIndex === -1 || !message.includes("Tool not found:")) {
|
|
108
|
+
return message;
|
|
109
|
+
}
|
|
110
|
+
return message.slice(0, availableToolsIndex + 1);
|
|
111
|
+
}
|
|
100
112
|
async function chainCms(toolName, args) {
|
|
101
|
-
|
|
113
|
+
let result;
|
|
114
|
+
try {
|
|
115
|
+
result = await mcpClientManager.callTool("cms", toolName, args);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
const message = truncateAvailableTools(error instanceof Error ? error.message : String(error));
|
|
118
|
+
console.warn(`Chained CMS tool "${toolName}" failed: ${message}`);
|
|
119
|
+
return {
|
|
120
|
+
ok: false,
|
|
121
|
+
errorResult: createToolResultError({
|
|
122
|
+
type: "Error",
|
|
123
|
+
title: "Chained tool call failed",
|
|
124
|
+
status: 500,
|
|
125
|
+
detail: `Chained CMS tool "${toolName}" failed: ${message}`
|
|
126
|
+
})
|
|
127
|
+
};
|
|
128
|
+
}
|
|
102
129
|
if (result.isError) {
|
|
103
130
|
const inner = extractInnerProblemDetails(result);
|
|
104
131
|
return { ok: false, errorResult: createToolResultError(inner) };
|
|
@@ -443,6 +470,19 @@ var tool3 = {
|
|
|
443
470
|
}
|
|
444
471
|
};
|
|
445
472
|
var list_children_default = withStandardDecorators(tool3);
|
|
473
|
+
|
|
474
|
+
// src/auth/auth-policies.ts
|
|
475
|
+
var sections = {
|
|
476
|
+
settings: "Umb.Section.Settings"};
|
|
477
|
+
|
|
478
|
+
// src/umbraco-api/tools/helpers/settings-access.ts
|
|
479
|
+
async function checkSettingsAccess() {
|
|
480
|
+
const result = await chainCms("get-user-current", {});
|
|
481
|
+
if (!result.ok) return result;
|
|
482
|
+
return { ok: true, hasAccess: result.data.allowedSections?.includes(sections.settings) ?? false };
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// src/umbraco-api/tools/content/get/list-document-types.ts
|
|
446
486
|
var inputSchema4 = {
|
|
447
487
|
take: z.number().optional().default(50).describe("Number of results to return"),
|
|
448
488
|
skip: z.number().optional().default(0).describe("Number of results to skip")
|
|
@@ -465,11 +505,14 @@ async function collectDocumentTypeIds() {
|
|
|
465
505
|
let result;
|
|
466
506
|
while (true) {
|
|
467
507
|
result = parentId ? await chainCms("get-document-type-children", { parentId, cursor }) : await chainCms("get-document-type-root", { cursor });
|
|
468
|
-
if (!result.ok) return;
|
|
508
|
+
if (!result.ok) return { ok: false, errorResult: result.errorResult };
|
|
469
509
|
const items = result.data.items ?? [];
|
|
470
510
|
for (const item of items) {
|
|
471
511
|
if (item.isFolder) {
|
|
472
|
-
if (item.hasChildren)
|
|
512
|
+
if (item.hasChildren) {
|
|
513
|
+
const childResult = await walk(item.id);
|
|
514
|
+
if (childResult && !childResult.ok) return childResult;
|
|
515
|
+
}
|
|
473
516
|
} else {
|
|
474
517
|
collected.push(item);
|
|
475
518
|
}
|
|
@@ -478,26 +521,35 @@ async function collectDocumentTypeIds() {
|
|
|
478
521
|
if (!nextCursor) break;
|
|
479
522
|
cursor = nextCursor;
|
|
480
523
|
}
|
|
524
|
+
return void 0;
|
|
481
525
|
}
|
|
482
|
-
await walk(void 0);
|
|
483
|
-
return
|
|
526
|
+
const failure = await walk(void 0);
|
|
527
|
+
if (failure && !failure.ok) return failure;
|
|
528
|
+
return { ok: true, nodes: collected };
|
|
484
529
|
}
|
|
485
530
|
async function resolveDocTypeDetails(nodes) {
|
|
486
531
|
const results = await Promise.all(
|
|
487
532
|
nodes.map(async (node) => {
|
|
488
533
|
const detailResult = await chainCms("get-document-type-by-id", { id: node.id });
|
|
489
|
-
if (!detailResult.ok) return
|
|
534
|
+
if (!detailResult.ok) return { ok: false, errorResult: detailResult.errorResult, node };
|
|
490
535
|
const d = detailResult.data;
|
|
491
536
|
return {
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
537
|
+
ok: true,
|
|
538
|
+
details: [{
|
|
539
|
+
id: node.id,
|
|
540
|
+
alias: d.alias ?? "",
|
|
541
|
+
name: d.name ?? node.name,
|
|
542
|
+
description: d.description ?? void 0,
|
|
543
|
+
icon: d.icon ?? node.icon
|
|
544
|
+
}],
|
|
545
|
+
node
|
|
497
546
|
};
|
|
498
547
|
})
|
|
499
548
|
);
|
|
500
|
-
|
|
549
|
+
const failed = results.find((r) => !r.ok);
|
|
550
|
+
if (failed && !failed.ok) return { ok: false, errorResult: failed.errorResult };
|
|
551
|
+
const details = results.flatMap((r) => r.ok ? r.details : []);
|
|
552
|
+
return { ok: true, details };
|
|
501
553
|
}
|
|
502
554
|
var tool4 = {
|
|
503
555
|
name: "list-document-types",
|
|
@@ -507,9 +559,22 @@ var tool4 = {
|
|
|
507
559
|
slices: ["list"],
|
|
508
560
|
annotations: { readOnlyHint: true },
|
|
509
561
|
handler: async ({ take, skip }) => {
|
|
510
|
-
const
|
|
562
|
+
const accessCheck = await checkSettingsAccess();
|
|
563
|
+
if (!accessCheck.ok) return accessCheck.errorResult;
|
|
564
|
+
if (!accessCheck.hasAccess) {
|
|
565
|
+
return createToolResultError({
|
|
566
|
+
status: 403,
|
|
567
|
+
title: "Settings access required",
|
|
568
|
+
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."
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
const treeResult = await collectDocumentTypeIds();
|
|
572
|
+
if (!treeResult.ok) return treeResult.errorResult;
|
|
573
|
+
const { nodes } = treeResult;
|
|
511
574
|
const sliced = nodes.slice(skip, skip + take);
|
|
512
|
-
const
|
|
575
|
+
const detailsResult = await resolveDocTypeDetails(sliced);
|
|
576
|
+
if (!detailsResult.ok) return detailsResult.errorResult;
|
|
577
|
+
const { details } = detailsResult;
|
|
513
578
|
return createToolResult({
|
|
514
579
|
items: details.map((d) => ({
|
|
515
580
|
id: d.id,
|
|
@@ -523,6 +588,73 @@ var tool4 = {
|
|
|
523
588
|
}
|
|
524
589
|
};
|
|
525
590
|
var list_document_types_default = withStandardDecorators(tool4);
|
|
591
|
+
|
|
592
|
+
// src/umbraco-api/tools/content/helpers/resolve-document-type-properties.ts
|
|
593
|
+
async function resolveDocumentTypeProperties(documentTypeId) {
|
|
594
|
+
const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
|
|
595
|
+
if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
|
|
596
|
+
const data = docTypeResult.data;
|
|
597
|
+
const collected = /* @__PURE__ */ new Map();
|
|
598
|
+
function addProperties(props) {
|
|
599
|
+
for (const p of props) {
|
|
600
|
+
if (p.alias && !collected.has(p.alias)) {
|
|
601
|
+
collected.set(p.alias, p);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
function compositionIdsOf(d) {
|
|
606
|
+
return Array.from(
|
|
607
|
+
new Set(
|
|
608
|
+
(d.compositions ?? []).map((c) => c.documentType?.id).filter((id) => typeof id === "string")
|
|
609
|
+
)
|
|
610
|
+
);
|
|
611
|
+
}
|
|
612
|
+
function describeFailure(errorResult) {
|
|
613
|
+
const text = errorResult.content?.[0]?.type === "text" ? errorResult.content[0].text : void 0;
|
|
614
|
+
if (!text) return "unknown error";
|
|
615
|
+
try {
|
|
616
|
+
const parsed = JSON.parse(text);
|
|
617
|
+
const detail = parsed?.detail;
|
|
618
|
+
return typeof detail === "string" ? detail : text;
|
|
619
|
+
} catch {
|
|
620
|
+
return text;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
addProperties(Array.isArray(data.properties) ? data.properties : []);
|
|
624
|
+
const visited = /* @__PURE__ */ new Set([documentTypeId]);
|
|
625
|
+
const failedCompositionIds = [];
|
|
626
|
+
const failedCompositionDetails = [];
|
|
627
|
+
let frontier = compositionIdsOf(data).filter((id) => !visited.has(id));
|
|
628
|
+
frontier.forEach((id) => visited.add(id));
|
|
629
|
+
while (frontier.length > 0) {
|
|
630
|
+
const results = await Promise.all(frontier.map((id) => chainCms("get-document-type-by-id", { id })));
|
|
631
|
+
const nextFrontier = [];
|
|
632
|
+
results.forEach((r, i) => {
|
|
633
|
+
if (!r.ok) {
|
|
634
|
+
failedCompositionIds.push(frontier[i]);
|
|
635
|
+
failedCompositionDetails.push(describeFailure(r.errorResult));
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
if (Array.isArray(r.data.properties)) addProperties(r.data.properties);
|
|
639
|
+
for (const id of compositionIdsOf(r.data)) {
|
|
640
|
+
if (!visited.has(id)) {
|
|
641
|
+
visited.add(id);
|
|
642
|
+
nextFrontier.push(id);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
});
|
|
646
|
+
frontier = nextFrontier;
|
|
647
|
+
}
|
|
648
|
+
return {
|
|
649
|
+
ok: true,
|
|
650
|
+
documentType: data,
|
|
651
|
+
properties: Array.from(collected.values()),
|
|
652
|
+
failedCompositionIds,
|
|
653
|
+
failedCompositionDetails
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// src/umbraco-api/tools/content/get/get-document-type.ts
|
|
526
658
|
var inputSchema5 = {
|
|
527
659
|
id: z.string().uuid().describe("UUID of the document type to retrieve")
|
|
528
660
|
};
|
|
@@ -550,30 +682,9 @@ var tool5 = {
|
|
|
550
682
|
slices: ["read"],
|
|
551
683
|
annotations: { readOnlyHint: true },
|
|
552
684
|
handler: async ({ id }) => {
|
|
553
|
-
const result = await
|
|
685
|
+
const result = await resolveDocumentTypeProperties(id);
|
|
554
686
|
if (!result.ok) return result.errorResult;
|
|
555
|
-
const data = result
|
|
556
|
-
const collected = /* @__PURE__ */ new Map();
|
|
557
|
-
function addProperties(props) {
|
|
558
|
-
for (const p of props) {
|
|
559
|
-
if (p.alias && !collected.has(p.alias)) {
|
|
560
|
-
collected.set(p.alias, p);
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
addProperties(Array.isArray(data.properties) ? data.properties : []);
|
|
565
|
-
const compositionIds = (data.compositions ?? []).map((c) => c.document?.id ?? c.documentType?.id ?? c.id).filter((cid) => typeof cid === "string");
|
|
566
|
-
if (compositionIds.length > 0) {
|
|
567
|
-
const compositions = await Promise.all(
|
|
568
|
-
compositionIds.map(async (cid) => {
|
|
569
|
-
const r = await chainCms("get-document-type-by-id", { id: cid });
|
|
570
|
-
return r.ok ? r.data : null;
|
|
571
|
-
})
|
|
572
|
-
);
|
|
573
|
-
for (const comp of compositions) {
|
|
574
|
-
if (comp && Array.isArray(comp.properties)) addProperties(comp.properties);
|
|
575
|
-
}
|
|
576
|
-
}
|
|
687
|
+
const { documentType: data, properties } = result;
|
|
577
688
|
return createToolResult({
|
|
578
689
|
id: data.id ?? id,
|
|
579
690
|
alias: data.alias ?? "",
|
|
@@ -581,7 +692,7 @@ var tool5 = {
|
|
|
581
692
|
description: data.description || void 0,
|
|
582
693
|
variesByCulture: data.variesByCulture || void 0,
|
|
583
694
|
variesBySegment: data.variesBySegment || void 0,
|
|
584
|
-
properties:
|
|
695
|
+
properties: properties.map((p) => ({
|
|
585
696
|
alias: p.alias ?? "",
|
|
586
697
|
name: p.name ?? p.alias ?? "",
|
|
587
698
|
description: p.description || void 0,
|
|
@@ -593,49 +704,193 @@ var tool5 = {
|
|
|
593
704
|
}
|
|
594
705
|
};
|
|
595
706
|
var get_document_type_default = withStandardDecorators(tool5);
|
|
707
|
+
var validationErrorSchema = z.object({
|
|
708
|
+
propertyAlias: z.string().describe(
|
|
709
|
+
"The alias of the property that failed validation, or '__document__' for document-level errors (mandatory cultures, name length, etc.)."
|
|
710
|
+
),
|
|
711
|
+
culture: z.string().nullable().optional().describe("Culture for variant content. Null for invariant."),
|
|
712
|
+
segment: z.string().nullable().optional().describe("Segment for segmented content. Null when none."),
|
|
713
|
+
message: z.string().describe("Human-readable validation error message.")
|
|
714
|
+
});
|
|
715
|
+
var validationResultSchema = z.object({
|
|
716
|
+
valid: z.boolean().describe("True when the saved document passes server-side validation and is publishable."),
|
|
717
|
+
errors: z.array(validationErrorSchema).describe(
|
|
718
|
+
"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."
|
|
719
|
+
)
|
|
720
|
+
}).describe(
|
|
721
|
+
"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."
|
|
722
|
+
);
|
|
723
|
+
async function validateDocumentState(id, doc) {
|
|
724
|
+
let target = null;
|
|
725
|
+
if (!target) {
|
|
726
|
+
const docResult = await chainCms("get-document-by-id", { id });
|
|
727
|
+
if (!docResult.ok) {
|
|
728
|
+
return {
|
|
729
|
+
valid: false,
|
|
730
|
+
errors: [
|
|
731
|
+
{
|
|
732
|
+
propertyAlias: "__document__",
|
|
733
|
+
message: "Could not refetch document to run validation."
|
|
734
|
+
}
|
|
735
|
+
]
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
target = docResult.data;
|
|
739
|
+
}
|
|
740
|
+
const values = (target.values ?? []).map((v) => ({
|
|
741
|
+
alias: v.alias,
|
|
742
|
+
value: v.value,
|
|
743
|
+
culture: v.culture ?? null,
|
|
744
|
+
segment: v.segment ?? null
|
|
745
|
+
}));
|
|
746
|
+
const variants = (target.variants ?? []).map((v) => ({
|
|
747
|
+
name: v.name,
|
|
748
|
+
culture: v.culture ?? null,
|
|
749
|
+
segment: v.segment ?? null
|
|
750
|
+
}));
|
|
751
|
+
const itemResult = await chainCms("get-item-document", { id: [id] });
|
|
752
|
+
const parent = itemResult.ok ? itemResult.data.items[0]?.parent ?? null : null;
|
|
753
|
+
const result = await chainCms("validate-document", {
|
|
754
|
+
id,
|
|
755
|
+
documentType: { id: target.documentType.id },
|
|
756
|
+
template: target.template ? { id: target.template.id } : null,
|
|
757
|
+
parent: parent ? { id: parent.id } : null,
|
|
758
|
+
values,
|
|
759
|
+
variants
|
|
760
|
+
});
|
|
761
|
+
if (result.ok) {
|
|
762
|
+
return { valid: true, errors: [] };
|
|
763
|
+
}
|
|
764
|
+
return { valid: false, errors: parseValidationErrors(result.errorResult, values) };
|
|
765
|
+
}
|
|
766
|
+
function parseValidationErrors(errorResult, requestValues) {
|
|
767
|
+
const structured = extractStructured(errorResult);
|
|
768
|
+
if (!structured) {
|
|
769
|
+
return [
|
|
770
|
+
{
|
|
771
|
+
propertyAlias: "__document__",
|
|
772
|
+
message: stringifyErrorFallback(errorResult)
|
|
773
|
+
}
|
|
774
|
+
];
|
|
775
|
+
}
|
|
776
|
+
const errors = structured.errors;
|
|
777
|
+
if (!errors || typeof errors !== "object") {
|
|
778
|
+
return [
|
|
779
|
+
{
|
|
780
|
+
propertyAlias: "__document__",
|
|
781
|
+
message: stringifyFromProblemDetails(structured)
|
|
782
|
+
}
|
|
783
|
+
];
|
|
784
|
+
}
|
|
785
|
+
const out = [];
|
|
786
|
+
for (const [jsonPath, messages] of Object.entries(errors)) {
|
|
787
|
+
const messageList = Array.isArray(messages) ? messages : [String(messages)];
|
|
788
|
+
const resolved = resolveJsonPath(jsonPath, requestValues);
|
|
789
|
+
for (const message of messageList) {
|
|
790
|
+
out.push({
|
|
791
|
+
propertyAlias: resolved.propertyAlias,
|
|
792
|
+
culture: resolved.culture,
|
|
793
|
+
segment: resolved.segment,
|
|
794
|
+
message: String(message)
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
if (out.length === 0) {
|
|
799
|
+
out.push({
|
|
800
|
+
propertyAlias: "__document__",
|
|
801
|
+
message: stringifyFromProblemDetails(structured)
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
return out;
|
|
805
|
+
}
|
|
806
|
+
var VALUES_PATH = /^\$\.values\[(\d+)\](?:\.value)?(.*)$/;
|
|
807
|
+
function resolveJsonPath(jsonPath, requestValues) {
|
|
808
|
+
const match = jsonPath.match(VALUES_PATH);
|
|
809
|
+
if (match) {
|
|
810
|
+
const index = Number(match[1]);
|
|
811
|
+
const entry = requestValues[index];
|
|
812
|
+
if (entry) {
|
|
813
|
+
const trailing = match[2]?.replace(/^\./, "");
|
|
814
|
+
return {
|
|
815
|
+
propertyAlias: trailing ? `${entry.alias}${match[2]}` : entry.alias,
|
|
816
|
+
culture: entry.culture,
|
|
817
|
+
segment: entry.segment
|
|
818
|
+
};
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
return { propertyAlias: jsonPath, culture: null, segment: null };
|
|
822
|
+
}
|
|
823
|
+
function extractStructured(errorResult) {
|
|
824
|
+
if (!errorResult || typeof errorResult !== "object") return null;
|
|
825
|
+
const r = errorResult;
|
|
826
|
+
if (r.structuredContent && typeof r.structuredContent === "object") {
|
|
827
|
+
return r.structuredContent;
|
|
828
|
+
}
|
|
829
|
+
const text = r.content?.find((c) => c?.type === "text")?.text;
|
|
830
|
+
if (text) {
|
|
831
|
+
try {
|
|
832
|
+
const parsed = JSON.parse(text);
|
|
833
|
+
if (parsed && typeof parsed === "object") {
|
|
834
|
+
return parsed;
|
|
835
|
+
}
|
|
836
|
+
} catch {
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
return null;
|
|
840
|
+
}
|
|
841
|
+
function stringifyFromProblemDetails(pd) {
|
|
842
|
+
if (pd.detail && typeof pd.detail === "string") return pd.detail;
|
|
843
|
+
if (pd.title && typeof pd.title === "string") return pd.title;
|
|
844
|
+
return "Document failed validation but no detail was returned.";
|
|
845
|
+
}
|
|
846
|
+
function stringifyErrorFallback(errorResult) {
|
|
847
|
+
if (!errorResult || typeof errorResult !== "object") return "Document failed validation.";
|
|
848
|
+
const r = errorResult;
|
|
849
|
+
const text = r.content?.find((c) => c?.type === "text")?.text;
|
|
850
|
+
return text ? text : "Document failed validation.";
|
|
851
|
+
}
|
|
596
852
|
|
|
597
853
|
// src/umbraco-api/tools/helpers/block-builder.ts
|
|
598
|
-
async function
|
|
599
|
-
|
|
854
|
+
async function toBlockProperties(elementTypeKey, values, culture, segment) {
|
|
855
|
+
if (values.length === 0) return { ok: true, properties: [] };
|
|
856
|
+
const docTypeResult = await chainCms("get-document-type-by-id", { id: elementTypeKey });
|
|
600
857
|
if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
|
|
601
|
-
const
|
|
602
|
-
if (dataTypeIds.length === 0) {
|
|
603
|
-
return { ok: true, editorAliasByAlias: /* @__PURE__ */ new Map() };
|
|
604
|
-
}
|
|
605
|
-
const dataTypesResult = await chainCms("get-data-types-by-id-array", { id: dataTypeIds });
|
|
606
|
-
if (!dataTypesResult.ok) return { ok: false, errorResult: dataTypesResult.errorResult };
|
|
607
|
-
const editorAliasByDataTypeId = new Map(
|
|
608
|
-
dataTypesResult.data.items.map((dt) => [dt.id, dt.editorAlias])
|
|
609
|
-
);
|
|
610
|
-
const editorAliasByAlias = /* @__PURE__ */ new Map();
|
|
611
|
-
for (const prop of docTypeResult.data.properties) {
|
|
612
|
-
const editorAlias = editorAliasByDataTypeId.get(prop.dataType.id);
|
|
613
|
-
if (editorAlias) editorAliasByAlias.set(prop.alias, editorAlias);
|
|
614
|
-
}
|
|
615
|
-
return { ok: true, editorAliasByAlias };
|
|
616
|
-
}
|
|
617
|
-
function buildBlockEntry(contentKey, contentTypeKey, values, editorAliasByAlias, culture, segment) {
|
|
858
|
+
const definitions = new Map(docTypeResult.data.properties.map((p) => [p.alias, p]));
|
|
618
859
|
return {
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
860
|
+
ok: true,
|
|
861
|
+
properties: values.map((v) => {
|
|
862
|
+
const def = definitions.get(v.alias);
|
|
863
|
+
return {
|
|
864
|
+
alias: v.alias,
|
|
865
|
+
value: v.value,
|
|
866
|
+
culture: def?.variesByCulture ? culture : null,
|
|
867
|
+
segment: def?.variesBySegment ? segment : null
|
|
868
|
+
};
|
|
869
|
+
})
|
|
628
870
|
};
|
|
629
871
|
}
|
|
630
|
-
function
|
|
631
|
-
|
|
632
|
-
if (
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
872
|
+
async function toNewBlockProperties(contentTypeKey, values, settingsTypeKey, settingsValues, culture, segment) {
|
|
873
|
+
const content = await toBlockProperties(contentTypeKey, values, culture, segment);
|
|
874
|
+
if (!content.ok) return content;
|
|
875
|
+
if (!settingsTypeKey || !settingsValues) return { ok: true, properties: content.properties };
|
|
876
|
+
const settings = await toBlockProperties(settingsTypeKey, settingsValues, culture, segment);
|
|
877
|
+
if (!settings.ok) return settings;
|
|
878
|
+
return { ok: true, properties: content.properties, settings: { properties: settings.properties } };
|
|
879
|
+
}
|
|
880
|
+
function toPlacement(position) {
|
|
881
|
+
return position.mode === "before" || position.mode === "after" ? { position: position.mode, contentKey: position.anchorContentKey } : { position: position.mode };
|
|
882
|
+
}
|
|
883
|
+
async function buildBlockWriteResult(id, pageName, contentKey, baseMessage) {
|
|
884
|
+
const validation = await validateDocumentState(id);
|
|
885
|
+
const message = validation.valid ? baseMessage : `${baseMessage} \u2014 but ${validation.errors.length} validation error(s) must be resolved before this page can be published`;
|
|
886
|
+
return createToolResult({
|
|
887
|
+
message,
|
|
888
|
+
id,
|
|
889
|
+
name: pageName,
|
|
890
|
+
contentKey,
|
|
891
|
+
previewUrl: await fetchPreviewUrl(id),
|
|
892
|
+
validation
|
|
893
|
+
});
|
|
639
894
|
}
|
|
640
895
|
function isBlockListOrGridValue(value) {
|
|
641
896
|
return value !== null && typeof value === "object" && !Array.isArray(value) && Array.isArray(value.contentData);
|
|
@@ -643,18 +898,6 @@ function isBlockListOrGridValue(value) {
|
|
|
643
898
|
function isRteWithBlocks(value) {
|
|
644
899
|
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);
|
|
645
900
|
}
|
|
646
|
-
function exposeEntry(contentKey, culture, segment) {
|
|
647
|
-
return { contentKey, culture, segment };
|
|
648
|
-
}
|
|
649
|
-
function removeBlockFromContainer(container, contentKey, layoutKey, newLayoutList, doomedSettingsKey) {
|
|
650
|
-
return {
|
|
651
|
-
...container,
|
|
652
|
-
layout: { ...container.layout ?? {}, [layoutKey]: [...newLayoutList] },
|
|
653
|
-
contentData: (container.contentData ?? []).filter((entry) => entry.key !== contentKey),
|
|
654
|
-
settingsData: doomedSettingsKey ? (container.settingsData ?? []).filter((entry) => entry.key !== doomedSettingsKey) : container.settingsData ?? [],
|
|
655
|
-
expose: (container.expose ?? []).filter((entry) => entry.contentKey !== contentKey)
|
|
656
|
-
};
|
|
657
|
-
}
|
|
658
901
|
|
|
659
902
|
// src/umbraco-api/tools/helpers/block-inspector.ts
|
|
660
903
|
function blockPropertiesSchema(editTool) {
|
|
@@ -717,12 +960,82 @@ function collectBlockProperties(values, propertyAlias) {
|
|
|
717
960
|
};
|
|
718
961
|
});
|
|
719
962
|
}
|
|
963
|
+
var MAX_ENRICHED_BLOCKS = 50;
|
|
964
|
+
var MAX_BLOCK_WALK_DEPTH = 20;
|
|
965
|
+
function enrichBlockNotFoundError(errorResult, values, options = {}) {
|
|
966
|
+
const problem = extractInnerProblemDetails(errorResult);
|
|
967
|
+
const availableBlocks = problem.availableBlocks;
|
|
968
|
+
if (!Array.isArray(availableBlocks)) return errorResult;
|
|
969
|
+
const { propertyAlias, note } = options;
|
|
970
|
+
const filtered = propertyAlias ? values.filter((v) => v.alias === propertyAlias) : values;
|
|
971
|
+
const typeByKey = /* @__PURE__ */ new Map();
|
|
972
|
+
for (const v of filtered) {
|
|
973
|
+
const container = isRteWithBlocks(v.value) ? v.value.blocks : v.value;
|
|
974
|
+
if (isBlockListOrGridValue(container)) {
|
|
975
|
+
collectBlockEntryTypes(container, typeByKey, 0);
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
const truncated = availableBlocks.length > MAX_ENRICHED_BLOCKS;
|
|
979
|
+
const limitedBlocks = truncated ? availableBlocks.slice(0, MAX_ENRICHED_BLOCKS) : availableBlocks;
|
|
980
|
+
const enrichedBlocks = limitedBlocks.map(
|
|
981
|
+
(b) => b && typeof b === "object" && typeof b.key === "string" ? { ...b, contentTypeKey: typeByKey.get(b.key) ?? null } : b
|
|
982
|
+
);
|
|
983
|
+
return createToolResultError({
|
|
984
|
+
...problem,
|
|
985
|
+
availableBlocks: enrichedBlocks,
|
|
986
|
+
...truncated ? { availableBlocksNote: `Showing ${MAX_ENRICHED_BLOCKS} of ${availableBlocks.length} available blocks \u2014 use inspect-blocks for the full list.` } : {},
|
|
987
|
+
...note ? { note } : {}
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
function collectBlockEntryTypes(container, into, depth) {
|
|
991
|
+
if (depth > MAX_BLOCK_WALK_DEPTH) return;
|
|
992
|
+
for (const list of [container.contentData, container.settingsData]) {
|
|
993
|
+
if (!Array.isArray(list)) continue;
|
|
994
|
+
for (const block of list) {
|
|
995
|
+
if (!block || typeof block !== "object") continue;
|
|
996
|
+
const key = block.key;
|
|
997
|
+
const contentTypeKey = block.contentTypeKey;
|
|
998
|
+
if (typeof key === "string" && typeof contentTypeKey === "string") into.set(key, contentTypeKey);
|
|
999
|
+
const nestedValues = block.values;
|
|
1000
|
+
if (!Array.isArray(nestedValues)) continue;
|
|
1001
|
+
for (const nested of nestedValues) {
|
|
1002
|
+
const nestedRaw = nested?.value;
|
|
1003
|
+
const nestedContainer = isRteWithBlocks(nestedRaw) ? nestedRaw.blocks : nestedRaw;
|
|
1004
|
+
if (isBlockListOrGridValue(nestedContainer)) {
|
|
1005
|
+
collectBlockEntryTypes(nestedContainer, into, depth + 1);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
720
1011
|
function withSettingsKeys(blocks, container) {
|
|
721
1012
|
return blocks.map((block) => {
|
|
722
1013
|
const settingsKey = findSettingsKey(container, block.contentKey);
|
|
723
1014
|
return settingsKey ? { ...block, settingsKey } : block;
|
|
724
1015
|
});
|
|
725
1016
|
}
|
|
1017
|
+
var blockPropertyAliasSchema = z.string().regex(
|
|
1018
|
+
/^[A-Za-z_][A-Za-z0-9_]*$/,
|
|
1019
|
+
"Property alias must be a valid identifier (letters, digits, underscore; not starting with a digit)"
|
|
1020
|
+
);
|
|
1021
|
+
function classifyBlockUpdateResults(results, requestedCount, requestedAliases = [], expectedEntryCount = 1) {
|
|
1022
|
+
const list = results ?? [];
|
|
1023
|
+
const processedCount = list.reduce((sum, r) => sum + (r.updatedCount ?? 0) + (r.addedCount ?? 0), 0);
|
|
1024
|
+
const updatedEntryCount = list.filter((r) => (r.updatedCount ?? 0) + (r.addedCount ?? 0) > 0).length;
|
|
1025
|
+
const errors = list.flatMap((r) => r.errors ?? []);
|
|
1026
|
+
const warnings = list.flatMap((r) => r.warnings ?? []);
|
|
1027
|
+
const failureText = [...errors, ...warnings].join("; ");
|
|
1028
|
+
const unresolvedEntries = list.filter(
|
|
1029
|
+
(r) => (r.updatedCount ?? 0) + (r.addedCount ?? 0) === 0 && !r.errors?.length && !r.warnings?.length
|
|
1030
|
+
);
|
|
1031
|
+
const missingEntryCount = Math.max(0, expectedEntryCount - list.length);
|
|
1032
|
+
const unresolvedBlockCount = unresolvedEntries.length + missingEntryCount;
|
|
1033
|
+
const detail = [...errors, ...warnings, ...unresolvedEntries.map((r) => r.message).filter(Boolean)].join("; ") || list.map((r) => r.message).filter(Boolean).join("; ") || "no detail returned";
|
|
1034
|
+
const outcome = processedCount === 0 ? "failed" : processedCount < requestedCount ? "partial" : "clean";
|
|
1035
|
+
const failedFields = requestedAliases.filter((alias) => failureText.includes(`'${alias}'`));
|
|
1036
|
+
const savedFields = unresolvedBlockCount > 0 ? [] : requestedAliases.filter((alias) => !failedFields.includes(alias));
|
|
1037
|
+
return { outcome, processedCount, updatedEntryCount, detail, warnings, savedFields, failedFields, unresolvedBlockCount };
|
|
1038
|
+
}
|
|
726
1039
|
|
|
727
1040
|
// src/umbraco-api/tools/content/get/inspect-blocks.ts
|
|
728
1041
|
var inputSchema6 = {
|
|
@@ -1069,166 +1382,92 @@ var tool10 = {
|
|
|
1069
1382
|
${aliases.join("\n")}`
|
|
1070
1383
|
});
|
|
1071
1384
|
}
|
|
1072
|
-
const match = findResult.data.items[0];
|
|
1073
|
-
if (!match) {
|
|
1074
|
-
return createToolResultError({
|
|
1075
|
-
detail: `No data type found with editorAlias "${editorAlias}".`
|
|
1076
|
-
});
|
|
1077
|
-
}
|
|
1078
|
-
const schemaResult = await chainCms("get-data-type-schema", { id: match.id });
|
|
1079
|
-
if (!schemaResult.ok) return schemaResult.errorResult;
|
|
1080
|
-
return createToolResult({
|
|
1081
|
-
message: `Value-shape template for ${editorAlias}:
|
|
1082
|
-
${JSON.stringify(schemaResult.data, null, 2)}`,
|
|
1083
|
-
editorAlias
|
|
1084
|
-
});
|
|
1085
|
-
}
|
|
1086
|
-
};
|
|
1087
|
-
var get_property_value_template_default = withStandardDecorators(tool10);
|
|
1088
|
-
var validationErrorSchema = z.object({
|
|
1089
|
-
propertyAlias: z.string().describe(
|
|
1090
|
-
"The alias of the property that failed validation, or '__document__' for document-level errors (mandatory cultures, name length, etc.)."
|
|
1091
|
-
),
|
|
1092
|
-
culture: z.string().nullable().optional().describe("Culture for variant content. Null for invariant."),
|
|
1093
|
-
segment: z.string().nullable().optional().describe("Segment for segmented content. Null when none."),
|
|
1094
|
-
message: z.string().describe("Human-readable validation error message.")
|
|
1095
|
-
});
|
|
1096
|
-
var validationResultSchema = z.object({
|
|
1097
|
-
valid: z.boolean().describe("True when the saved document passes server-side validation and is publishable."),
|
|
1098
|
-
errors: z.array(validationErrorSchema).describe(
|
|
1099
|
-
"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."
|
|
1100
|
-
)
|
|
1101
|
-
}).describe(
|
|
1102
|
-
"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."
|
|
1103
|
-
);
|
|
1104
|
-
async function validateDocumentState(id, doc) {
|
|
1105
|
-
let target = null;
|
|
1106
|
-
if (!target) {
|
|
1107
|
-
const docResult = await chainCms("get-document-by-id", { id });
|
|
1108
|
-
if (!docResult.ok) {
|
|
1109
|
-
return {
|
|
1110
|
-
valid: false,
|
|
1111
|
-
errors: [
|
|
1112
|
-
{
|
|
1113
|
-
propertyAlias: "__document__",
|
|
1114
|
-
message: "Could not refetch document to run validation."
|
|
1115
|
-
}
|
|
1116
|
-
]
|
|
1117
|
-
};
|
|
1118
|
-
}
|
|
1119
|
-
target = docResult.data;
|
|
1120
|
-
}
|
|
1121
|
-
const values = (target.values ?? []).map((v) => ({
|
|
1122
|
-
alias: v.alias,
|
|
1123
|
-
value: v.value,
|
|
1124
|
-
culture: v.culture ?? null,
|
|
1125
|
-
segment: v.segment ?? null
|
|
1126
|
-
}));
|
|
1127
|
-
const variants = (target.variants ?? []).map((v) => ({
|
|
1128
|
-
name: v.name,
|
|
1129
|
-
culture: v.culture ?? null,
|
|
1130
|
-
segment: v.segment ?? null
|
|
1131
|
-
}));
|
|
1132
|
-
const itemResult = await chainCms("get-item-document", { id: [id] });
|
|
1133
|
-
const parent = itemResult.ok ? itemResult.data.items[0]?.parent ?? null : null;
|
|
1134
|
-
const result = await chainCms("validate-document", {
|
|
1135
|
-
id,
|
|
1136
|
-
documentType: { id: target.documentType.id },
|
|
1137
|
-
template: target.template ? { id: target.template.id } : null,
|
|
1138
|
-
parent: parent ? { id: parent.id } : null,
|
|
1139
|
-
values,
|
|
1140
|
-
variants
|
|
1141
|
-
});
|
|
1142
|
-
if (result.ok) {
|
|
1143
|
-
return { valid: true, errors: [] };
|
|
1144
|
-
}
|
|
1145
|
-
return { valid: false, errors: parseValidationErrors(result.errorResult, values) };
|
|
1146
|
-
}
|
|
1147
|
-
function parseValidationErrors(errorResult, requestValues) {
|
|
1148
|
-
const structured = extractStructured(errorResult);
|
|
1149
|
-
if (!structured) {
|
|
1150
|
-
return [
|
|
1151
|
-
{
|
|
1152
|
-
propertyAlias: "__document__",
|
|
1153
|
-
message: stringifyErrorFallback(errorResult)
|
|
1154
|
-
}
|
|
1155
|
-
];
|
|
1156
|
-
}
|
|
1157
|
-
const errors = structured.errors;
|
|
1158
|
-
if (!errors || typeof errors !== "object") {
|
|
1159
|
-
return [
|
|
1160
|
-
{
|
|
1161
|
-
propertyAlias: "__document__",
|
|
1162
|
-
message: stringifyFromProblemDetails(structured)
|
|
1163
|
-
}
|
|
1164
|
-
];
|
|
1165
|
-
}
|
|
1166
|
-
const out = [];
|
|
1167
|
-
for (const [jsonPath, messages] of Object.entries(errors)) {
|
|
1168
|
-
const messageList = Array.isArray(messages) ? messages : [String(messages)];
|
|
1169
|
-
const resolved = resolveJsonPath(jsonPath, requestValues);
|
|
1170
|
-
for (const message of messageList) {
|
|
1171
|
-
out.push({
|
|
1172
|
-
propertyAlias: resolved.propertyAlias,
|
|
1173
|
-
culture: resolved.culture,
|
|
1174
|
-
segment: resolved.segment,
|
|
1175
|
-
message: String(message)
|
|
1385
|
+
const match = findResult.data.items[0];
|
|
1386
|
+
if (!match) {
|
|
1387
|
+
return createToolResultError({
|
|
1388
|
+
detail: `No data type found with editorAlias "${editorAlias}".`
|
|
1176
1389
|
});
|
|
1177
1390
|
}
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1391
|
+
const schemaResult = await chainCms("get-data-type-schema", { id: match.id });
|
|
1392
|
+
if (!schemaResult.ok) return schemaResult.errorResult;
|
|
1393
|
+
return createToolResult({
|
|
1394
|
+
message: `Value-shape template for ${editorAlias}:
|
|
1395
|
+
${JSON.stringify(schemaResult.data, null, 2)}`,
|
|
1396
|
+
editorAlias
|
|
1183
1397
|
});
|
|
1184
1398
|
}
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1399
|
+
};
|
|
1400
|
+
var get_property_value_template_default = withStandardDecorators(tool10);
|
|
1401
|
+
async function resolveEditorAliases(documentTypeId, values) {
|
|
1402
|
+
if (!values || values.length === 0) {
|
|
1403
|
+
return { ok: true, values: [] };
|
|
1404
|
+
}
|
|
1405
|
+
const docTypeResult = await resolveDocumentTypeProperties(documentTypeId);
|
|
1406
|
+
if (!docTypeResult.ok) return docTypeResult;
|
|
1407
|
+
const dataTypeIds = Array.from(
|
|
1408
|
+
new Set(
|
|
1409
|
+
docTypeResult.properties.map((p) => p.dataType?.id).filter((id) => typeof id === "string")
|
|
1410
|
+
)
|
|
1411
|
+
);
|
|
1412
|
+
const editorAliasByDataTypeId = /* @__PURE__ */ new Map();
|
|
1413
|
+
if (dataTypeIds.length > 0) {
|
|
1414
|
+
const dataTypesResult = await chainCms("get-data-types-by-id-array", { id: dataTypeIds });
|
|
1415
|
+
if (!dataTypesResult.ok) return dataTypesResult;
|
|
1416
|
+
for (const dt of dataTypesResult.data.items) {
|
|
1417
|
+
if (dt.id && dt.editorAlias) editorAliasByDataTypeId.set(dt.id, dt.editorAlias);
|
|
1200
1418
|
}
|
|
1201
1419
|
}
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
const
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
}
|
|
1210
|
-
const
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1420
|
+
const propertyAliases = new Set(
|
|
1421
|
+
docTypeResult.properties.map((p) => p.alias).filter((alias) => typeof alias === "string")
|
|
1422
|
+
);
|
|
1423
|
+
const editorAliasByPropertyAlias = /* @__PURE__ */ new Map();
|
|
1424
|
+
for (const prop of docTypeResult.properties) {
|
|
1425
|
+
const editorAlias = prop.dataType?.id ? editorAliasByDataTypeId.get(prop.dataType.id) : void 0;
|
|
1426
|
+
if (prop.alias && editorAlias) editorAliasByPropertyAlias.set(prop.alias, editorAlias);
|
|
1427
|
+
}
|
|
1428
|
+
const notAProperty = /* @__PURE__ */ new Set();
|
|
1429
|
+
const missingEditorAlias = /* @__PURE__ */ new Set();
|
|
1430
|
+
const resolved = values.map((v) => {
|
|
1431
|
+
const editorAlias = editorAliasByPropertyAlias.get(v.alias);
|
|
1432
|
+
if (!editorAlias) {
|
|
1433
|
+
if (propertyAliases.has(v.alias)) missingEditorAlias.add(v.alias);
|
|
1434
|
+
else notAProperty.add(v.alias);
|
|
1435
|
+
}
|
|
1436
|
+
return {
|
|
1437
|
+
alias: v.alias,
|
|
1438
|
+
value: v.value,
|
|
1439
|
+
culture: v.culture ?? null,
|
|
1440
|
+
segment: v.segment ?? null,
|
|
1441
|
+
editorAlias: editorAlias ?? ""
|
|
1442
|
+
};
|
|
1443
|
+
});
|
|
1444
|
+
if (notAProperty.size > 0 || missingEditorAlias.size > 0) {
|
|
1445
|
+
const messages = [];
|
|
1446
|
+
if (notAProperty.size > 0) {
|
|
1447
|
+
if (docTypeResult.failedCompositionIds.length > 0) {
|
|
1448
|
+
const failures = docTypeResult.failedCompositionIds.map((id, i) => `${id} (${docTypeResult.failedCompositionDetails[i]})`).join(", ");
|
|
1449
|
+
messages.push(
|
|
1450
|
+
`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`
|
|
1451
|
+
);
|
|
1452
|
+
} else {
|
|
1453
|
+
messages.push(
|
|
1454
|
+
`not a property on this document type, own or inherited via composition: ${Array.from(notAProperty).join(", ")}`
|
|
1455
|
+
);
|
|
1216
1456
|
}
|
|
1217
|
-
} catch {
|
|
1218
1457
|
}
|
|
1458
|
+
if (missingEditorAlias.size > 0) {
|
|
1459
|
+
messages.push(
|
|
1460
|
+
`a property on this document type, but its data type has no resolvable editor alias: ${Array.from(missingEditorAlias).join(", ")}`
|
|
1461
|
+
);
|
|
1462
|
+
}
|
|
1463
|
+
return {
|
|
1464
|
+
ok: false,
|
|
1465
|
+
errorResult: createToolResultError(
|
|
1466
|
+
`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.`
|
|
1467
|
+
)
|
|
1468
|
+
};
|
|
1219
1469
|
}
|
|
1220
|
-
return
|
|
1221
|
-
}
|
|
1222
|
-
function stringifyFromProblemDetails(pd) {
|
|
1223
|
-
if (pd.detail && typeof pd.detail === "string") return pd.detail;
|
|
1224
|
-
if (pd.title && typeof pd.title === "string") return pd.title;
|
|
1225
|
-
return "Document failed validation but no detail was returned.";
|
|
1226
|
-
}
|
|
1227
|
-
function stringifyErrorFallback(errorResult) {
|
|
1228
|
-
if (!errorResult || typeof errorResult !== "object") return "Document failed validation.";
|
|
1229
|
-
const r = errorResult;
|
|
1230
|
-
const text = r.content?.find((c) => c?.type === "text")?.text;
|
|
1231
|
-
return text ? text : "Document failed validation.";
|
|
1470
|
+
return { ok: true, values: resolved };
|
|
1232
1471
|
}
|
|
1233
1472
|
|
|
1234
1473
|
// src/umbraco-api/tools/content/post/create-page.ts
|
|
@@ -1258,31 +1497,12 @@ var tool11 = {
|
|
|
1258
1497
|
slices: ["create"],
|
|
1259
1498
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
|
|
1260
1499
|
handler: async ({ name, documentTypeId, parentId, values }) => {
|
|
1261
|
-
const
|
|
1262
|
-
if (
|
|
1263
|
-
const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
|
|
1264
|
-
if (!docTypeResult.ok) return docTypeResult.errorResult;
|
|
1265
|
-
const dataTypeIds = Array.from(new Set(docTypeResult.data.properties.map((p) => p.dataType.id)));
|
|
1266
|
-
const dataTypesResult = await chainCms("get-data-types-by-id-array", { id: dataTypeIds });
|
|
1267
|
-
if (!dataTypesResult.ok) return dataTypesResult.errorResult;
|
|
1268
|
-
const editorAliasByDataTypeId = new Map(
|
|
1269
|
-
dataTypesResult.data.items.map((dt) => [dt.id, dt.editorAlias])
|
|
1270
|
-
);
|
|
1271
|
-
for (const prop of docTypeResult.data.properties) {
|
|
1272
|
-
const editorAlias = editorAliasByDataTypeId.get(prop.dataType.id);
|
|
1273
|
-
if (editorAlias) editorAliasByPropertyAlias.set(prop.alias, editorAlias);
|
|
1274
|
-
}
|
|
1275
|
-
}
|
|
1500
|
+
const resolved = await resolveEditorAliases(documentTypeId, values);
|
|
1501
|
+
if (!resolved.ok) return resolved.errorResult;
|
|
1276
1502
|
const createResult = await chainCms("create-document", {
|
|
1277
1503
|
documentTypeId,
|
|
1278
1504
|
name,
|
|
1279
|
-
values:
|
|
1280
|
-
alias: v.alias,
|
|
1281
|
-
value: v.value,
|
|
1282
|
-
culture: v.culture ?? null,
|
|
1283
|
-
segment: v.segment ?? null,
|
|
1284
|
-
editorAlias: editorAliasByPropertyAlias.get(v.alias) ?? ""
|
|
1285
|
-
})),
|
|
1505
|
+
values: resolved.values,
|
|
1286
1506
|
...parentId ? { parentId } : {}
|
|
1287
1507
|
});
|
|
1288
1508
|
if (!createResult.ok) return createResult.errorResult;
|
|
@@ -1325,31 +1545,12 @@ var tool12 = {
|
|
|
1325
1545
|
slices: ["create", "publish"],
|
|
1326
1546
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
|
|
1327
1547
|
handler: async ({ name, documentTypeId, parentId, values }) => {
|
|
1328
|
-
const
|
|
1329
|
-
if (
|
|
1330
|
-
const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
|
|
1331
|
-
if (!docTypeResult.ok) return docTypeResult.errorResult;
|
|
1332
|
-
const dataTypeIds = Array.from(new Set(docTypeResult.data.properties.map((p) => p.dataType.id)));
|
|
1333
|
-
const dataTypesResult = await chainCms("get-data-types-by-id-array", { id: dataTypeIds });
|
|
1334
|
-
if (!dataTypesResult.ok) return dataTypesResult.errorResult;
|
|
1335
|
-
const editorAliasByDataTypeId = new Map(
|
|
1336
|
-
dataTypesResult.data.items.map((dt) => [dt.id, dt.editorAlias])
|
|
1337
|
-
);
|
|
1338
|
-
for (const prop of docTypeResult.data.properties) {
|
|
1339
|
-
const editorAlias = editorAliasByDataTypeId.get(prop.dataType.id);
|
|
1340
|
-
if (editorAlias) editorAliasByPropertyAlias.set(prop.alias, editorAlias);
|
|
1341
|
-
}
|
|
1342
|
-
}
|
|
1548
|
+
const resolved = await resolveEditorAliases(documentTypeId, values);
|
|
1549
|
+
if (!resolved.ok) return resolved.errorResult;
|
|
1343
1550
|
const createResult = await chainCms("create-and-publish-document", {
|
|
1344
1551
|
documentTypeId,
|
|
1345
1552
|
name,
|
|
1346
|
-
values:
|
|
1347
|
-
alias: v.alias,
|
|
1348
|
-
value: v.value,
|
|
1349
|
-
culture: v.culture ?? null,
|
|
1350
|
-
segment: v.segment ?? null,
|
|
1351
|
-
editorAlias: editorAliasByPropertyAlias.get(v.alias) ?? ""
|
|
1352
|
-
})),
|
|
1553
|
+
values: resolved.values,
|
|
1353
1554
|
...parentId ? { parentId } : {}
|
|
1354
1555
|
});
|
|
1355
1556
|
if (!createResult.ok) return createResult.errorResult;
|
|
@@ -1458,64 +1659,25 @@ var tool14 = {
|
|
|
1458
1659
|
const existingProp = (doc.values ?? []).find(
|
|
1459
1660
|
(v) => v.alias === propertyAlias && (v.culture ?? null) === (culture ?? null) && (v.segment ?? null) === (segment ?? null)
|
|
1460
1661
|
);
|
|
1461
|
-
|
|
1462
|
-
layout: { "Umbraco.BlockList": [] },
|
|
1463
|
-
contentData: [],
|
|
1464
|
-
settingsData: [],
|
|
1465
|
-
expose: []
|
|
1466
|
-
};
|
|
1467
|
-
if (existingProp && (!isBlockListOrGridValue(propValue) || existingProp.editorAlias !== "Umbraco.BlockList")) {
|
|
1662
|
+
if (existingProp?.value && (!isBlockListOrGridValue(existingProp.value) || existingProp.editorAlias !== "Umbraco.BlockList")) {
|
|
1468
1663
|
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 });
|
|
1469
1664
|
}
|
|
1470
|
-
const contentEditorAliases = await resolveBlockEditorAliases(contentTypeKey);
|
|
1471
|
-
if (!contentEditorAliases.ok) return contentEditorAliases.errorResult;
|
|
1472
|
-
let settingsEditorAliases = null;
|
|
1473
|
-
if (settingsTypeKey) {
|
|
1474
|
-
const settingsResult = await resolveBlockEditorAliases(settingsTypeKey);
|
|
1475
|
-
if (!settingsResult.ok) return settingsResult.errorResult;
|
|
1476
|
-
settingsEditorAliases = settingsResult.editorAliasByAlias;
|
|
1477
|
-
}
|
|
1478
|
-
const newContentKey = randomUUID();
|
|
1479
|
-
const newSettingsKey = settingsTypeKey ? randomUUID() : void 0;
|
|
1480
1665
|
const cultureValue = culture ?? null;
|
|
1481
1666
|
const segmentValue = segment ?? null;
|
|
1482
|
-
const
|
|
1483
|
-
|
|
1484
|
-
const
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
layout: { ...propValue.layout ?? {}, [layoutKey]: insertResult.list },
|
|
1494
|
-
contentData: [...propValue.contentData ?? [], newContentEntry],
|
|
1495
|
-
settingsData: newSettingsEntry ? [...propValue.settingsData ?? [], newSettingsEntry] : propValue.settingsData ?? [],
|
|
1496
|
-
expose: [...propValue.expose ?? [], exposeEntry(newContentKey, cultureValue, segmentValue)]
|
|
1497
|
-
};
|
|
1498
|
-
const updateResult = await chainCms("update-document-properties", {
|
|
1499
|
-
id,
|
|
1500
|
-
properties: [{
|
|
1501
|
-
alias: propertyAlias,
|
|
1502
|
-
value: newValue,
|
|
1503
|
-
culture: cultureValue,
|
|
1504
|
-
segment: segmentValue
|
|
1505
|
-
}]
|
|
1506
|
-
});
|
|
1507
|
-
if (!updateResult.ok) return updateResult.errorResult;
|
|
1508
|
-
const validation = await validateDocumentState(id);
|
|
1509
|
-
const baseMessage = `Added a new block to "${pageName}" (saved, not published)`;
|
|
1510
|
-
const message = validation.valid ? baseMessage : `${baseMessage} \u2014 but ${validation.errors.length} validation error(s) must be resolved before this page can be published`;
|
|
1511
|
-
return createToolResult({
|
|
1512
|
-
message,
|
|
1513
|
-
id,
|
|
1514
|
-
name: pageName,
|
|
1515
|
-
contentKey: newContentKey,
|
|
1516
|
-
previewUrl: await fetchPreviewUrl(id),
|
|
1517
|
-
validation
|
|
1667
|
+
const blockProperties = await toNewBlockProperties(contentTypeKey, values, settingsTypeKey, settingsValues, cultureValue, segmentValue);
|
|
1668
|
+
if (!blockProperties.ok) return blockProperties.errorResult;
|
|
1669
|
+
const createResult = await chainCms("create-document-block", {
|
|
1670
|
+
documentId: id,
|
|
1671
|
+
propertyAlias,
|
|
1672
|
+
culture: cultureValue,
|
|
1673
|
+
segment: segmentValue,
|
|
1674
|
+
contentTypeKey,
|
|
1675
|
+
properties: blockProperties.properties,
|
|
1676
|
+
settings: blockProperties.settings,
|
|
1677
|
+
placement: toPlacement(resolvedPosition)
|
|
1518
1678
|
});
|
|
1679
|
+
if (!createResult.ok) return createResult.errorResult;
|
|
1680
|
+
return buildBlockWriteResult(id, pageName, createResult.data.results[0].contentKey, `Added a new block to "${pageName}" (saved, not published)`);
|
|
1519
1681
|
}
|
|
1520
1682
|
};
|
|
1521
1683
|
var add_blocklist_block_default = withStandardDecorators(tool14);
|
|
@@ -1578,100 +1740,30 @@ var tool15 = {
|
|
|
1578
1740
|
const existingProp = (doc.values ?? []).find(
|
|
1579
1741
|
(v) => v.alias === propertyAlias && (v.culture ?? null) === (culture ?? null) && (v.segment ?? null) === (segment ?? null)
|
|
1580
1742
|
);
|
|
1581
|
-
|
|
1582
|
-
layout: { "Umbraco.BlockGrid": [] },
|
|
1583
|
-
contentData: [],
|
|
1584
|
-
settingsData: [],
|
|
1585
|
-
expose: []
|
|
1586
|
-
};
|
|
1587
|
-
if (existingProp && (!isBlockListOrGridValue(propValue) || existingProp.editorAlias !== "Umbraco.BlockGrid")) {
|
|
1743
|
+
if (existingProp?.value && (!isBlockListOrGridValue(existingProp.value) || existingProp.editorAlias !== "Umbraco.BlockGrid")) {
|
|
1588
1744
|
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 });
|
|
1589
1745
|
}
|
|
1590
|
-
const contentEditorAliases = await resolveBlockEditorAliases(contentTypeKey);
|
|
1591
|
-
if (!contentEditorAliases.ok) return contentEditorAliases.errorResult;
|
|
1592
|
-
let settingsEditorAliases = null;
|
|
1593
|
-
if (settingsTypeKey) {
|
|
1594
|
-
const settingsResult = await resolveBlockEditorAliases(settingsTypeKey);
|
|
1595
|
-
if (!settingsResult.ok) return settingsResult.errorResult;
|
|
1596
|
-
settingsEditorAliases = settingsResult.editorAliasByAlias;
|
|
1597
|
-
}
|
|
1598
|
-
const newContentKey = randomUUID();
|
|
1599
|
-
const newSettingsKey = settingsTypeKey ? randomUUID() : void 0;
|
|
1600
1746
|
const cultureValue = culture ?? null;
|
|
1601
1747
|
const segmentValue = segment ?? null;
|
|
1602
|
-
const
|
|
1603
|
-
|
|
1604
|
-
const
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
let nextTopLayout;
|
|
1618
|
-
if (areaKey) {
|
|
1619
|
-
const parentIndex = topLayout.findIndex((item) => item.contentKey === parentContentKey);
|
|
1620
|
-
if (parentIndex === -1) {
|
|
1621
|
-
return createToolResultError({ content: [{ type: "text", text: `Parent block '${parentContentKey}' was not found in '${propertyAlias}'.` }], isError: true });
|
|
1622
|
-
}
|
|
1623
|
-
const parent = topLayout[parentIndex];
|
|
1624
|
-
const areas = Array.isArray(parent.areas) ? parent.areas : [];
|
|
1625
|
-
const areaIndex = areas.findIndex((area2) => area2.key === areaKey);
|
|
1626
|
-
if (areaIndex === -1) {
|
|
1627
|
-
return createToolResultError({ content: [{ type: "text", text: `Area '${areaKey}' was not found on parent block '${parentContentKey}'.` }], isError: true });
|
|
1628
|
-
}
|
|
1629
|
-
const area = areas[areaIndex];
|
|
1630
|
-
const insertResult = insertAtPosition(area.items ?? [], layoutEntry, resolvedPosition, (item) => item.contentKey === resolvedPosition.anchorContentKey);
|
|
1631
|
-
if (!insertResult.ok) {
|
|
1632
|
-
return createToolResultError({ content: [{ type: "text", text: `Anchor block '${resolvedPosition.anchorContentKey}' was not found in area '${areaKey}'.` }], isError: true });
|
|
1633
|
-
}
|
|
1634
|
-
const updatedArea = { ...area, items: insertResult.list };
|
|
1635
|
-
const updatedAreas = areas.slice();
|
|
1636
|
-
updatedAreas[areaIndex] = updatedArea;
|
|
1637
|
-
const updatedParent = { ...parent, areas: updatedAreas };
|
|
1638
|
-
nextTopLayout = topLayout.slice();
|
|
1639
|
-
nextTopLayout[parentIndex] = updatedParent;
|
|
1640
|
-
} else {
|
|
1641
|
-
const insertResult = insertAtPosition(topLayout, layoutEntry, resolvedPosition, (item) => item.contentKey === resolvedPosition.anchorContentKey);
|
|
1642
|
-
if (!insertResult.ok) {
|
|
1643
|
-
return createToolResultError({ content: [{ type: "text", text: `Anchor block '${resolvedPosition.anchorContentKey}' was not found in '${propertyAlias}'.` }], isError: true });
|
|
1748
|
+
const blockProperties = await toNewBlockProperties(contentTypeKey, values, settingsTypeKey, settingsValues, cultureValue, segmentValue);
|
|
1749
|
+
if (!blockProperties.ok) return blockProperties.errorResult;
|
|
1750
|
+
const createResult = await chainCms("create-document-block", {
|
|
1751
|
+
documentId: id,
|
|
1752
|
+
propertyAlias,
|
|
1753
|
+
culture: cultureValue,
|
|
1754
|
+
segment: segmentValue,
|
|
1755
|
+
contentTypeKey,
|
|
1756
|
+
properties: blockProperties.properties,
|
|
1757
|
+
settings: blockProperties.settings,
|
|
1758
|
+
placement: toPlacement(resolvedPosition),
|
|
1759
|
+
grid: {
|
|
1760
|
+
columnSpan: columnSpan ?? 12,
|
|
1761
|
+
rowSpan: rowSpan ?? 1,
|
|
1762
|
+
...areaKey && parentContentKey ? { areaKey, parentContentKey } : {}
|
|
1644
1763
|
}
|
|
1645
|
-
nextTopLayout = insertResult.list;
|
|
1646
|
-
}
|
|
1647
|
-
const newValue = {
|
|
1648
|
-
...propValue,
|
|
1649
|
-
layout: { ...propValue.layout ?? {}, [layoutKey]: nextTopLayout },
|
|
1650
|
-
contentData: [...propValue.contentData ?? [], newContentEntry],
|
|
1651
|
-
settingsData: newSettingsEntry ? [...propValue.settingsData ?? [], newSettingsEntry] : propValue.settingsData ?? [],
|
|
1652
|
-
expose: [...propValue.expose ?? [], exposeEntry(newContentKey, cultureValue, segmentValue)]
|
|
1653
|
-
};
|
|
1654
|
-
const updateResult = await chainCms("update-document-properties", {
|
|
1655
|
-
id,
|
|
1656
|
-
properties: [{
|
|
1657
|
-
alias: propertyAlias,
|
|
1658
|
-
value: newValue,
|
|
1659
|
-
culture: cultureValue,
|
|
1660
|
-
segment: segmentValue
|
|
1661
|
-
}]
|
|
1662
|
-
});
|
|
1663
|
-
if (!updateResult.ok) return updateResult.errorResult;
|
|
1664
|
-
const validation = await validateDocumentState(id);
|
|
1665
|
-
const baseMessage = `Added a new block to "${pageName}" (saved, not published)`;
|
|
1666
|
-
const message = validation.valid ? baseMessage : `${baseMessage} \u2014 but ${validation.errors.length} validation error(s) must be resolved before this page can be published`;
|
|
1667
|
-
return createToolResult({
|
|
1668
|
-
message,
|
|
1669
|
-
id,
|
|
1670
|
-
name: pageName,
|
|
1671
|
-
contentKey: newContentKey,
|
|
1672
|
-
previewUrl: await fetchPreviewUrl(id),
|
|
1673
|
-
validation
|
|
1674
1764
|
});
|
|
1765
|
+
if (!createResult.ok) return createResult.errorResult;
|
|
1766
|
+
return buildBlockWriteResult(id, pageName, createResult.data.results[0].contentKey, `Added a new block to "${pageName}" (saved, not published)`);
|
|
1675
1767
|
}
|
|
1676
1768
|
};
|
|
1677
1769
|
var add_blockgrid_block_default = withStandardDecorators(tool15);
|
|
@@ -1702,26 +1794,6 @@ var outputSchema16 = z.object({
|
|
|
1702
1794
|
previewUrl: previewUrlSchema,
|
|
1703
1795
|
validation: validationResultSchema
|
|
1704
1796
|
});
|
|
1705
|
-
function buildBlockTag(contentKey) {
|
|
1706
|
-
return `<umb-rte-block data-content-key="${contentKey}"></umb-rte-block>`;
|
|
1707
|
-
}
|
|
1708
|
-
function findAnchorTagRange(markup, anchorKey) {
|
|
1709
|
-
const re = new RegExp(`<umb-rte-block[^>]*data-content-key="${anchorKey}"[^>]*>\\s*</umb-rte-block>`, "i");
|
|
1710
|
-
const match = markup.match(re);
|
|
1711
|
-
if (!match || match.index === void 0) return null;
|
|
1712
|
-
return { start: match.index, end: match.index + match[0].length };
|
|
1713
|
-
}
|
|
1714
|
-
function insertMarkup(markup, newTag, mode, anchorKey) {
|
|
1715
|
-
if (mode === "append") return { ok: true, markup: `${markup}${newTag}` };
|
|
1716
|
-
if (mode === "prepend") return { ok: true, markup: `${newTag}${markup}` };
|
|
1717
|
-
if (!anchorKey) return { ok: false, reason: "missing anchor" };
|
|
1718
|
-
const range = findAnchorTagRange(markup, anchorKey);
|
|
1719
|
-
if (!range) return { ok: false, reason: "anchor not found" };
|
|
1720
|
-
if (mode === "before") {
|
|
1721
|
-
return { ok: true, markup: `${markup.slice(0, range.start)}${newTag}${markup.slice(range.start)}` };
|
|
1722
|
-
}
|
|
1723
|
-
return { ok: true, markup: `${markup.slice(0, range.end)}${newTag}${markup.slice(range.end)}` };
|
|
1724
|
-
}
|
|
1725
1797
|
var tool16 = {
|
|
1726
1798
|
name: "add-rte-block",
|
|
1727
1799
|
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.",
|
|
@@ -1747,71 +1819,25 @@ var tool16 = {
|
|
|
1747
1819
|
const existingProp = (doc.values ?? []).find(
|
|
1748
1820
|
(v) => v.alias === propertyAlias && (v.culture ?? null) === (culture ?? null) && (v.segment ?? null) === (segment ?? null)
|
|
1749
1821
|
);
|
|
1750
|
-
|
|
1751
|
-
markup: "",
|
|
1752
|
-
blocks: { layout: {}, contentData: [], settingsData: [], expose: [] }
|
|
1753
|
-
};
|
|
1754
|
-
if (existingProp && !isRteWithBlocks(propValue)) {
|
|
1822
|
+
if (existingProp?.value && !isRteWithBlocks(existingProp.value)) {
|
|
1755
1823
|
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 });
|
|
1756
1824
|
}
|
|
1757
|
-
const contentEditorAliases = await resolveBlockEditorAliases(contentTypeKey);
|
|
1758
|
-
if (!contentEditorAliases.ok) return contentEditorAliases.errorResult;
|
|
1759
|
-
let settingsEditorAliases = null;
|
|
1760
|
-
if (settingsTypeKey) {
|
|
1761
|
-
const settingsResult = await resolveBlockEditorAliases(settingsTypeKey);
|
|
1762
|
-
if (!settingsResult.ok) return settingsResult.errorResult;
|
|
1763
|
-
settingsEditorAliases = settingsResult.editorAliasByAlias;
|
|
1764
|
-
}
|
|
1765
|
-
const newContentKey = randomUUID();
|
|
1766
|
-
const newSettingsKey = settingsTypeKey ? randomUUID() : void 0;
|
|
1767
1825
|
const cultureValue = culture ?? null;
|
|
1768
1826
|
const segmentValue = segment ?? null;
|
|
1769
|
-
const
|
|
1770
|
-
|
|
1771
|
-
const
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
if (!markupResult.ok) {
|
|
1781
|
-
return createToolResultError({ content: [{ type: "text", text: `Could not insert into markup \u2014 ${markupResult.reason}.` }], isError: true });
|
|
1782
|
-
}
|
|
1783
|
-
const newValue = {
|
|
1784
|
-
...propValue,
|
|
1785
|
-
markup: markupResult.markup,
|
|
1786
|
-
blocks: {
|
|
1787
|
-
...blocks,
|
|
1788
|
-
layout: { ...blocks.layout ?? {}, [layoutKey]: insertLayoutResult.list },
|
|
1789
|
-
contentData: [...blocks.contentData ?? [], newContentEntry],
|
|
1790
|
-
settingsData: newSettingsEntry ? [...blocks.settingsData ?? [], newSettingsEntry] : blocks.settingsData ?? [],
|
|
1791
|
-
expose: [...blocks.expose ?? [], exposeEntry(newContentKey, cultureValue, segmentValue)]
|
|
1792
|
-
}
|
|
1793
|
-
};
|
|
1794
|
-
const updateResult = await chainCms("update-document-properties", {
|
|
1795
|
-
id,
|
|
1796
|
-
properties: [{
|
|
1797
|
-
alias: propertyAlias,
|
|
1798
|
-
value: newValue,
|
|
1799
|
-
culture: cultureValue,
|
|
1800
|
-
segment: segmentValue
|
|
1801
|
-
}]
|
|
1802
|
-
});
|
|
1803
|
-
if (!updateResult.ok) return updateResult.errorResult;
|
|
1804
|
-
const validation = await validateDocumentState(id);
|
|
1805
|
-
const baseMessage = `Added a new block to "${pageName}" rich text (saved, not published)`;
|
|
1806
|
-
const message = validation.valid ? baseMessage : `${baseMessage} \u2014 but ${validation.errors.length} validation error(s) must be resolved before this page can be published`;
|
|
1807
|
-
return createToolResult({
|
|
1808
|
-
message,
|
|
1809
|
-
id,
|
|
1810
|
-
name: pageName,
|
|
1811
|
-
contentKey: newContentKey,
|
|
1812
|
-
previewUrl: await fetchPreviewUrl(id),
|
|
1813
|
-
validation
|
|
1827
|
+
const blockProperties = await toNewBlockProperties(contentTypeKey, values, settingsTypeKey, settingsValues, cultureValue, segmentValue);
|
|
1828
|
+
if (!blockProperties.ok) return blockProperties.errorResult;
|
|
1829
|
+
const createResult = await chainCms("create-document-block", {
|
|
1830
|
+
documentId: id,
|
|
1831
|
+
propertyAlias,
|
|
1832
|
+
culture: cultureValue,
|
|
1833
|
+
segment: segmentValue,
|
|
1834
|
+
contentTypeKey,
|
|
1835
|
+
properties: blockProperties.properties,
|
|
1836
|
+
settings: blockProperties.settings,
|
|
1837
|
+
placement: toPlacement(resolvedPosition)
|
|
1814
1838
|
});
|
|
1839
|
+
if (!createResult.ok) return createResult.errorResult;
|
|
1840
|
+
return buildBlockWriteResult(id, pageName, createResult.data.results[0].contentKey, `Added a new block to "${pageName}" rich text (saved, not published)`);
|
|
1815
1841
|
}
|
|
1816
1842
|
};
|
|
1817
1843
|
var add_rte_block_default = withStandardDecorators(tool16);
|
|
@@ -1871,7 +1897,7 @@ var inputSchema18 = {
|
|
|
1871
1897
|
propertyAlias: z.string().describe("The document property alias containing the blocks (e.g. 'mainContent'). Use inspect-blocks to find this."),
|
|
1872
1898
|
contentKey: z.string().uuid().describe("The unique key of the block to edit. Use inspect-blocks to find this."),
|
|
1873
1899
|
values: z.array(z.object({
|
|
1874
|
-
alias:
|
|
1900
|
+
alias: blockPropertyAliasSchema.describe("The property alias within the block"),
|
|
1875
1901
|
value: z.any().describe("The new value for the property")
|
|
1876
1902
|
})).describe("Properties to update within the block"),
|
|
1877
1903
|
blockType: z.enum(["content", "settings"]).optional().describe("Whether to update the block's content or its settings. Defaults to 'content'."),
|
|
@@ -1885,7 +1911,8 @@ var outputSchema18 = z.object({
|
|
|
1885
1911
|
contentKey: z.string(),
|
|
1886
1912
|
updatedFields: z.array(z.string()),
|
|
1887
1913
|
previewUrl: previewUrlSchema,
|
|
1888
|
-
validation: validationResultSchema
|
|
1914
|
+
validation: validationResultSchema,
|
|
1915
|
+
warnings: z.array(z.string()).optional()
|
|
1889
1916
|
});
|
|
1890
1917
|
var tool18 = {
|
|
1891
1918
|
name: "edit-block",
|
|
@@ -1900,6 +1927,20 @@ var tool18 = {
|
|
|
1900
1927
|
const pageName = docResult.data.variants?.[0]?.name ?? "Unknown";
|
|
1901
1928
|
const fieldNames = values.map((v) => v.alias);
|
|
1902
1929
|
const resolvedBlockType = blockType ?? "content";
|
|
1930
|
+
let targetKey = contentKey;
|
|
1931
|
+
if (resolvedBlockType === "settings") {
|
|
1932
|
+
const rawValue = (docResult.data.values ?? []).find(
|
|
1933
|
+
(v) => v.alias === propertyAlias && (v.culture ?? null) === (culture ?? null) && (v.segment ?? null) === (segment ?? null)
|
|
1934
|
+
)?.value;
|
|
1935
|
+
const container = isRteWithBlocks(rawValue) ? rawValue.blocks : rawValue;
|
|
1936
|
+
const settingsKey = findSettingsKey(container, contentKey);
|
|
1937
|
+
if (!settingsKey) {
|
|
1938
|
+
return createToolResultError(
|
|
1939
|
+
`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.`
|
|
1940
|
+
);
|
|
1941
|
+
}
|
|
1942
|
+
targetKey = settingsKey;
|
|
1943
|
+
}
|
|
1903
1944
|
const propsTuple = values.map((v) => ({ alias: v.alias, value: v.value }));
|
|
1904
1945
|
const updateResult = await chainCms("update-block-property", {
|
|
1905
1946
|
documentId: id,
|
|
@@ -1907,12 +1948,41 @@ var tool18 = {
|
|
|
1907
1948
|
culture: culture ?? null,
|
|
1908
1949
|
segment: segment ?? null,
|
|
1909
1950
|
updates: [{
|
|
1910
|
-
contentKey,
|
|
1951
|
+
contentKey: targetKey,
|
|
1911
1952
|
blockType: resolvedBlockType,
|
|
1912
1953
|
properties: propsTuple
|
|
1913
1954
|
}]
|
|
1914
1955
|
});
|
|
1915
|
-
if (!updateResult.ok)
|
|
1956
|
+
if (!updateResult.ok) {
|
|
1957
|
+
return enrichBlockNotFoundError(updateResult.errorResult, docResult.data.values ?? [], {
|
|
1958
|
+
propertyAlias,
|
|
1959
|
+
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.`
|
|
1960
|
+
});
|
|
1961
|
+
}
|
|
1962
|
+
const results = updateResult.data.results;
|
|
1963
|
+
if (!results || results.length === 0) {
|
|
1964
|
+
return createToolResultError(
|
|
1965
|
+
"update-block-property returned no per-block result \u2014 cannot confirm the write succeeded."
|
|
1966
|
+
);
|
|
1967
|
+
}
|
|
1968
|
+
const classification = classifyBlockUpdateResults(results, fieldNames.length, fieldNames, 1);
|
|
1969
|
+
if (classification.outcome === "failed") {
|
|
1970
|
+
return createToolResultError(
|
|
1971
|
+
`Block update failed: ${classification.detail || updateResult.data.message || "no detail returned"}`
|
|
1972
|
+
);
|
|
1973
|
+
}
|
|
1974
|
+
if (classification.outcome === "partial") {
|
|
1975
|
+
return createToolResultError({
|
|
1976
|
+
message: `Block update partially failed: ${classification.processedCount} of ${fieldNames.length} field(s) saved \u2014 ${classification.detail}`,
|
|
1977
|
+
savedFields: classification.savedFields,
|
|
1978
|
+
failedFields: classification.failedFields,
|
|
1979
|
+
...classification.savedFields.length > 0 ? { note: "savedFields were written to the document and must not be retried." } : {},
|
|
1980
|
+
...classification.warnings.length ? { warnings: classification.warnings } : {},
|
|
1981
|
+
validation: await validateDocumentState(id),
|
|
1982
|
+
previewUrl: await fetchPreviewUrl(id)
|
|
1983
|
+
});
|
|
1984
|
+
}
|
|
1985
|
+
const warnings = classification.warnings;
|
|
1916
1986
|
const validation = await validateDocumentState(id);
|
|
1917
1987
|
const target = resolvedBlockType === "settings" ? "settings" : "content";
|
|
1918
1988
|
const baseMessage = `Updated ${fieldNames.length} field(s) in block ${target} on "${pageName}" (saved, not published)`;
|
|
@@ -1924,7 +1994,8 @@ var tool18 = {
|
|
|
1924
1994
|
contentKey,
|
|
1925
1995
|
updatedFields: fieldNames,
|
|
1926
1996
|
previewUrl: await fetchPreviewUrl(id),
|
|
1927
|
-
validation
|
|
1997
|
+
validation,
|
|
1998
|
+
...warnings.length ? { warnings } : {}
|
|
1928
1999
|
});
|
|
1929
2000
|
}
|
|
1930
2001
|
};
|
|
@@ -1978,10 +2049,9 @@ var tool19 = {
|
|
|
1978
2049
|
});
|
|
1979
2050
|
}
|
|
1980
2051
|
const cultureLabel = targetCulture ? ` (${targetCulture})` : "";
|
|
1981
|
-
const confirmed = await
|
|
2052
|
+
const confirmed = await requestApproval(
|
|
1982
2053
|
extra,
|
|
1983
|
-
`Rename page${cultureLabel} from "${previousName}" to "${name}"? The page URL segment may change when you next publish
|
|
1984
|
-
{ title: "Confirm rename" }
|
|
2054
|
+
`Rename page${cultureLabel} from "${previousName}" to "${name}"? The page URL segment may change when you next publish.`
|
|
1985
2055
|
);
|
|
1986
2056
|
if (!confirmed) {
|
|
1987
2057
|
return createToolResult({
|
|
@@ -2268,68 +2338,26 @@ var outputSchema24 = z.object({
|
|
|
2268
2338
|
previewUrl: previewUrlSchema,
|
|
2269
2339
|
validation: validationResultSchema
|
|
2270
2340
|
});
|
|
2271
|
-
function
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
}
|
|
2276
|
-
for (let i = 0; i < items.length; i++) {
|
|
2277
|
-
const item = items[i];
|
|
2278
|
-
if (!Array.isArray(item.areas)) continue;
|
|
2279
|
-
for (let aIdx = 0; aIdx < item.areas.length; aIdx++) {
|
|
2280
|
-
const inner = findAndRemoveGridItem(item.areas[aIdx].items ?? [], contentKey);
|
|
2281
|
-
if (inner.found) {
|
|
2282
|
-
const updatedAreas = item.areas.slice();
|
|
2283
|
-
updatedAreas[aIdx] = { ...item.areas[aIdx], items: inner.nextItems };
|
|
2284
|
-
const nextItems = items.slice();
|
|
2285
|
-
nextItems[i] = { ...item, areas: updatedAreas };
|
|
2286
|
-
return { found: true, doomedSettingsKey: inner.doomedSettingsKey, nextItems };
|
|
2287
|
-
}
|
|
2288
|
-
}
|
|
2289
|
-
}
|
|
2290
|
-
return { found: false };
|
|
2341
|
+
function gridContainsBlock(items, contentKey) {
|
|
2342
|
+
return items.some(
|
|
2343
|
+
(item) => item.contentKey === contentKey || (item.areas ?? []).some((area) => gridContainsBlock(area.items ?? [], contentKey))
|
|
2344
|
+
);
|
|
2291
2345
|
}
|
|
2292
|
-
function
|
|
2346
|
+
function locateBlock(propValue, editorAlias, propertyAlias, contentKey, pageName) {
|
|
2293
2347
|
const notFound = { ok: false, errorText: `Block '${contentKey}' was not found in property '${propertyAlias}'.` };
|
|
2294
2348
|
const draftSuffix = "Will be saved as a draft, not published.";
|
|
2295
2349
|
if (isBlockListOrGridValue(propValue) && editorAlias === "Umbraco.BlockList") {
|
|
2296
|
-
const
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
if (!doomed) return notFound;
|
|
2300
|
-
return {
|
|
2301
|
-
ok: true,
|
|
2302
|
-
newValue: removeBlockFromContainer(propValue, contentKey, layoutKey, layoutList.filter((e) => e.contentKey !== contentKey), doomed.settingsKey),
|
|
2303
|
-
confirmMessage: `Remove block ${contentKey} from "${pageName}" (BlockList ${propertyAlias})? ${draftSuffix}`
|
|
2304
|
-
};
|
|
2350
|
+
const layoutList = propValue.layout?.["Umbraco.BlockList"] ?? [];
|
|
2351
|
+
if (!layoutList.some((e) => e.contentKey === contentKey)) return notFound;
|
|
2352
|
+
return { ok: true, confirmMessage: `Remove block ${contentKey} from "${pageName}" (BlockList ${propertyAlias})? ${draftSuffix}` };
|
|
2305
2353
|
}
|
|
2306
2354
|
if (isBlockListOrGridValue(propValue) && editorAlias === "Umbraco.BlockGrid") {
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
if (!removed.found) return notFound;
|
|
2310
|
-
return {
|
|
2311
|
-
ok: true,
|
|
2312
|
-
newValue: removeBlockFromContainer(propValue, contentKey, layoutKey, removed.nextItems, removed.doomedSettingsKey),
|
|
2313
|
-
confirmMessage: `Remove block ${contentKey} from "${pageName}" (BlockGrid ${propertyAlias})? ${draftSuffix}`
|
|
2314
|
-
};
|
|
2355
|
+
if (!gridContainsBlock(propValue.layout?.["Umbraco.BlockGrid"] ?? [], contentKey)) return notFound;
|
|
2356
|
+
return { ok: true, confirmMessage: `Remove block ${contentKey} from "${pageName}" (BlockGrid ${propertyAlias})? ${draftSuffix}` };
|
|
2315
2357
|
}
|
|
2316
2358
|
if (isRteWithBlocks(propValue)) {
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
const layoutList = blocks.layout?.[layoutKey] ?? [];
|
|
2320
|
-
const inContent = (blocks.contentData ?? []).some((e) => e.key === contentKey);
|
|
2321
|
-
if (!inContent) return notFound;
|
|
2322
|
-
const doomedSettingsKey = layoutList.find((e) => e.contentKey === contentKey)?.settingsKey;
|
|
2323
|
-
const tagRe = new RegExp(`<umb-rte-block[^>]*data-content-key="${contentKey}"[^>]*>\\s*</umb-rte-block>`, "gi");
|
|
2324
|
-
return {
|
|
2325
|
-
ok: true,
|
|
2326
|
-
newValue: {
|
|
2327
|
-
...propValue,
|
|
2328
|
-
markup: (propValue.markup ?? "").replace(tagRe, ""),
|
|
2329
|
-
blocks: removeBlockFromContainer(blocks, contentKey, layoutKey, layoutList.filter((e) => e.contentKey !== contentKey), doomedSettingsKey)
|
|
2330
|
-
},
|
|
2331
|
-
confirmMessage: `Remove block ${contentKey} from a Rich Text in "${pageName}" (${propertyAlias})? ${draftSuffix}`
|
|
2332
|
-
};
|
|
2359
|
+
if (!(propValue.blocks.contentData ?? []).some((e) => e.key === contentKey)) return notFound;
|
|
2360
|
+
return { ok: true, confirmMessage: `Remove block ${contentKey} from a Rich Text in "${pageName}" (${propertyAlias})? ${draftSuffix}` };
|
|
2333
2361
|
}
|
|
2334
2362
|
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.` };
|
|
2335
2363
|
}
|
|
@@ -2354,29 +2382,22 @@ var tool24 = {
|
|
|
2354
2382
|
isError: true
|
|
2355
2383
|
});
|
|
2356
2384
|
}
|
|
2357
|
-
const
|
|
2358
|
-
if (!
|
|
2359
|
-
return createToolResultError({ content: [{ type: "text", text:
|
|
2385
|
+
const location = locateBlock(prop.value, prop.editorAlias, propertyAlias, contentKey, pageName);
|
|
2386
|
+
if (!location.ok) {
|
|
2387
|
+
return createToolResultError({ content: [{ type: "text", text: location.errorText }], isError: true });
|
|
2360
2388
|
}
|
|
2361
|
-
if (!await requestApproval(extra,
|
|
2389
|
+
if (!await requestApproval(extra, location.confirmMessage)) {
|
|
2362
2390
|
return createToolResultError({ content: [{ type: "text", text: "Cancelled by user." }], isError: true });
|
|
2363
2391
|
}
|
|
2364
|
-
const
|
|
2365
|
-
id,
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
const baseMessage = `Removed block from "${pageName}" (saved, not published)`;
|
|
2371
|
-
const message = validation.valid ? baseMessage : `${baseMessage} \u2014 but ${validation.errors.length} validation error(s) must be resolved before this page can be published`;
|
|
2372
|
-
return createToolResult({
|
|
2373
|
-
message,
|
|
2374
|
-
id,
|
|
2375
|
-
name: pageName,
|
|
2376
|
-
contentKey,
|
|
2377
|
-
previewUrl: await fetchPreviewUrl(id),
|
|
2378
|
-
validation
|
|
2392
|
+
const deleteResult = await chainCms("delete-document-block", {
|
|
2393
|
+
documentId: id,
|
|
2394
|
+
propertyAlias,
|
|
2395
|
+
culture: culture ?? null,
|
|
2396
|
+
segment: segment ?? null,
|
|
2397
|
+
contentKey
|
|
2379
2398
|
});
|
|
2399
|
+
if (!deleteResult.ok) return deleteResult.errorResult;
|
|
2400
|
+
return buildBlockWriteResult(id, pageName, contentKey, `Removed block from "${pageName}" (saved, not published)`);
|
|
2380
2401
|
}
|
|
2381
2402
|
};
|
|
2382
2403
|
var delete_block_default = withStandardDecorators(tool24);
|
|
@@ -2639,7 +2660,7 @@ var tool27 = {
|
|
|
2639
2660
|
});
|
|
2640
2661
|
if (!updateAndPublishResult.ok) {
|
|
2641
2662
|
const rolledBack = `No changes were saved to "${pageName}" \u2014 save-and-publish is a single atomic operation, so the field updates were rolled back along with the publish.`;
|
|
2642
|
-
const problem = updateAndPublishResult.errorResult
|
|
2663
|
+
const problem = extractInnerProblemDetails(updateAndPublishResult.errorResult);
|
|
2643
2664
|
return createToolResultError({
|
|
2644
2665
|
...problem,
|
|
2645
2666
|
status: typeof problem?.status === "number" ? problem.status : 500,
|
|
@@ -3501,12 +3522,7 @@ function validateBulkIds(ids) {
|
|
|
3501
3522
|
function parseBulkError(err) {
|
|
3502
3523
|
if (err === null || err === void 0) return "Unknown error";
|
|
3503
3524
|
if (typeof err === "object") {
|
|
3504
|
-
|
|
3505
|
-
const sc = asRecord.structuredContent;
|
|
3506
|
-
if (sc !== null && sc !== void 0 && typeof sc === "object") {
|
|
3507
|
-
return sc;
|
|
3508
|
-
}
|
|
3509
|
-
return err;
|
|
3525
|
+
return extractInnerProblemDetails(err);
|
|
3510
3526
|
}
|
|
3511
3527
|
if (typeof err === "string") {
|
|
3512
3528
|
try {
|
|
@@ -3910,31 +3926,12 @@ var tool50 = {
|
|
|
3910
3926
|
slices: ["create"],
|
|
3911
3927
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
|
|
3912
3928
|
handler: async ({ name, elementTypeId, parentId, values }) => {
|
|
3913
|
-
const
|
|
3914
|
-
if (
|
|
3915
|
-
const typeResult = await chainCms("get-document-type-by-id", { id: elementTypeId });
|
|
3916
|
-
if (!typeResult.ok) return typeResult.errorResult;
|
|
3917
|
-
const dataTypeIds = Array.from(new Set(typeResult.data.properties.map((p) => p.dataType.id)));
|
|
3918
|
-
const dataTypesResult = await chainCms("get-data-types-by-id-array", { id: dataTypeIds });
|
|
3919
|
-
if (!dataTypesResult.ok) return dataTypesResult.errorResult;
|
|
3920
|
-
const editorAliasByDataTypeId = new Map(
|
|
3921
|
-
dataTypesResult.data.items.map((dt) => [dt.id, dt.editorAlias])
|
|
3922
|
-
);
|
|
3923
|
-
for (const prop of typeResult.data.properties) {
|
|
3924
|
-
const editorAlias = editorAliasByDataTypeId.get(prop.dataType.id);
|
|
3925
|
-
if (editorAlias) editorAliasByPropertyAlias.set(prop.alias, editorAlias);
|
|
3926
|
-
}
|
|
3927
|
-
}
|
|
3929
|
+
const resolved = await resolveEditorAliases(elementTypeId, values);
|
|
3930
|
+
if (!resolved.ok) return resolved.errorResult;
|
|
3928
3931
|
const createResult = await chainCms("create-element", {
|
|
3929
3932
|
documentTypeId: elementTypeId,
|
|
3930
3933
|
name,
|
|
3931
|
-
values:
|
|
3932
|
-
alias: v.alias,
|
|
3933
|
-
value: v.value,
|
|
3934
|
-
culture: v.culture ?? null,
|
|
3935
|
-
segment: v.segment ?? null,
|
|
3936
|
-
editorAlias: editorAliasByPropertyAlias.get(v.alias) ?? ""
|
|
3937
|
-
})),
|
|
3934
|
+
values: resolved.values,
|
|
3938
3935
|
...parentId ? { parentId } : {}
|
|
3939
3936
|
});
|
|
3940
3937
|
if (!createResult.ok) return createResult.errorResult;
|
|
@@ -4146,7 +4143,7 @@ var inputSchema56 = {
|
|
|
4146
4143
|
propertyAlias: z.string().describe("The element property alias containing the blocks (e.g. 'mainContent'). Use inspect-element-blocks to find this."),
|
|
4147
4144
|
contentKey: z.string().uuid().describe("The unique key of the block to edit \u2014 always the block's contentKey as reported by inspect-element-blocks, including when blockType is 'settings'."),
|
|
4148
4145
|
values: z.array(z.object({
|
|
4149
|
-
alias:
|
|
4146
|
+
alias: blockPropertyAliasSchema.describe("The property alias within the block"),
|
|
4150
4147
|
value: z.any().describe("The new value for the property")
|
|
4151
4148
|
})).min(1).describe("Properties to update within the block"),
|
|
4152
4149
|
blockType: z.enum(["content", "settings"]).optional().describe("Whether to update the block's content or its settings. Defaults to 'content'."),
|
|
@@ -4201,15 +4198,29 @@ var tool56 = {
|
|
|
4201
4198
|
}]
|
|
4202
4199
|
});
|
|
4203
4200
|
if (!updateResult.ok) return updateResult.errorResult;
|
|
4204
|
-
const
|
|
4205
|
-
if (
|
|
4206
|
-
|
|
4201
|
+
const results = updateResult.data.results;
|
|
4202
|
+
if (!results || results.length === 0) {
|
|
4203
|
+
return createToolResultError(
|
|
4204
|
+
"update-element-block-property returned no per-block result \u2014 cannot confirm the write succeeded."
|
|
4205
|
+
);
|
|
4206
|
+
}
|
|
4207
|
+
const classification = classifyBlockUpdateResults(results, fieldNames.length, fieldNames, 1);
|
|
4208
|
+
if (classification.outcome === "failed") {
|
|
4207
4209
|
return createToolResultError(
|
|
4208
|
-
`Block update failed: ${detail || updateResult.data.message || "no detail returned"}`
|
|
4210
|
+
`Block update failed: ${classification.detail || updateResult.data.message || "no detail returned"}`
|
|
4209
4211
|
);
|
|
4210
4212
|
}
|
|
4213
|
+
if (classification.outcome === "partial") {
|
|
4214
|
+
return createToolResultError({
|
|
4215
|
+
message: `Block update partially failed: ${classification.processedCount} of ${fieldNames.length} field(s) saved \u2014 ${classification.detail}`,
|
|
4216
|
+
savedFields: classification.savedFields,
|
|
4217
|
+
failedFields: classification.failedFields,
|
|
4218
|
+
...classification.savedFields.length > 0 ? { note: "savedFields were written to the element and must not be retried." } : {},
|
|
4219
|
+
...classification.warnings.length ? { warnings: classification.warnings } : {}
|
|
4220
|
+
});
|
|
4221
|
+
}
|
|
4211
4222
|
const target = resolvedBlockType === "settings" ? "settings" : "content";
|
|
4212
|
-
const warnings =
|
|
4223
|
+
const warnings = classification.warnings;
|
|
4213
4224
|
return createToolResult({
|
|
4214
4225
|
message: `Updated ${fieldNames.length} field(s) in block ${target} on element "${elementName}" (saved, not published)`,
|
|
4215
4226
|
id,
|
|
@@ -4294,6 +4305,15 @@ var tool58 = {
|
|
|
4294
4305
|
slices: ["list"],
|
|
4295
4306
|
annotations: { readOnlyHint: true },
|
|
4296
4307
|
handler: async ({ parentId, take, skip }) => {
|
|
4308
|
+
const accessCheck = await checkSettingsAccess();
|
|
4309
|
+
if (!accessCheck.ok) return accessCheck.errorResult;
|
|
4310
|
+
if (!accessCheck.hasAccess) {
|
|
4311
|
+
return createToolResultError({
|
|
4312
|
+
status: 403,
|
|
4313
|
+
title: "Settings access required",
|
|
4314
|
+
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."
|
|
4315
|
+
});
|
|
4316
|
+
}
|
|
4297
4317
|
const cursor = buildChainedCursor(skip, take);
|
|
4298
4318
|
const result = parentId ? await chainCms("get-document-blueprint-children", { parentId, cursor }) : await chainCms("get-document-blueprint-root", { cursor });
|
|
4299
4319
|
if (!result.ok) return result.errorResult;
|
|
@@ -5827,7 +5847,7 @@ var inputSchema85 = {
|
|
|
5827
5847
|
contentTypeKey: z.string().uuid().describe("The block element type key to target. Use inspect-blocks to find this."),
|
|
5828
5848
|
propertyAlias: z.string().describe("The document property alias containing the blocks (e.g. 'contentRows'). Use inspect-blocks to find this."),
|
|
5829
5849
|
values: z.array(z.object({
|
|
5830
|
-
alias:
|
|
5850
|
+
alias: blockPropertyAliasSchema.describe("The property alias within the block"),
|
|
5831
5851
|
value: z.any().describe("The new value for the property")
|
|
5832
5852
|
})).min(1).describe("Properties to update on every matching block"),
|
|
5833
5853
|
culture: z.string().nullable().optional().describe("Culture code if the document property is variant"),
|
|
@@ -5843,7 +5863,8 @@ var outputSchema85 = z.object({
|
|
|
5843
5863
|
previousVersionId: z.string().optional(),
|
|
5844
5864
|
error: z.union([z.string(), z.record(z.string(), z.unknown())]).optional(),
|
|
5845
5865
|
previewUrl: previewUrlSchema.optional(),
|
|
5846
|
-
validation: validationResultSchema.optional()
|
|
5866
|
+
validation: validationResultSchema.optional(),
|
|
5867
|
+
warnings: z.array(z.string()).optional()
|
|
5847
5868
|
})),
|
|
5848
5869
|
successCount: z.number(),
|
|
5849
5870
|
failureCount: z.number(),
|
|
@@ -5887,6 +5908,7 @@ var tool85 = {
|
|
|
5887
5908
|
});
|
|
5888
5909
|
const items = [];
|
|
5889
5910
|
const pageBlocks = /* @__PURE__ */ new Map();
|
|
5911
|
+
const docValuesByItem = /* @__PURE__ */ new Map();
|
|
5890
5912
|
for (const id of ids) {
|
|
5891
5913
|
const docResult = await chainCms("get-document-by-id", { id });
|
|
5892
5914
|
if (!docResult.ok) continue;
|
|
@@ -5900,6 +5922,7 @@ var tool85 = {
|
|
|
5900
5922
|
const currentVersionId = versionData?.items?.[0]?.id ?? "";
|
|
5901
5923
|
items.push({ id, name, currentVersionId });
|
|
5902
5924
|
pageBlocks.set(id, findMatchingBlocks(doc, propertyAlias, contentTypeKey));
|
|
5925
|
+
docValuesByItem.set(id, doc.values ?? []);
|
|
5903
5926
|
}
|
|
5904
5927
|
if (items.length === 0) {
|
|
5905
5928
|
return createToolResult({
|
|
@@ -5972,28 +5995,68 @@ Changes will be saved but not published.`;
|
|
|
5972
5995
|
updates
|
|
5973
5996
|
});
|
|
5974
5997
|
if (!updateResult.ok) {
|
|
5998
|
+
const enriched = enrichBlockNotFoundError(
|
|
5999
|
+
updateResult.errorResult,
|
|
6000
|
+
docValuesByItem.get(item.id) ?? [],
|
|
6001
|
+
{ propertyAlias }
|
|
6002
|
+
);
|
|
5975
6003
|
results.push({
|
|
5976
6004
|
id: item.id,
|
|
5977
6005
|
name: item.name,
|
|
5978
6006
|
success: false,
|
|
5979
6007
|
blocksUpdated: 0,
|
|
5980
6008
|
previousVersionId: item.currentVersionId || void 0,
|
|
5981
|
-
error: parseBulkError(
|
|
6009
|
+
error: parseBulkError(enriched)
|
|
5982
6010
|
});
|
|
5983
6011
|
stopped = true;
|
|
5984
6012
|
} else {
|
|
5985
|
-
|
|
5986
|
-
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
|
|
5990
|
-
|
|
5991
|
-
|
|
5992
|
-
|
|
6013
|
+
const blockResults = updateResult.data.results;
|
|
6014
|
+
if (!blockResults || blockResults.length === 0) {
|
|
6015
|
+
results.push({
|
|
6016
|
+
id: item.id,
|
|
6017
|
+
name: item.name,
|
|
6018
|
+
success: false,
|
|
6019
|
+
blocksUpdated: 0,
|
|
6020
|
+
previousVersionId: item.currentVersionId || void 0,
|
|
6021
|
+
error: "update-block-property returned no per-block result \u2014 cannot confirm the write succeeded."
|
|
6022
|
+
});
|
|
6023
|
+
stopped = true;
|
|
6024
|
+
} else {
|
|
6025
|
+
const classification = classifyBlockUpdateResults(blockResults, blocks.length * values.length, fieldNames, blocks.length);
|
|
6026
|
+
if (classification.outcome === "clean") {
|
|
6027
|
+
totalBlocksUpdated += blocks.length;
|
|
6028
|
+
results.push({
|
|
6029
|
+
id: item.id,
|
|
6030
|
+
name: item.name,
|
|
6031
|
+
success: true,
|
|
6032
|
+
blocksUpdated: blocks.length,
|
|
6033
|
+
previousVersionId: item.currentVersionId || void 0,
|
|
6034
|
+
...classification.warnings.length ? { warnings: classification.warnings } : {}
|
|
6035
|
+
});
|
|
6036
|
+
} else {
|
|
6037
|
+
totalBlocksUpdated += classification.updatedEntryCount;
|
|
6038
|
+
const totalProperties = blocks.length * values.length;
|
|
6039
|
+
results.push({
|
|
6040
|
+
id: item.id,
|
|
6041
|
+
name: item.name,
|
|
6042
|
+
success: false,
|
|
6043
|
+
blocksUpdated: classification.updatedEntryCount,
|
|
6044
|
+
previousVersionId: item.currentVersionId || void 0,
|
|
6045
|
+
error: classification.outcome === "failed" ? `Block update failed: ${classification.detail}` : {
|
|
6046
|
+
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}`,
|
|
6047
|
+
savedFields: classification.savedFields,
|
|
6048
|
+
failedFields: classification.failedFields,
|
|
6049
|
+
...classification.savedFields.length > 0 ? { note: "savedFields were written to the document and must not be retried." } : {}
|
|
6050
|
+
},
|
|
6051
|
+
...classification.warnings.length ? { warnings: classification.warnings } : {}
|
|
6052
|
+
});
|
|
6053
|
+
stopped = true;
|
|
6054
|
+
}
|
|
6055
|
+
}
|
|
5993
6056
|
}
|
|
5994
6057
|
}
|
|
5995
6058
|
for (const row of results) {
|
|
5996
|
-
if (
|
|
6059
|
+
if (row.blocksUpdated === 0) continue;
|
|
5997
6060
|
row.validation = await validateDocumentState(row.id);
|
|
5998
6061
|
row.previewUrl = await fetchPreviewUrl(row.id);
|
|
5999
6062
|
}
|
|
@@ -6078,12 +6141,10 @@ var tool86 = {
|
|
|
6078
6141
|
var search_members_default = withStandardDecorators(tool86);
|
|
6079
6142
|
|
|
6080
6143
|
// src/umbraco-api/tools/member/sensitive-data-access.ts
|
|
6081
|
-
|
|
6082
|
-
async function hasSensitiveDataAccess() {
|
|
6083
|
-
if (cachedAccess !== void 0) return cachedAccess;
|
|
6144
|
+
async function checkSensitiveDataAccess() {
|
|
6084
6145
|
const result = await chainCms("get-user-current", {});
|
|
6085
|
-
|
|
6086
|
-
return
|
|
6146
|
+
if (!result.ok) return result;
|
|
6147
|
+
return { ok: true, hasAccess: result.data.hasAccessToSensitiveData ?? false };
|
|
6087
6148
|
}
|
|
6088
6149
|
|
|
6089
6150
|
// src/umbraco-api/tools/member/get/get-member.ts
|
|
@@ -6121,7 +6182,8 @@ var tool87 = {
|
|
|
6121
6182
|
const result = await chainCms("get-member", { id });
|
|
6122
6183
|
if (!result.ok) return result.errorResult;
|
|
6123
6184
|
const data = result.data;
|
|
6124
|
-
const
|
|
6185
|
+
const accessCheck = await checkSensitiveDataAccess();
|
|
6186
|
+
const accessible = accessCheck.ok && accessCheck.hasAccess;
|
|
6125
6187
|
return createToolResult({
|
|
6126
6188
|
id: data.id ?? id,
|
|
6127
6189
|
name: data.variants?.[0]?.name ?? "Unknown",
|
|
@@ -6280,12 +6342,16 @@ var tool90 = {
|
|
|
6280
6342
|
slices: ["update"],
|
|
6281
6343
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true },
|
|
6282
6344
|
handler: async ({ id, name, email, username, newPassword, isTwoFactorEnabled, isApproved, isLockedOut, groups, values }, extra) => {
|
|
6283
|
-
if (
|
|
6284
|
-
|
|
6285
|
-
|
|
6286
|
-
|
|
6287
|
-
|
|
6288
|
-
|
|
6345
|
+
if (isApproved !== void 0 || isLockedOut !== void 0 || isTwoFactorEnabled !== void 0) {
|
|
6346
|
+
const accessCheck = await checkSensitiveDataAccess();
|
|
6347
|
+
if (!accessCheck.ok) return accessCheck.errorResult;
|
|
6348
|
+
if (!accessCheck.hasAccess) {
|
|
6349
|
+
return createToolResultError({
|
|
6350
|
+
status: 403,
|
|
6351
|
+
title: "Sensitive Data access required",
|
|
6352
|
+
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."
|
|
6353
|
+
});
|
|
6354
|
+
}
|
|
6289
6355
|
}
|
|
6290
6356
|
const memberResult = await chainCms("get-member", { id });
|
|
6291
6357
|
if (!memberResult.ok) return memberResult.errorResult;
|