@umbraco-cms/mcp-editor 17.6.0-beta.6 → 17.6.0-beta.8
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 +1016 -820
- package/dist/collections.js.map +1 -1
- package/dist/index.js +1024 -829
- 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({
|
|
@@ -120,78 +141,21 @@ async function chainCms(toolName, args) {
|
|
|
120
141
|
}
|
|
121
142
|
return { ok: true, data: extractChainedResult(result) };
|
|
122
143
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const stripped = stripHtml(text);
|
|
131
|
-
if (!stripped) return 0;
|
|
132
|
-
return stripped.split(/\s+/).filter(Boolean).length;
|
|
133
|
-
}
|
|
134
|
-
function extractTextFromBlockValues(innerValues) {
|
|
135
|
-
const parts = [];
|
|
136
|
-
for (const v of innerValues || []) {
|
|
137
|
-
const text = extractTextFromValue(v.value, v.editorAlias);
|
|
138
|
-
if (text) parts.push(text);
|
|
139
|
-
}
|
|
140
|
-
return parts.join(" ");
|
|
141
|
-
}
|
|
142
|
-
function extractTextFromValue(value, editorAlias) {
|
|
143
|
-
if (typeof value === "string") {
|
|
144
|
-
return stripHtml(value);
|
|
145
|
-
}
|
|
146
|
-
if (value && typeof value === "object" && typeof value.markup === "string") {
|
|
147
|
-
const markupText = stripHtml(value.markup);
|
|
148
|
-
const blockText = extractTextFromContentData(value.blocks?.contentData);
|
|
149
|
-
return [markupText, blockText].filter(Boolean).join(" ");
|
|
150
|
-
}
|
|
151
|
-
if (value && typeof value === "object" && Array.isArray(value.contentData)) {
|
|
152
|
-
return extractTextFromContentData(value.contentData);
|
|
153
|
-
}
|
|
154
|
-
return "";
|
|
155
|
-
}
|
|
156
|
-
function extractTextFromContentData(contentData) {
|
|
157
|
-
const parts = [];
|
|
158
|
-
for (const block of contentData || []) {
|
|
159
|
-
const blockText = extractTextFromBlockValues(block.values || []);
|
|
160
|
-
if (blockText) parts.push(blockText);
|
|
161
|
-
}
|
|
162
|
-
return parts.join(" ");
|
|
163
|
-
}
|
|
164
|
-
function extractTextContent(values) {
|
|
165
|
-
const parts = [];
|
|
166
|
-
for (const v of values || []) {
|
|
167
|
-
const text = extractTextFromValue(v.value, v.editorAlias);
|
|
168
|
-
if (text) parts.push(text);
|
|
169
|
-
}
|
|
170
|
-
return parts.filter(Boolean).join(" ").replace(/\s+/g, " ").trim();
|
|
171
|
-
}
|
|
172
|
-
function extractHeadings(html) {
|
|
173
|
-
const headings = [];
|
|
174
|
-
const regex = /<h([1-6])[^>]*>(.*?)<\/h[1-6]>/gi;
|
|
175
|
-
let match;
|
|
176
|
-
while ((match = regex.exec(html)) !== null) {
|
|
177
|
-
headings.push({ level: parseInt(match[1]), text: stripHtml(match[2]) });
|
|
178
|
-
}
|
|
179
|
-
return headings;
|
|
144
|
+
var DEFAULT_PROVIDER_ALIAS = "umbDocumentUrlProvider";
|
|
145
|
+
var URL_BATCH_CHUNK_SIZE = 40;
|
|
146
|
+
function describeChainError(errorResult) {
|
|
147
|
+
const problem = extractInnerProblemDetails(errorResult);
|
|
148
|
+
const title = typeof problem.title === "string" ? problem.title : void 0;
|
|
149
|
+
const detail = typeof problem.detail === "string" ? problem.detail : void 0;
|
|
150
|
+
return [title, detail].filter(Boolean).join(": ") || "unknown error";
|
|
180
151
|
}
|
|
181
|
-
function
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
while ((match = regex.exec(html)) !== null) {
|
|
186
|
-
const srcMatch = match[0].match(/src="([^"]*)"/i);
|
|
187
|
-
const altMatch = match[0].match(/alt="([^"]*)"/i);
|
|
188
|
-
const src = srcMatch?.[1] ?? "";
|
|
189
|
-
const alt = altMatch?.[1] ?? "";
|
|
190
|
-
images.push({ src, alt, hasAlt: !!altMatch && alt.length > 0 });
|
|
152
|
+
function chunkIds(ids, size) {
|
|
153
|
+
const chunks = [];
|
|
154
|
+
for (let i = 0; i < ids.length; i += size) {
|
|
155
|
+
chunks.push(ids.slice(i, i + size));
|
|
191
156
|
}
|
|
192
|
-
return
|
|
157
|
+
return chunks;
|
|
193
158
|
}
|
|
194
|
-
var DEFAULT_PROVIDER_ALIAS = "umbDocumentUrlProvider";
|
|
195
159
|
var cachedBaseUrl = null;
|
|
196
160
|
var cachedMtimeMs = null;
|
|
197
161
|
function readBaseUrlFromEnvFile(envPath) {
|
|
@@ -297,26 +261,131 @@ function flattenPublishedUrls(urls) {
|
|
|
297
261
|
async function fetchPublishedUrls(id) {
|
|
298
262
|
try {
|
|
299
263
|
const result = await chainCms("get-document-urls", { id: [id] });
|
|
300
|
-
if (!result.ok)
|
|
264
|
+
if (!result.ok) {
|
|
265
|
+
console.warn(
|
|
266
|
+
`fetchPublishedUrls: get-document-urls failed for id ${id} \u2014 returning no published URLs: ${describeChainError(result.errorResult)}`
|
|
267
|
+
);
|
|
268
|
+
return [];
|
|
269
|
+
}
|
|
301
270
|
return flattenPublishedUrls(result.data.items);
|
|
302
|
-
} catch {
|
|
271
|
+
} catch (error) {
|
|
272
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
273
|
+
console.warn(
|
|
274
|
+
`fetchPublishedUrls: unexpected error fetching published URLs for id ${id} \u2014 returning no published URLs: ${message}`
|
|
275
|
+
);
|
|
303
276
|
return [];
|
|
304
277
|
}
|
|
305
278
|
}
|
|
306
279
|
async function fetchPublishedUrlsBatch(ids) {
|
|
307
280
|
const out = /* @__PURE__ */ new Map();
|
|
308
281
|
if (ids.length === 0) return out;
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
282
|
+
for (const idChunk of chunkIds(ids, URL_BATCH_CHUNK_SIZE)) {
|
|
283
|
+
try {
|
|
284
|
+
const result = await chainCms("get-document-urls", { id: idChunk });
|
|
285
|
+
if (!result.ok) {
|
|
286
|
+
console.warn(
|
|
287
|
+
`fetchPublishedUrlsBatch: get-document-urls failed for a chunk of ${idChunk.length} ids \u2014 those ids will have no published URL: ${describeChainError(result.errorResult)}`
|
|
288
|
+
);
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
for (const entry of result.data.items ?? []) {
|
|
292
|
+
if (!entry?.id) continue;
|
|
293
|
+
out.set(entry.id, flattenPublishedUrls([entry]));
|
|
294
|
+
}
|
|
295
|
+
} catch (error) {
|
|
296
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
297
|
+
console.warn(
|
|
298
|
+
`fetchPublishedUrlsBatch: unexpected error processing a chunk of ${idChunk.length} ids \u2014 those ids will have no published URL: ${message}`
|
|
299
|
+
);
|
|
315
300
|
}
|
|
316
|
-
} catch {
|
|
317
301
|
}
|
|
318
302
|
return out;
|
|
319
303
|
}
|
|
304
|
+
async function fetchPrimaryPublishedUrl(id) {
|
|
305
|
+
const urls = await fetchPublishedUrls(id);
|
|
306
|
+
return urls[0] ?? "";
|
|
307
|
+
}
|
|
308
|
+
async function fetchPrimaryPublishedUrlsBatch(ids) {
|
|
309
|
+
const batch = await fetchPublishedUrlsBatch(ids);
|
|
310
|
+
const out = /* @__PURE__ */ new Map();
|
|
311
|
+
for (const id of ids) {
|
|
312
|
+
out.set(id, batch.get(id)?.[0] ?? "");
|
|
313
|
+
}
|
|
314
|
+
return out;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// src/umbraco-api/tools/helpers/tree-walker.ts
|
|
318
|
+
function buildChainedCursor(skip, take) {
|
|
319
|
+
return encodeCursor({ s: skip, t: take });
|
|
320
|
+
}
|
|
321
|
+
function stripHtml(html) {
|
|
322
|
+
return (html || "").replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
|
|
323
|
+
}
|
|
324
|
+
function countWords(text) {
|
|
325
|
+
const stripped = stripHtml(text);
|
|
326
|
+
if (!stripped) return 0;
|
|
327
|
+
return stripped.split(/\s+/).filter(Boolean).length;
|
|
328
|
+
}
|
|
329
|
+
function extractTextFromBlockValues(innerValues) {
|
|
330
|
+
const parts = [];
|
|
331
|
+
for (const v of innerValues || []) {
|
|
332
|
+
const text = extractTextFromValue(v.value, v.editorAlias);
|
|
333
|
+
if (text) parts.push(text);
|
|
334
|
+
}
|
|
335
|
+
return parts.join(" ");
|
|
336
|
+
}
|
|
337
|
+
function extractTextFromValue(value, editorAlias) {
|
|
338
|
+
if (typeof value === "string") {
|
|
339
|
+
return stripHtml(value);
|
|
340
|
+
}
|
|
341
|
+
if (value && typeof value === "object" && typeof value.markup === "string") {
|
|
342
|
+
const markupText = stripHtml(value.markup);
|
|
343
|
+
const blockText = extractTextFromContentData(value.blocks?.contentData);
|
|
344
|
+
return [markupText, blockText].filter(Boolean).join(" ");
|
|
345
|
+
}
|
|
346
|
+
if (value && typeof value === "object" && Array.isArray(value.contentData)) {
|
|
347
|
+
return extractTextFromContentData(value.contentData);
|
|
348
|
+
}
|
|
349
|
+
return "";
|
|
350
|
+
}
|
|
351
|
+
function extractTextFromContentData(contentData) {
|
|
352
|
+
const parts = [];
|
|
353
|
+
for (const block of contentData || []) {
|
|
354
|
+
const blockText = extractTextFromBlockValues(block.values || []);
|
|
355
|
+
if (blockText) parts.push(blockText);
|
|
356
|
+
}
|
|
357
|
+
return parts.join(" ");
|
|
358
|
+
}
|
|
359
|
+
function extractTextContent(values) {
|
|
360
|
+
const parts = [];
|
|
361
|
+
for (const v of values || []) {
|
|
362
|
+
const text = extractTextFromValue(v.value, v.editorAlias);
|
|
363
|
+
if (text) parts.push(text);
|
|
364
|
+
}
|
|
365
|
+
return parts.filter(Boolean).join(" ").replace(/\s+/g, " ").trim();
|
|
366
|
+
}
|
|
367
|
+
function extractHeadings(html) {
|
|
368
|
+
const headings = [];
|
|
369
|
+
const regex = /<h([1-6])[^>]*>(.*?)<\/h[1-6]>/gi;
|
|
370
|
+
let match;
|
|
371
|
+
while ((match = regex.exec(html)) !== null) {
|
|
372
|
+
headings.push({ level: parseInt(match[1]), text: stripHtml(match[2]) });
|
|
373
|
+
}
|
|
374
|
+
return headings;
|
|
375
|
+
}
|
|
376
|
+
function extractImages(html) {
|
|
377
|
+
const images = [];
|
|
378
|
+
const regex = /<img[^>]*>/gi;
|
|
379
|
+
let match;
|
|
380
|
+
while ((match = regex.exec(html)) !== null) {
|
|
381
|
+
const srcMatch = match[0].match(/src="([^"]*)"/i);
|
|
382
|
+
const altMatch = match[0].match(/alt="([^"]*)"/i);
|
|
383
|
+
const src = srcMatch?.[1] ?? "";
|
|
384
|
+
const alt = altMatch?.[1] ?? "";
|
|
385
|
+
images.push({ src, alt, hasAlt: !!altMatch && alt.length > 0 });
|
|
386
|
+
}
|
|
387
|
+
return images;
|
|
388
|
+
}
|
|
320
389
|
|
|
321
390
|
// src/umbraco-api/tools/content/get/search-content.ts
|
|
322
391
|
var inputSchema = {
|
|
@@ -335,7 +404,7 @@ var outputSchema = z.object({
|
|
|
335
404
|
});
|
|
336
405
|
var tool = {
|
|
337
406
|
name: "search-content",
|
|
338
|
-
description: "Search for content pages by name or
|
|
407
|
+
description: "Search for content pages by name only \u2014 it does not match body text or other field values (tracked in #234). Returns a list of matching pages with their names and IDs. For body text, use list-children + get-page instead. Use get-page with an ID from the results to retrieve full page content.",
|
|
339
408
|
inputSchema,
|
|
340
409
|
outputSchema,
|
|
341
410
|
slices: ["search"],
|
|
@@ -411,8 +480,10 @@ var tool2 = {
|
|
|
411
480
|
})),
|
|
412
481
|
variants: doc.variants ?? [],
|
|
413
482
|
previewUrl: buildPreviewUrl(doc.id),
|
|
414
|
-
//
|
|
415
|
-
|
|
483
|
+
// The get-document-by-id response doesn't carry `urls` — published
|
|
484
|
+
// URLs come only from the separate get-document-urls endpoint via
|
|
485
|
+
// fetchPublishedUrls.
|
|
486
|
+
publishedUrls: await fetchPublishedUrls(id)
|
|
416
487
|
});
|
|
417
488
|
}
|
|
418
489
|
};
|
|
@@ -458,6 +529,19 @@ var tool3 = {
|
|
|
458
529
|
}
|
|
459
530
|
};
|
|
460
531
|
var list_children_default = withStandardDecorators(tool3);
|
|
532
|
+
|
|
533
|
+
// src/auth/auth-policies.ts
|
|
534
|
+
var sections = {
|
|
535
|
+
settings: "Umb.Section.Settings"};
|
|
536
|
+
|
|
537
|
+
// src/umbraco-api/tools/helpers/settings-access.ts
|
|
538
|
+
async function checkSettingsAccess() {
|
|
539
|
+
const result = await chainCms("get-user-current", {});
|
|
540
|
+
if (!result.ok) return result;
|
|
541
|
+
return { ok: true, hasAccess: result.data.allowedSections?.includes(sections.settings) ?? false };
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
// src/umbraco-api/tools/content/get/list-document-types.ts
|
|
461
545
|
var inputSchema4 = {
|
|
462
546
|
take: z.number().optional().default(50).describe("Number of results to return"),
|
|
463
547
|
skip: z.number().optional().default(0).describe("Number of results to skip")
|
|
@@ -480,11 +564,14 @@ async function collectDocumentTypeIds() {
|
|
|
480
564
|
let result;
|
|
481
565
|
while (true) {
|
|
482
566
|
result = parentId ? await chainCms("get-document-type-children", { parentId, cursor }) : await chainCms("get-document-type-root", { cursor });
|
|
483
|
-
if (!result.ok) return;
|
|
567
|
+
if (!result.ok) return { ok: false, errorResult: result.errorResult };
|
|
484
568
|
const items = result.data.items ?? [];
|
|
485
569
|
for (const item of items) {
|
|
486
570
|
if (item.isFolder) {
|
|
487
|
-
if (item.hasChildren)
|
|
571
|
+
if (item.hasChildren) {
|
|
572
|
+
const childResult = await walk(item.id);
|
|
573
|
+
if (childResult && !childResult.ok) return childResult;
|
|
574
|
+
}
|
|
488
575
|
} else {
|
|
489
576
|
collected.push(item);
|
|
490
577
|
}
|
|
@@ -493,26 +580,35 @@ async function collectDocumentTypeIds() {
|
|
|
493
580
|
if (!nextCursor) break;
|
|
494
581
|
cursor = nextCursor;
|
|
495
582
|
}
|
|
583
|
+
return void 0;
|
|
496
584
|
}
|
|
497
|
-
await walk(void 0);
|
|
498
|
-
return
|
|
585
|
+
const failure = await walk(void 0);
|
|
586
|
+
if (failure && !failure.ok) return failure;
|
|
587
|
+
return { ok: true, nodes: collected };
|
|
499
588
|
}
|
|
500
589
|
async function resolveDocTypeDetails(nodes) {
|
|
501
590
|
const results = await Promise.all(
|
|
502
591
|
nodes.map(async (node) => {
|
|
503
592
|
const detailResult = await chainCms("get-document-type-by-id", { id: node.id });
|
|
504
|
-
if (!detailResult.ok) return
|
|
593
|
+
if (!detailResult.ok) return { ok: false, errorResult: detailResult.errorResult, node };
|
|
505
594
|
const d = detailResult.data;
|
|
506
595
|
return {
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
596
|
+
ok: true,
|
|
597
|
+
details: [{
|
|
598
|
+
id: node.id,
|
|
599
|
+
alias: d.alias ?? "",
|
|
600
|
+
name: d.name ?? node.name,
|
|
601
|
+
description: d.description ?? void 0,
|
|
602
|
+
icon: d.icon ?? node.icon
|
|
603
|
+
}],
|
|
604
|
+
node
|
|
512
605
|
};
|
|
513
606
|
})
|
|
514
607
|
);
|
|
515
|
-
|
|
608
|
+
const failed = results.find((r) => !r.ok);
|
|
609
|
+
if (failed && !failed.ok) return { ok: false, errorResult: failed.errorResult };
|
|
610
|
+
const details = results.flatMap((r) => r.ok ? r.details : []);
|
|
611
|
+
return { ok: true, details };
|
|
516
612
|
}
|
|
517
613
|
var tool4 = {
|
|
518
614
|
name: "list-document-types",
|
|
@@ -522,9 +618,22 @@ var tool4 = {
|
|
|
522
618
|
slices: ["list"],
|
|
523
619
|
annotations: { readOnlyHint: true },
|
|
524
620
|
handler: async ({ take, skip }) => {
|
|
525
|
-
const
|
|
621
|
+
const accessCheck = await checkSettingsAccess();
|
|
622
|
+
if (!accessCheck.ok) return accessCheck.errorResult;
|
|
623
|
+
if (!accessCheck.hasAccess) {
|
|
624
|
+
return createToolResultError({
|
|
625
|
+
status: 403,
|
|
626
|
+
title: "Settings access required",
|
|
627
|
+
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."
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
const treeResult = await collectDocumentTypeIds();
|
|
631
|
+
if (!treeResult.ok) return treeResult.errorResult;
|
|
632
|
+
const { nodes } = treeResult;
|
|
526
633
|
const sliced = nodes.slice(skip, skip + take);
|
|
527
|
-
const
|
|
634
|
+
const detailsResult = await resolveDocTypeDetails(sliced);
|
|
635
|
+
if (!detailsResult.ok) return detailsResult.errorResult;
|
|
636
|
+
const { details } = detailsResult;
|
|
528
637
|
return createToolResult({
|
|
529
638
|
items: details.map((d) => ({
|
|
530
639
|
id: d.id,
|
|
@@ -538,6 +647,73 @@ var tool4 = {
|
|
|
538
647
|
}
|
|
539
648
|
};
|
|
540
649
|
var list_document_types_default = withStandardDecorators(tool4);
|
|
650
|
+
|
|
651
|
+
// src/umbraco-api/tools/content/helpers/resolve-document-type-properties.ts
|
|
652
|
+
async function resolveDocumentTypeProperties(documentTypeId) {
|
|
653
|
+
const docTypeResult = await chainCms("get-document-type-by-id", { id: documentTypeId });
|
|
654
|
+
if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
|
|
655
|
+
const data = docTypeResult.data;
|
|
656
|
+
const collected = /* @__PURE__ */ new Map();
|
|
657
|
+
function addProperties(props) {
|
|
658
|
+
for (const p of props) {
|
|
659
|
+
if (p.alias && !collected.has(p.alias)) {
|
|
660
|
+
collected.set(p.alias, p);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
function compositionIdsOf(d) {
|
|
665
|
+
return Array.from(
|
|
666
|
+
new Set(
|
|
667
|
+
(d.compositions ?? []).map((c) => c.documentType?.id).filter((id) => typeof id === "string")
|
|
668
|
+
)
|
|
669
|
+
);
|
|
670
|
+
}
|
|
671
|
+
function describeFailure(errorResult) {
|
|
672
|
+
const text = errorResult.content?.[0]?.type === "text" ? errorResult.content[0].text : void 0;
|
|
673
|
+
if (!text) return "unknown error";
|
|
674
|
+
try {
|
|
675
|
+
const parsed = JSON.parse(text);
|
|
676
|
+
const detail = parsed?.detail;
|
|
677
|
+
return typeof detail === "string" ? detail : text;
|
|
678
|
+
} catch {
|
|
679
|
+
return text;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
addProperties(Array.isArray(data.properties) ? data.properties : []);
|
|
683
|
+
const visited = /* @__PURE__ */ new Set([documentTypeId]);
|
|
684
|
+
const failedCompositionIds = [];
|
|
685
|
+
const failedCompositionDetails = [];
|
|
686
|
+
let frontier = compositionIdsOf(data).filter((id) => !visited.has(id));
|
|
687
|
+
frontier.forEach((id) => visited.add(id));
|
|
688
|
+
while (frontier.length > 0) {
|
|
689
|
+
const results = await Promise.all(frontier.map((id) => chainCms("get-document-type-by-id", { id })));
|
|
690
|
+
const nextFrontier = [];
|
|
691
|
+
results.forEach((r, i) => {
|
|
692
|
+
if (!r.ok) {
|
|
693
|
+
failedCompositionIds.push(frontier[i]);
|
|
694
|
+
failedCompositionDetails.push(describeFailure(r.errorResult));
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
if (Array.isArray(r.data.properties)) addProperties(r.data.properties);
|
|
698
|
+
for (const id of compositionIdsOf(r.data)) {
|
|
699
|
+
if (!visited.has(id)) {
|
|
700
|
+
visited.add(id);
|
|
701
|
+
nextFrontier.push(id);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
});
|
|
705
|
+
frontier = nextFrontier;
|
|
706
|
+
}
|
|
707
|
+
return {
|
|
708
|
+
ok: true,
|
|
709
|
+
documentType: data,
|
|
710
|
+
properties: Array.from(collected.values()),
|
|
711
|
+
failedCompositionIds,
|
|
712
|
+
failedCompositionDetails
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
// src/umbraco-api/tools/content/get/get-document-type.ts
|
|
541
717
|
var inputSchema5 = {
|
|
542
718
|
id: z.string().uuid().describe("UUID of the document type to retrieve")
|
|
543
719
|
};
|
|
@@ -565,30 +741,9 @@ var tool5 = {
|
|
|
565
741
|
slices: ["read"],
|
|
566
742
|
annotations: { readOnlyHint: true },
|
|
567
743
|
handler: async ({ id }) => {
|
|
568
|
-
const result = await
|
|
744
|
+
const result = await resolveDocumentTypeProperties(id);
|
|
569
745
|
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
|
-
}
|
|
746
|
+
const { documentType: data, properties } = result;
|
|
592
747
|
return createToolResult({
|
|
593
748
|
id: data.id ?? id,
|
|
594
749
|
alias: data.alias ?? "",
|
|
@@ -596,7 +751,7 @@ var tool5 = {
|
|
|
596
751
|
description: data.description || void 0,
|
|
597
752
|
variesByCulture: data.variesByCulture || void 0,
|
|
598
753
|
variesBySegment: data.variesBySegment || void 0,
|
|
599
|
-
properties:
|
|
754
|
+
properties: properties.map((p) => ({
|
|
600
755
|
alias: p.alias ?? "",
|
|
601
756
|
name: p.name ?? p.alias ?? "",
|
|
602
757
|
description: p.description || void 0,
|
|
@@ -608,66 +763,294 @@ var tool5 = {
|
|
|
608
763
|
}
|
|
609
764
|
};
|
|
610
765
|
var get_document_type_default = withStandardDecorators(tool5);
|
|
611
|
-
var
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
previewUrl: previewUrlSchema,
|
|
619
|
-
blockProperties: z.array(z.object({
|
|
620
|
-
propertyAlias: z.string().describe("The document property containing these blocks"),
|
|
621
|
-
editorAlias: z.string().optional(),
|
|
622
|
-
blocks: z.array(z.object({
|
|
623
|
-
contentKey: z.string().describe("The block's unique key \u2014 use this with edit-block"),
|
|
624
|
-
contentTypeKey: z.string().describe("The block's element type ID"),
|
|
625
|
-
properties: z.array(z.object({
|
|
626
|
-
alias: z.string(),
|
|
627
|
-
value: z.any()
|
|
628
|
-
}))
|
|
629
|
-
}))
|
|
630
|
-
}))
|
|
766
|
+
var validationErrorSchema = z.object({
|
|
767
|
+
propertyAlias: z.string().describe(
|
|
768
|
+
"The alias of the property that failed validation, or '__document__' for document-level errors (mandatory cultures, name length, etc.)."
|
|
769
|
+
),
|
|
770
|
+
culture: z.string().nullable().optional().describe("Culture for variant content. Null for invariant."),
|
|
771
|
+
segment: z.string().nullable().optional().describe("Segment for segmented content. Null when none."),
|
|
772
|
+
message: z.string().describe("Human-readable validation error message.")
|
|
631
773
|
});
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
774
|
+
var validationResultSchema = z.object({
|
|
775
|
+
valid: z.boolean().describe("True when the saved document passes server-side validation and is publishable."),
|
|
776
|
+
errors: z.array(validationErrorSchema).describe(
|
|
777
|
+
"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."
|
|
778
|
+
)
|
|
779
|
+
}).describe(
|
|
780
|
+
"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."
|
|
781
|
+
);
|
|
782
|
+
async function validateDocumentState(id, doc) {
|
|
783
|
+
let target = null;
|
|
784
|
+
if (!target) {
|
|
785
|
+
const docResult = await chainCms("get-document-by-id", { id });
|
|
786
|
+
if (!docResult.ok) {
|
|
787
|
+
return {
|
|
788
|
+
valid: false,
|
|
789
|
+
errors: [
|
|
790
|
+
{
|
|
791
|
+
propertyAlias: "__document__",
|
|
792
|
+
message: "Could not refetch document to run validation."
|
|
793
|
+
}
|
|
794
|
+
]
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
target = docResult.data;
|
|
798
|
+
}
|
|
799
|
+
const values = (target.values ?? []).map((v) => ({
|
|
800
|
+
alias: v.alias,
|
|
801
|
+
value: v.value,
|
|
802
|
+
culture: v.culture ?? null,
|
|
803
|
+
segment: v.segment ?? null
|
|
804
|
+
}));
|
|
805
|
+
const variants = (target.variants ?? []).map((v) => ({
|
|
806
|
+
name: v.name,
|
|
807
|
+
culture: v.culture ?? null,
|
|
808
|
+
segment: v.segment ?? null
|
|
809
|
+
}));
|
|
810
|
+
const ancestorsResult = await chainCms("get-document-ancestors", { descendantId: id });
|
|
811
|
+
const parent = ancestorsResult.ok ? (ancestorsResult.data.items ?? []).find((item) => item.id === id)?.parent ?? null : null;
|
|
812
|
+
const result = await chainCms("validate-document", {
|
|
813
|
+
id,
|
|
814
|
+
documentType: { id: target.documentType.id },
|
|
815
|
+
template: target.template ? { id: target.template.id } : null,
|
|
816
|
+
parent,
|
|
817
|
+
values,
|
|
818
|
+
variants
|
|
819
|
+
});
|
|
820
|
+
if (result.ok) {
|
|
821
|
+
return { valid: true, errors: [] };
|
|
822
|
+
}
|
|
823
|
+
return { valid: false, errors: parseValidationErrors(result.errorResult, values) };
|
|
824
|
+
}
|
|
825
|
+
function parseValidationErrors(errorResult, requestValues) {
|
|
826
|
+
const structured = extractStructured(errorResult);
|
|
827
|
+
if (!structured) {
|
|
828
|
+
return [
|
|
829
|
+
{
|
|
830
|
+
propertyAlias: "__document__",
|
|
831
|
+
message: stringifyErrorFallback(errorResult)
|
|
832
|
+
}
|
|
833
|
+
];
|
|
834
|
+
}
|
|
835
|
+
const errors = structured.errors;
|
|
836
|
+
if (!errors || typeof errors !== "object") {
|
|
837
|
+
return [
|
|
838
|
+
{
|
|
839
|
+
propertyAlias: "__document__",
|
|
840
|
+
message: stringifyFromProblemDetails(structured)
|
|
841
|
+
}
|
|
842
|
+
];
|
|
843
|
+
}
|
|
844
|
+
const out = [];
|
|
845
|
+
for (const [jsonPath, messages] of Object.entries(errors)) {
|
|
846
|
+
const messageList = Array.isArray(messages) ? messages : [String(messages)];
|
|
847
|
+
const resolved = resolveJsonPath(jsonPath, requestValues);
|
|
848
|
+
for (const message of messageList) {
|
|
849
|
+
out.push({
|
|
850
|
+
propertyAlias: resolved.propertyAlias,
|
|
851
|
+
culture: resolved.culture,
|
|
852
|
+
segment: resolved.segment,
|
|
853
|
+
message: String(message)
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
if (out.length === 0) {
|
|
858
|
+
out.push({
|
|
859
|
+
propertyAlias: "__document__",
|
|
860
|
+
message: stringifyFromProblemDetails(structured)
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
return out;
|
|
864
|
+
}
|
|
865
|
+
var VALUES_PATH = /^\$\.values\[(\d+)\](?:\.value)?(.*)$/;
|
|
866
|
+
function resolveJsonPath(jsonPath, requestValues) {
|
|
867
|
+
const match = jsonPath.match(VALUES_PATH);
|
|
868
|
+
if (match) {
|
|
869
|
+
const index = Number(match[1]);
|
|
870
|
+
const entry = requestValues[index];
|
|
871
|
+
if (entry) {
|
|
872
|
+
const trailing = match[2]?.replace(/^\./, "");
|
|
873
|
+
return {
|
|
874
|
+
propertyAlias: trailing ? `${entry.alias}${match[2]}` : entry.alias,
|
|
875
|
+
culture: entry.culture,
|
|
876
|
+
segment: entry.segment
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
return { propertyAlias: jsonPath, culture: null, segment: null };
|
|
881
|
+
}
|
|
882
|
+
function extractStructured(errorResult) {
|
|
883
|
+
if (!errorResult || typeof errorResult !== "object") return null;
|
|
884
|
+
const r = errorResult;
|
|
885
|
+
if (r.structuredContent && typeof r.structuredContent === "object") {
|
|
886
|
+
return r.structuredContent;
|
|
887
|
+
}
|
|
888
|
+
const text = r.content?.find((c) => c?.type === "text")?.text;
|
|
889
|
+
if (text) {
|
|
890
|
+
try {
|
|
891
|
+
const parsed = JSON.parse(text);
|
|
892
|
+
if (parsed && typeof parsed === "object") {
|
|
893
|
+
return parsed;
|
|
894
|
+
}
|
|
895
|
+
} catch {
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
return null;
|
|
899
|
+
}
|
|
900
|
+
function stringifyFromProblemDetails(pd) {
|
|
901
|
+
if (pd.detail && typeof pd.detail === "string") return pd.detail;
|
|
902
|
+
if (pd.title && typeof pd.title === "string") return pd.title;
|
|
903
|
+
return "Document failed validation but no detail was returned.";
|
|
904
|
+
}
|
|
905
|
+
function stringifyErrorFallback(errorResult) {
|
|
906
|
+
if (!errorResult || typeof errorResult !== "object") return "Document failed validation.";
|
|
907
|
+
const r = errorResult;
|
|
908
|
+
const text = r.content?.find((c) => c?.type === "text")?.text;
|
|
909
|
+
return text ? text : "Document failed validation.";
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
// src/umbraco-api/tools/helpers/block-builder.ts
|
|
913
|
+
async function toBlockProperties(elementTypeKey, values, culture, segment) {
|
|
914
|
+
if (values.length === 0) return { ok: true, properties: [] };
|
|
915
|
+
const docTypeResult = await chainCms("get-document-type-by-id", { id: elementTypeKey });
|
|
916
|
+
if (!docTypeResult.ok) return { ok: false, errorResult: docTypeResult.errorResult };
|
|
917
|
+
const definitions = new Map(docTypeResult.data.properties.map((p) => [p.alias, p]));
|
|
918
|
+
return {
|
|
919
|
+
ok: true,
|
|
920
|
+
properties: values.map((v) => {
|
|
921
|
+
const def = definitions.get(v.alias);
|
|
922
|
+
return {
|
|
923
|
+
alias: v.alias,
|
|
924
|
+
value: v.value,
|
|
925
|
+
culture: def?.variesByCulture ? culture : null,
|
|
926
|
+
segment: def?.variesBySegment ? segment : null
|
|
927
|
+
};
|
|
928
|
+
})
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
async function toNewBlockProperties(contentTypeKey, values, settingsTypeKey, settingsValues, culture, segment) {
|
|
932
|
+
const content = await toBlockProperties(contentTypeKey, values, culture, segment);
|
|
933
|
+
if (!content.ok) return content;
|
|
934
|
+
if (!settingsTypeKey || !settingsValues) return { ok: true, properties: content.properties };
|
|
935
|
+
const settings = await toBlockProperties(settingsTypeKey, settingsValues, culture, segment);
|
|
936
|
+
if (!settings.ok) return settings;
|
|
937
|
+
return { ok: true, properties: content.properties, settings: { properties: settings.properties } };
|
|
938
|
+
}
|
|
939
|
+
function toPlacement(position) {
|
|
940
|
+
return position.mode === "before" || position.mode === "after" ? { position: position.mode, contentKey: position.anchorContentKey } : { position: position.mode };
|
|
941
|
+
}
|
|
942
|
+
async function buildBlockWriteResult(id, pageName, contentKey, baseMessage) {
|
|
943
|
+
const validation = await validateDocumentState(id);
|
|
944
|
+
const message = validation.valid ? baseMessage : `${baseMessage} \u2014 but ${validation.errors.length} validation error(s) must be resolved before this page can be published`;
|
|
945
|
+
return createToolResult({
|
|
946
|
+
message,
|
|
947
|
+
id,
|
|
948
|
+
name: pageName,
|
|
949
|
+
contentKey,
|
|
950
|
+
previewUrl: await fetchPreviewUrl(id),
|
|
951
|
+
validation
|
|
952
|
+
});
|
|
953
|
+
}
|
|
954
|
+
function isBlockListOrGridValue(value) {
|
|
955
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) && Array.isArray(value.contentData);
|
|
956
|
+
}
|
|
957
|
+
function isRteWithBlocks(value) {
|
|
958
|
+
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);
|
|
959
|
+
}
|
|
960
|
+
function findSettingsKey(container, contentKey) {
|
|
961
|
+
const layout = container?.layout;
|
|
962
|
+
if (!layout || typeof layout !== "object") return void 0;
|
|
963
|
+
return searchLayout(Object.values(layout), contentKey);
|
|
964
|
+
}
|
|
965
|
+
function searchLayout(entries, contentKey) {
|
|
966
|
+
for (const entry of entries) {
|
|
967
|
+
if (Array.isArray(entry)) {
|
|
968
|
+
const found = searchLayout(entry, contentKey);
|
|
969
|
+
if (found) return found;
|
|
970
|
+
continue;
|
|
971
|
+
}
|
|
972
|
+
if (!entry || typeof entry !== "object") continue;
|
|
973
|
+
const candidate = entry;
|
|
974
|
+
if (candidate.contentKey === contentKey) {
|
|
975
|
+
return typeof candidate.settingsKey === "string" && candidate.settingsKey.length > 0 ? candidate.settingsKey : void 0;
|
|
976
|
+
}
|
|
977
|
+
for (const nested of [candidate.areas, candidate.items]) {
|
|
978
|
+
if (Array.isArray(nested)) {
|
|
979
|
+
const found = searchLayout(nested, contentKey);
|
|
980
|
+
if (found) return found;
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
return void 0;
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
// src/umbraco-api/tools/content/get/inspect-blocks.ts
|
|
988
|
+
var inputSchema6 = {
|
|
989
|
+
id: z.string().uuid().describe("The ID of the page to inspect"),
|
|
990
|
+
propertyAlias: z.string().optional().describe("Specific property alias to inspect. If omitted, all block-based properties are shown.")
|
|
991
|
+
};
|
|
992
|
+
var outputSchema6 = z.object({
|
|
993
|
+
id: z.string(),
|
|
994
|
+
name: z.string(),
|
|
995
|
+
previewUrl: previewUrlSchema,
|
|
996
|
+
blockProperties: z.array(z.object({
|
|
997
|
+
propertyAlias: z.string().describe("The document property containing these blocks"),
|
|
998
|
+
editorAlias: z.string().optional(),
|
|
999
|
+
blocks: z.array(z.object({
|
|
1000
|
+
contentKey: z.string().describe("The block's unique key \u2014 use this with edit-block"),
|
|
1001
|
+
contentTypeKey: z.string().describe("The block's element type ID"),
|
|
1002
|
+
settingsKey: z.string().optional().describe("The key of the block's settings entry. Absent when the block has no settings."),
|
|
1003
|
+
properties: z.array(z.object({
|
|
1004
|
+
alias: z.string(),
|
|
1005
|
+
value: z.any()
|
|
1006
|
+
}))
|
|
1007
|
+
}))
|
|
1008
|
+
}))
|
|
1009
|
+
});
|
|
1010
|
+
function isBlockListOrGridValue2(value) {
|
|
1011
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) && Array.isArray(value.contentData);
|
|
1012
|
+
}
|
|
1013
|
+
function isRteWithBlocks2(value) {
|
|
1014
|
+
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);
|
|
1015
|
+
}
|
|
1016
|
+
function extractBlocks(contentData, container) {
|
|
1017
|
+
return contentData.map((block) => {
|
|
1018
|
+
const contentKey = block.key ?? "";
|
|
1019
|
+
const settingsKey = findSettingsKey(container, contentKey);
|
|
1020
|
+
return {
|
|
1021
|
+
contentKey,
|
|
1022
|
+
contentTypeKey: block.contentTypeKey ?? "",
|
|
1023
|
+
...settingsKey ? { settingsKey } : {},
|
|
1024
|
+
properties: Array.isArray(block.values) ? block.values.map((v) => ({ alias: v.alias ?? "", value: v.value })) : []
|
|
1025
|
+
};
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
1028
|
+
var tool6 = {
|
|
1029
|
+
name: "inspect-blocks",
|
|
1030
|
+
description: "Inspect the block structure of a content page. Shows each block's type, unique key, and property values. Use this to understand how content is structured inside BlockList, BlockGrid, or Rich Text properties before using edit-block to make changes.",
|
|
1031
|
+
inputSchema: inputSchema6,
|
|
1032
|
+
outputSchema: outputSchema6,
|
|
1033
|
+
slices: ["read"],
|
|
1034
|
+
annotations: { readOnlyHint: true },
|
|
1035
|
+
handler: async ({ id, propertyAlias }) => {
|
|
653
1036
|
const result = await chainCms("get-document-by-id", { id });
|
|
654
1037
|
if (!result.ok) return result.errorResult;
|
|
655
1038
|
const doc = result.data;
|
|
656
1039
|
const allValues = doc.values ?? [];
|
|
657
1040
|
const filtered = propertyAlias ? allValues.filter((v) => v.alias === propertyAlias) : allValues;
|
|
658
|
-
const blockProperties = filtered.filter((v) =>
|
|
1041
|
+
const blockProperties = filtered.filter((v) => isBlockListOrGridValue2(v.value) || isRteWithBlocks2(v.value)).map((v) => {
|
|
659
1042
|
const value = v.value;
|
|
660
|
-
if (
|
|
1043
|
+
if (isRteWithBlocks2(value)) {
|
|
661
1044
|
return {
|
|
662
1045
|
propertyAlias: v.alias,
|
|
663
1046
|
editorAlias: "Umbraco.RichText",
|
|
664
|
-
blocks: extractBlocks(value.blocks.contentData)
|
|
1047
|
+
blocks: extractBlocks(value.blocks.contentData, value.blocks)
|
|
665
1048
|
};
|
|
666
1049
|
}
|
|
667
1050
|
return {
|
|
668
1051
|
propertyAlias: v.alias,
|
|
669
1052
|
editorAlias: v.editorAlias ?? void 0,
|
|
670
|
-
blocks: extractBlocks(value.contentData)
|
|
1053
|
+
blocks: extractBlocks(value.contentData, value)
|
|
671
1054
|
};
|
|
672
1055
|
});
|
|
673
1056
|
return createToolResult({
|
|
@@ -1008,150 +1391,76 @@ ${aliases.join("\n")}`
|
|
|
1008
1391
|
}
|
|
1009
1392
|
};
|
|
1010
1393
|
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
|
-
let target = null;
|
|
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
|
-
};
|
|
1394
|
+
async function resolveEditorAliases(documentTypeId, values) {
|
|
1395
|
+
if (!values || values.length === 0) {
|
|
1396
|
+
return { ok: true, values: [] };
|
|
1397
|
+
}
|
|
1398
|
+
const docTypeResult = await resolveDocumentTypeProperties(documentTypeId);
|
|
1399
|
+
if (!docTypeResult.ok) return docTypeResult;
|
|
1400
|
+
const dataTypeIds = Array.from(
|
|
1401
|
+
new Set(
|
|
1402
|
+
docTypeResult.properties.map((p) => p.dataType?.id).filter((id) => typeof id === "string")
|
|
1403
|
+
)
|
|
1404
|
+
);
|
|
1405
|
+
const editorAliasByDataTypeId = /* @__PURE__ */ new Map();
|
|
1406
|
+
if (dataTypeIds.length > 0) {
|
|
1407
|
+
const dataTypesResult = await chainCms("get-data-types-by-id-array", { id: dataTypeIds });
|
|
1408
|
+
if (!dataTypesResult.ok) return dataTypesResult;
|
|
1409
|
+
for (const dt of dataTypesResult.data.items) {
|
|
1410
|
+
if (dt.id && dt.editorAlias) editorAliasByDataTypeId.set(dt.id, dt.editorAlias);
|
|
1123
1411
|
}
|
|
1124
1412
|
}
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
const
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
}
|
|
1133
|
-
const
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
} catch {
|
|
1413
|
+
const propertyAliases = new Set(
|
|
1414
|
+
docTypeResult.properties.map((p) => p.alias).filter((alias) => typeof alias === "string")
|
|
1415
|
+
);
|
|
1416
|
+
const editorAliasByPropertyAlias = /* @__PURE__ */ new Map();
|
|
1417
|
+
for (const prop of docTypeResult.properties) {
|
|
1418
|
+
const editorAlias = prop.dataType?.id ? editorAliasByDataTypeId.get(prop.dataType.id) : void 0;
|
|
1419
|
+
if (prop.alias && editorAlias) editorAliasByPropertyAlias.set(prop.alias, editorAlias);
|
|
1420
|
+
}
|
|
1421
|
+
const notAProperty = /* @__PURE__ */ new Set();
|
|
1422
|
+
const missingEditorAlias = /* @__PURE__ */ new Set();
|
|
1423
|
+
const resolved = values.map((v) => {
|
|
1424
|
+
const editorAlias = editorAliasByPropertyAlias.get(v.alias);
|
|
1425
|
+
if (!editorAlias) {
|
|
1426
|
+
if (propertyAliases.has(v.alias)) missingEditorAlias.add(v.alias);
|
|
1427
|
+
else notAProperty.add(v.alias);
|
|
1141
1428
|
}
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
}
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1429
|
+
return {
|
|
1430
|
+
alias: v.alias,
|
|
1431
|
+
value: v.value,
|
|
1432
|
+
culture: v.culture ?? null,
|
|
1433
|
+
segment: v.segment ?? null,
|
|
1434
|
+
editorAlias: editorAlias ?? ""
|
|
1435
|
+
};
|
|
1436
|
+
});
|
|
1437
|
+
if (notAProperty.size > 0 || missingEditorAlias.size > 0) {
|
|
1438
|
+
const messages = [];
|
|
1439
|
+
if (notAProperty.size > 0) {
|
|
1440
|
+
if (docTypeResult.failedCompositionIds.length > 0) {
|
|
1441
|
+
const failures = docTypeResult.failedCompositionIds.map((id, i) => `${id} (${docTypeResult.failedCompositionDetails[i]})`).join(", ");
|
|
1442
|
+
messages.push(
|
|
1443
|
+
`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`
|
|
1444
|
+
);
|
|
1445
|
+
} else {
|
|
1446
|
+
messages.push(
|
|
1447
|
+
`not a property on this document type, own or inherited via composition: ${Array.from(notAProperty).join(", ")}`
|
|
1448
|
+
);
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
if (missingEditorAlias.size > 0) {
|
|
1452
|
+
messages.push(
|
|
1453
|
+
`a property on this document type, but its data type has no resolvable editor alias: ${Array.from(missingEditorAlias).join(", ")}`
|
|
1454
|
+
);
|
|
1455
|
+
}
|
|
1456
|
+
return {
|
|
1457
|
+
ok: false,
|
|
1458
|
+
errorResult: createToolResultError(
|
|
1459
|
+
`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.`
|
|
1460
|
+
)
|
|
1461
|
+
};
|
|
1462
|
+
}
|
|
1463
|
+
return { ok: true, values: resolved };
|
|
1155
1464
|
}
|
|
1156
1465
|
|
|
1157
1466
|
// src/umbraco-api/tools/content/post/create-page.ts
|
|
@@ -1181,31 +1490,12 @@ var tool11 = {
|
|
|
1181
1490
|
slices: ["create"],
|
|
1182
1491
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
|
|
1183
1492
|
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
|
-
}
|
|
1493
|
+
const resolved = await resolveEditorAliases(documentTypeId, values);
|
|
1494
|
+
if (!resolved.ok) return resolved.errorResult;
|
|
1199
1495
|
const createResult = await chainCms("create-document", {
|
|
1200
1496
|
documentTypeId,
|
|
1201
1497
|
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
|
-
})),
|
|
1498
|
+
values: resolved.values,
|
|
1209
1499
|
...parentId ? { parentId } : {}
|
|
1210
1500
|
});
|
|
1211
1501
|
if (!createResult.ok) return createResult.errorResult;
|
|
@@ -1242,41 +1532,50 @@ var outputSchema12 = z.object({
|
|
|
1242
1532
|
});
|
|
1243
1533
|
var tool12 = {
|
|
1244
1534
|
name: "create-and-publish-page",
|
|
1245
|
-
description: "Create a new content page and publish it
|
|
1535
|
+
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
1536
|
inputSchema: inputSchema12,
|
|
1247
1537
|
outputSchema: outputSchema12,
|
|
1248
1538
|
slices: ["create", "publish"],
|
|
1249
1539
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
|
|
1250
1540
|
handler: async ({ name, documentTypeId, parentId, values }) => {
|
|
1251
|
-
const
|
|
1252
|
-
if (
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
);
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1541
|
+
const resolved = await resolveEditorAliases(documentTypeId, values);
|
|
1542
|
+
if (!resolved.ok) return resolved.errorResult;
|
|
1543
|
+
if (await isCmsToolAvailable("create-and-publish-document")) {
|
|
1544
|
+
const createResult = await chainCms("create-and-publish-document", {
|
|
1545
|
+
documentTypeId,
|
|
1546
|
+
name,
|
|
1547
|
+
values: resolved.values,
|
|
1548
|
+
...parentId ? { parentId } : {}
|
|
1549
|
+
});
|
|
1550
|
+
if (!createResult.ok) return createResult.errorResult;
|
|
1551
|
+
const createdId2 = createResult.data.id;
|
|
1552
|
+
return createToolResult({
|
|
1553
|
+
message: `Created and published "${name}"`,
|
|
1554
|
+
id: createdId2,
|
|
1555
|
+
name,
|
|
1556
|
+
publishedUrls: createdId2 ? await fetchPublishedUrls(createdId2) : []
|
|
1557
|
+
});
|
|
1265
1558
|
}
|
|
1266
|
-
const
|
|
1559
|
+
const createDocumentResult = await chainCms("create-document", {
|
|
1267
1560
|
documentTypeId,
|
|
1268
1561
|
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
|
-
})),
|
|
1562
|
+
values: resolved.values,
|
|
1276
1563
|
...parentId ? { parentId } : {}
|
|
1277
1564
|
});
|
|
1278
|
-
if (!
|
|
1279
|
-
const createdId =
|
|
1565
|
+
if (!createDocumentResult.ok) return createDocumentResult.errorResult;
|
|
1566
|
+
const createdId = createDocumentResult.data.id;
|
|
1567
|
+
const publishResult = await chainCms("publish-document", {
|
|
1568
|
+
id: createdId,
|
|
1569
|
+
data: { publishSchedules: [{ culture: null }] }
|
|
1570
|
+
});
|
|
1571
|
+
if (!publishResult.ok) {
|
|
1572
|
+
return createToolResult({
|
|
1573
|
+
message: `Created "${name}" as a draft but publish failed: ${publishResult.errorResult.content?.[0]?.text ?? "unknown error"}`,
|
|
1574
|
+
id: createdId,
|
|
1575
|
+
name,
|
|
1576
|
+
publishedUrls: []
|
|
1577
|
+
});
|
|
1578
|
+
}
|
|
1280
1579
|
return createToolResult({
|
|
1281
1580
|
message: `Created and published "${name}"`,
|
|
1282
1581
|
id: createdId,
|
|
@@ -1329,70 +1628,6 @@ var tool13 = {
|
|
|
1329
1628
|
}
|
|
1330
1629
|
};
|
|
1331
1630
|
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
1631
|
var positionSchema = z.object({
|
|
1397
1632
|
mode: z.enum(["append", "prepend", "before", "after"]).describe("Where to place the new block relative to existing blocks"),
|
|
1398
1633
|
anchorContentKey: z.string().uuid().optional().describe("Required for 'before' or 'after' \u2014 the contentKey of the anchor block")
|
|
@@ -1445,64 +1680,25 @@ var tool14 = {
|
|
|
1445
1680
|
const existingProp = (doc.values ?? []).find(
|
|
1446
1681
|
(v) => v.alias === propertyAlias && (v.culture ?? null) === (culture ?? null) && (v.segment ?? null) === (segment ?? null)
|
|
1447
1682
|
);
|
|
1448
|
-
|
|
1449
|
-
layout: { "Umbraco.BlockList": [] },
|
|
1450
|
-
contentData: [],
|
|
1451
|
-
settingsData: [],
|
|
1452
|
-
expose: []
|
|
1453
|
-
};
|
|
1454
|
-
if (existingProp && (!isBlockListOrGridValue2(propValue) || existingProp.editorAlias !== "Umbraco.BlockList")) {
|
|
1683
|
+
if (existingProp?.value && (!isBlockListOrGridValue(existingProp.value) || existingProp.editorAlias !== "Umbraco.BlockList")) {
|
|
1455
1684
|
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
1685
|
}
|
|
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
1686
|
const cultureValue = culture ?? null;
|
|
1468
1687
|
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
|
|
1688
|
+
const blockProperties = await toNewBlockProperties(contentTypeKey, values, settingsTypeKey, settingsValues, cultureValue, segmentValue);
|
|
1689
|
+
if (!blockProperties.ok) return blockProperties.errorResult;
|
|
1690
|
+
const createResult = await chainCms("create-document-block", {
|
|
1691
|
+
documentId: id,
|
|
1692
|
+
propertyAlias,
|
|
1693
|
+
culture: cultureValue,
|
|
1694
|
+
segment: segmentValue,
|
|
1695
|
+
contentTypeKey,
|
|
1696
|
+
properties: blockProperties.properties,
|
|
1697
|
+
settings: blockProperties.settings,
|
|
1698
|
+
placement: toPlacement(resolvedPosition)
|
|
1505
1699
|
});
|
|
1700
|
+
if (!createResult.ok) return createResult.errorResult;
|
|
1701
|
+
return buildBlockWriteResult(id, pageName, createResult.data.results[0].contentKey, `Added a new block to "${pageName}" (saved, not published)`);
|
|
1506
1702
|
}
|
|
1507
1703
|
};
|
|
1508
1704
|
var add_blocklist_block_default = withStandardDecorators(tool14);
|
|
@@ -1565,100 +1761,30 @@ var tool15 = {
|
|
|
1565
1761
|
const existingProp = (doc.values ?? []).find(
|
|
1566
1762
|
(v) => v.alias === propertyAlias && (v.culture ?? null) === (culture ?? null) && (v.segment ?? null) === (segment ?? null)
|
|
1567
1763
|
);
|
|
1568
|
-
|
|
1569
|
-
layout: { "Umbraco.BlockGrid": [] },
|
|
1570
|
-
contentData: [],
|
|
1571
|
-
settingsData: [],
|
|
1572
|
-
expose: []
|
|
1573
|
-
};
|
|
1574
|
-
if (existingProp && (!isBlockListOrGridValue2(propValue) || existingProp.editorAlias !== "Umbraco.BlockGrid")) {
|
|
1764
|
+
if (existingProp?.value && (!isBlockListOrGridValue(existingProp.value) || existingProp.editorAlias !== "Umbraco.BlockGrid")) {
|
|
1575
1765
|
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
1766
|
}
|
|
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
1767
|
const cultureValue = culture ?? null;
|
|
1588
1768
|
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 });
|
|
1769
|
+
const blockProperties = await toNewBlockProperties(contentTypeKey, values, settingsTypeKey, settingsValues, cultureValue, segmentValue);
|
|
1770
|
+
if (!blockProperties.ok) return blockProperties.errorResult;
|
|
1771
|
+
const createResult = await chainCms("create-document-block", {
|
|
1772
|
+
documentId: id,
|
|
1773
|
+
propertyAlias,
|
|
1774
|
+
culture: cultureValue,
|
|
1775
|
+
segment: segmentValue,
|
|
1776
|
+
contentTypeKey,
|
|
1777
|
+
properties: blockProperties.properties,
|
|
1778
|
+
settings: blockProperties.settings,
|
|
1779
|
+
placement: toPlacement(resolvedPosition),
|
|
1780
|
+
grid: {
|
|
1781
|
+
columnSpan: columnSpan ?? 12,
|
|
1782
|
+
rowSpan: rowSpan ?? 1,
|
|
1783
|
+
...areaKey && parentContentKey ? { areaKey, parentContentKey } : {}
|
|
1631
1784
|
}
|
|
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
1785
|
});
|
|
1786
|
+
if (!createResult.ok) return createResult.errorResult;
|
|
1787
|
+
return buildBlockWriteResult(id, pageName, createResult.data.results[0].contentKey, `Added a new block to "${pageName}" (saved, not published)`);
|
|
1662
1788
|
}
|
|
1663
1789
|
};
|
|
1664
1790
|
var add_blockgrid_block_default = withStandardDecorators(tool15);
|
|
@@ -1689,26 +1815,6 @@ var outputSchema16 = z.object({
|
|
|
1689
1815
|
previewUrl: previewUrlSchema,
|
|
1690
1816
|
validation: validationResultSchema
|
|
1691
1817
|
});
|
|
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
1818
|
var tool16 = {
|
|
1713
1819
|
name: "add-rte-block",
|
|
1714
1820
|
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 +1840,25 @@ var tool16 = {
|
|
|
1734
1840
|
const existingProp = (doc.values ?? []).find(
|
|
1735
1841
|
(v) => v.alias === propertyAlias && (v.culture ?? null) === (culture ?? null) && (v.segment ?? null) === (segment ?? null)
|
|
1736
1842
|
);
|
|
1737
|
-
|
|
1738
|
-
markup: "",
|
|
1739
|
-
blocks: { layout: {}, contentData: [], settingsData: [], expose: [] }
|
|
1740
|
-
};
|
|
1741
|
-
if (existingProp && !isRteWithBlocks2(propValue)) {
|
|
1843
|
+
if (existingProp?.value && !isRteWithBlocks(existingProp.value)) {
|
|
1742
1844
|
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
1845
|
}
|
|
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
1846
|
const cultureValue = culture ?? null;
|
|
1755
1847
|
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
|
|
1848
|
+
const blockProperties = await toNewBlockProperties(contentTypeKey, values, settingsTypeKey, settingsValues, cultureValue, segmentValue);
|
|
1849
|
+
if (!blockProperties.ok) return blockProperties.errorResult;
|
|
1850
|
+
const createResult = await chainCms("create-document-block", {
|
|
1851
|
+
documentId: id,
|
|
1852
|
+
propertyAlias,
|
|
1853
|
+
culture: cultureValue,
|
|
1854
|
+
segment: segmentValue,
|
|
1855
|
+
contentTypeKey,
|
|
1856
|
+
properties: blockProperties.properties,
|
|
1857
|
+
settings: blockProperties.settings,
|
|
1858
|
+
placement: toPlacement(resolvedPosition)
|
|
1801
1859
|
});
|
|
1860
|
+
if (!createResult.ok) return createResult.errorResult;
|
|
1861
|
+
return buildBlockWriteResult(id, pageName, createResult.data.results[0].contentKey, `Added a new block to "${pageName}" rich text (saved, not published)`);
|
|
1802
1862
|
}
|
|
1803
1863
|
};
|
|
1804
1864
|
var add_rte_block_default = withStandardDecorators(tool16);
|
|
@@ -1853,12 +1913,84 @@ var tool17 = {
|
|
|
1853
1913
|
}
|
|
1854
1914
|
};
|
|
1855
1915
|
var edit_page_default = withStandardDecorators(tool17);
|
|
1916
|
+
var MAX_ENRICHED_BLOCKS = 50;
|
|
1917
|
+
var MAX_BLOCK_WALK_DEPTH = 20;
|
|
1918
|
+
function enrichBlockNotFoundError(errorResult, values, options = {}) {
|
|
1919
|
+
const problem = extractInnerProblemDetails(errorResult);
|
|
1920
|
+
const availableBlocks = problem.availableBlocks;
|
|
1921
|
+
if (!Array.isArray(availableBlocks)) return errorResult;
|
|
1922
|
+
const { propertyAlias, note } = options;
|
|
1923
|
+
const filtered = propertyAlias ? values.filter((v) => v.alias === propertyAlias) : values;
|
|
1924
|
+
const typeByKey = /* @__PURE__ */ new Map();
|
|
1925
|
+
for (const v of filtered) {
|
|
1926
|
+
const container = isRteWithBlocks(v.value) ? v.value.blocks : v.value;
|
|
1927
|
+
if (isBlockListOrGridValue(container)) {
|
|
1928
|
+
collectBlockEntryTypes(container, typeByKey, 0);
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
const truncated = availableBlocks.length > MAX_ENRICHED_BLOCKS;
|
|
1932
|
+
const limitedBlocks = truncated ? availableBlocks.slice(0, MAX_ENRICHED_BLOCKS) : availableBlocks;
|
|
1933
|
+
const enrichedBlocks = limitedBlocks.map(
|
|
1934
|
+
(b) => b && typeof b === "object" && typeof b.key === "string" ? { ...b, contentTypeKey: typeByKey.get(b.key) ?? null } : b
|
|
1935
|
+
);
|
|
1936
|
+
return createToolResultError({
|
|
1937
|
+
...problem,
|
|
1938
|
+
availableBlocks: enrichedBlocks,
|
|
1939
|
+
...truncated ? { availableBlocksNote: `Showing ${MAX_ENRICHED_BLOCKS} of ${availableBlocks.length} available blocks \u2014 use inspect-blocks for the full list.` } : {},
|
|
1940
|
+
...note ? { note } : {}
|
|
1941
|
+
});
|
|
1942
|
+
}
|
|
1943
|
+
function collectBlockEntryTypes(container, into, depth) {
|
|
1944
|
+
if (depth > MAX_BLOCK_WALK_DEPTH) return;
|
|
1945
|
+
for (const list of [container.contentData, container.settingsData]) {
|
|
1946
|
+
if (!Array.isArray(list)) continue;
|
|
1947
|
+
for (const block of list) {
|
|
1948
|
+
if (!block || typeof block !== "object") continue;
|
|
1949
|
+
const key = block.key;
|
|
1950
|
+
const contentTypeKey = block.contentTypeKey;
|
|
1951
|
+
if (typeof key === "string" && typeof contentTypeKey === "string") into.set(key, contentTypeKey);
|
|
1952
|
+
const nestedValues = block.values;
|
|
1953
|
+
if (!Array.isArray(nestedValues)) continue;
|
|
1954
|
+
for (const nested of nestedValues) {
|
|
1955
|
+
const nestedRaw = nested?.value;
|
|
1956
|
+
const nestedContainer = isRteWithBlocks(nestedRaw) ? nestedRaw.blocks : nestedRaw;
|
|
1957
|
+
if (isBlockListOrGridValue(nestedContainer)) {
|
|
1958
|
+
collectBlockEntryTypes(nestedContainer, into, depth + 1);
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
var blockPropertyAliasSchema = z.string().regex(
|
|
1965
|
+
/^[A-Za-z_][A-Za-z0-9_]*$/,
|
|
1966
|
+
"Property alias must be a valid identifier (letters, digits, underscore; not starting with a digit)"
|
|
1967
|
+
);
|
|
1968
|
+
function classifyBlockUpdateResults(results, requestedCount, requestedAliases = [], expectedEntryCount = 1) {
|
|
1969
|
+
const list = results ?? [];
|
|
1970
|
+
const processedCount = list.reduce((sum, r) => sum + (r.updatedCount ?? 0) + (r.addedCount ?? 0), 0);
|
|
1971
|
+
const updatedEntryCount = list.filter((r) => (r.updatedCount ?? 0) + (r.addedCount ?? 0) > 0).length;
|
|
1972
|
+
const errors = list.flatMap((r) => r.errors ?? []);
|
|
1973
|
+
const warnings = list.flatMap((r) => r.warnings ?? []);
|
|
1974
|
+
const failureText = [...errors, ...warnings].join("; ");
|
|
1975
|
+
const unresolvedEntries = list.filter(
|
|
1976
|
+
(r) => (r.updatedCount ?? 0) + (r.addedCount ?? 0) === 0 && !r.errors?.length && !r.warnings?.length
|
|
1977
|
+
);
|
|
1978
|
+
const missingEntryCount = Math.max(0, expectedEntryCount - list.length);
|
|
1979
|
+
const unresolvedBlockCount = unresolvedEntries.length + missingEntryCount;
|
|
1980
|
+
const detail = [...errors, ...warnings, ...unresolvedEntries.map((r) => r.message).filter(Boolean)].join("; ") || list.map((r) => r.message).filter(Boolean).join("; ") || "no detail returned";
|
|
1981
|
+
const outcome = processedCount === 0 ? "failed" : processedCount < requestedCount ? "partial" : "clean";
|
|
1982
|
+
const failedFields = requestedAliases.filter((alias) => failureText.includes(`'${alias}'`));
|
|
1983
|
+
const savedFields = unresolvedBlockCount > 0 ? [] : requestedAliases.filter((alias) => !failedFields.includes(alias));
|
|
1984
|
+
return { outcome, processedCount, updatedEntryCount, detail, warnings, savedFields, failedFields, unresolvedBlockCount };
|
|
1985
|
+
}
|
|
1986
|
+
|
|
1987
|
+
// src/umbraco-api/tools/content/put/edit-block.ts
|
|
1856
1988
|
var inputSchema18 = {
|
|
1857
1989
|
id: z.string().uuid().describe("The ID of the page containing the block"),
|
|
1858
1990
|
propertyAlias: z.string().describe("The document property alias containing the blocks (e.g. 'mainContent'). Use inspect-blocks to find this."),
|
|
1859
1991
|
contentKey: z.string().uuid().describe("The unique key of the block to edit. Use inspect-blocks to find this."),
|
|
1860
1992
|
values: z.array(z.object({
|
|
1861
|
-
alias:
|
|
1993
|
+
alias: blockPropertyAliasSchema.describe("The property alias within the block"),
|
|
1862
1994
|
value: z.any().describe("The new value for the property")
|
|
1863
1995
|
})).describe("Properties to update within the block"),
|
|
1864
1996
|
blockType: z.enum(["content", "settings"]).optional().describe("Whether to update the block's content or its settings. Defaults to 'content'."),
|
|
@@ -1872,7 +2004,8 @@ var outputSchema18 = z.object({
|
|
|
1872
2004
|
contentKey: z.string(),
|
|
1873
2005
|
updatedFields: z.array(z.string()),
|
|
1874
2006
|
previewUrl: previewUrlSchema,
|
|
1875
|
-
validation: validationResultSchema
|
|
2007
|
+
validation: validationResultSchema,
|
|
2008
|
+
warnings: z.array(z.string()).optional()
|
|
1876
2009
|
});
|
|
1877
2010
|
var tool18 = {
|
|
1878
2011
|
name: "edit-block",
|
|
@@ -1887,6 +2020,20 @@ var tool18 = {
|
|
|
1887
2020
|
const pageName = docResult.data.variants?.[0]?.name ?? "Unknown";
|
|
1888
2021
|
const fieldNames = values.map((v) => v.alias);
|
|
1889
2022
|
const resolvedBlockType = blockType ?? "content";
|
|
2023
|
+
let targetKey = contentKey;
|
|
2024
|
+
if (resolvedBlockType === "settings") {
|
|
2025
|
+
const rawValue = (docResult.data.values ?? []).find(
|
|
2026
|
+
(v) => v.alias === propertyAlias && (v.culture ?? null) === (culture ?? null) && (v.segment ?? null) === (segment ?? null)
|
|
2027
|
+
)?.value;
|
|
2028
|
+
const container = isRteWithBlocks(rawValue) ? rawValue.blocks : rawValue;
|
|
2029
|
+
const settingsKey = findSettingsKey(container, contentKey);
|
|
2030
|
+
if (!settingsKey) {
|
|
2031
|
+
return createToolResultError(
|
|
2032
|
+
`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.`
|
|
2033
|
+
);
|
|
2034
|
+
}
|
|
2035
|
+
targetKey = settingsKey;
|
|
2036
|
+
}
|
|
1890
2037
|
const propsTuple = values.map((v) => ({ alias: v.alias, value: v.value }));
|
|
1891
2038
|
const updateResult = await chainCms("update-block-property", {
|
|
1892
2039
|
documentId: id,
|
|
@@ -1894,12 +2041,41 @@ var tool18 = {
|
|
|
1894
2041
|
culture: culture ?? null,
|
|
1895
2042
|
segment: segment ?? null,
|
|
1896
2043
|
updates: [{
|
|
1897
|
-
contentKey,
|
|
2044
|
+
contentKey: targetKey,
|
|
1898
2045
|
blockType: resolvedBlockType,
|
|
1899
2046
|
properties: propsTuple
|
|
1900
2047
|
}]
|
|
1901
2048
|
});
|
|
1902
|
-
if (!updateResult.ok)
|
|
2049
|
+
if (!updateResult.ok) {
|
|
2050
|
+
return enrichBlockNotFoundError(updateResult.errorResult, docResult.data.values ?? [], {
|
|
2051
|
+
propertyAlias,
|
|
2052
|
+
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.`
|
|
2053
|
+
});
|
|
2054
|
+
}
|
|
2055
|
+
const results = updateResult.data.results;
|
|
2056
|
+
if (!results || results.length === 0) {
|
|
2057
|
+
return createToolResultError(
|
|
2058
|
+
"update-block-property returned no per-block result \u2014 cannot confirm the write succeeded."
|
|
2059
|
+
);
|
|
2060
|
+
}
|
|
2061
|
+
const classification = classifyBlockUpdateResults(results, fieldNames.length, fieldNames, 1);
|
|
2062
|
+
if (classification.outcome === "failed") {
|
|
2063
|
+
return createToolResultError(
|
|
2064
|
+
`Block update failed: ${classification.detail || updateResult.data.message || "no detail returned"}`
|
|
2065
|
+
);
|
|
2066
|
+
}
|
|
2067
|
+
if (classification.outcome === "partial") {
|
|
2068
|
+
return createToolResultError({
|
|
2069
|
+
message: `Block update partially failed: ${classification.processedCount} of ${fieldNames.length} field(s) saved \u2014 ${classification.detail}`,
|
|
2070
|
+
savedFields: classification.savedFields,
|
|
2071
|
+
failedFields: classification.failedFields,
|
|
2072
|
+
...classification.savedFields.length > 0 ? { note: "savedFields were written to the document and must not be retried." } : {},
|
|
2073
|
+
...classification.warnings.length ? { warnings: classification.warnings } : {},
|
|
2074
|
+
validation: await validateDocumentState(id),
|
|
2075
|
+
previewUrl: await fetchPreviewUrl(id)
|
|
2076
|
+
});
|
|
2077
|
+
}
|
|
2078
|
+
const warnings = classification.warnings;
|
|
1903
2079
|
const validation = await validateDocumentState(id);
|
|
1904
2080
|
const target = resolvedBlockType === "settings" ? "settings" : "content";
|
|
1905
2081
|
const baseMessage = `Updated ${fieldNames.length} field(s) in block ${target} on "${pageName}" (saved, not published)`;
|
|
@@ -1911,7 +2087,8 @@ var tool18 = {
|
|
|
1911
2087
|
contentKey,
|
|
1912
2088
|
updatedFields: fieldNames,
|
|
1913
2089
|
previewUrl: await fetchPreviewUrl(id),
|
|
1914
|
-
validation
|
|
2090
|
+
validation,
|
|
2091
|
+
...warnings.length ? { warnings } : {}
|
|
1915
2092
|
});
|
|
1916
2093
|
}
|
|
1917
2094
|
};
|
|
@@ -1964,10 +2141,9 @@ var tool19 = {
|
|
|
1964
2141
|
});
|
|
1965
2142
|
}
|
|
1966
2143
|
const cultureLabel = targetCulture ? ` (${targetCulture})` : "";
|
|
1967
|
-
const confirmed = await
|
|
2144
|
+
const confirmed = await requestApproval(
|
|
1968
2145
|
extra,
|
|
1969
|
-
`Rename page${cultureLabel} from "${previousName}" to "${name}"? The page URL segment may change when you next publish
|
|
1970
|
-
{ title: "Confirm rename" }
|
|
2146
|
+
`Rename page${cultureLabel} from "${previousName}" to "${name}"? The page URL segment may change when you next publish.`
|
|
1971
2147
|
);
|
|
1972
2148
|
if (!confirmed) {
|
|
1973
2149
|
return createToolResult({
|
|
@@ -2254,68 +2430,26 @@ var outputSchema24 = z.object({
|
|
|
2254
2430
|
previewUrl: previewUrlSchema,
|
|
2255
2431
|
validation: validationResultSchema
|
|
2256
2432
|
});
|
|
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 };
|
|
2433
|
+
function gridContainsBlock(items, contentKey) {
|
|
2434
|
+
return items.some(
|
|
2435
|
+
(item) => item.contentKey === contentKey || (item.areas ?? []).some((area) => gridContainsBlock(area.items ?? [], contentKey))
|
|
2436
|
+
);
|
|
2277
2437
|
}
|
|
2278
|
-
function
|
|
2438
|
+
function locateBlock(propValue, editorAlias, propertyAlias, contentKey, pageName) {
|
|
2279
2439
|
const notFound = { ok: false, errorText: `Block '${contentKey}' was not found in property '${propertyAlias}'.` };
|
|
2280
2440
|
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
|
-
};
|
|
2441
|
+
if (isBlockListOrGridValue(propValue) && editorAlias === "Umbraco.BlockList") {
|
|
2442
|
+
const layoutList = propValue.layout?.["Umbraco.BlockList"] ?? [];
|
|
2443
|
+
if (!layoutList.some((e) => e.contentKey === contentKey)) return notFound;
|
|
2444
|
+
return { ok: true, confirmMessage: `Remove block ${contentKey} from "${pageName}" (BlockList ${propertyAlias})? ${draftSuffix}` };
|
|
2291
2445
|
}
|
|
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
|
-
};
|
|
2446
|
+
if (isBlockListOrGridValue(propValue) && editorAlias === "Umbraco.BlockGrid") {
|
|
2447
|
+
if (!gridContainsBlock(propValue.layout?.["Umbraco.BlockGrid"] ?? [], contentKey)) return notFound;
|
|
2448
|
+
return { ok: true, confirmMessage: `Remove block ${contentKey} from "${pageName}" (BlockGrid ${propertyAlias})? ${draftSuffix}` };
|
|
2301
2449
|
}
|
|
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
|
-
};
|
|
2450
|
+
if (isRteWithBlocks(propValue)) {
|
|
2451
|
+
if (!(propValue.blocks.contentData ?? []).some((e) => e.key === contentKey)) return notFound;
|
|
2452
|
+
return { ok: true, confirmMessage: `Remove block ${contentKey} from a Rich Text in "${pageName}" (${propertyAlias})? ${draftSuffix}` };
|
|
2319
2453
|
}
|
|
2320
2454
|
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
2455
|
}
|
|
@@ -2340,29 +2474,22 @@ var tool24 = {
|
|
|
2340
2474
|
isError: true
|
|
2341
2475
|
});
|
|
2342
2476
|
}
|
|
2343
|
-
const
|
|
2344
|
-
if (!
|
|
2345
|
-
return createToolResultError({ content: [{ type: "text", text:
|
|
2477
|
+
const location = locateBlock(prop.value, prop.editorAlias, propertyAlias, contentKey, pageName);
|
|
2478
|
+
if (!location.ok) {
|
|
2479
|
+
return createToolResultError({ content: [{ type: "text", text: location.errorText }], isError: true });
|
|
2346
2480
|
}
|
|
2347
|
-
if (!await requestApproval(extra,
|
|
2481
|
+
if (!await requestApproval(extra, location.confirmMessage)) {
|
|
2348
2482
|
return createToolResultError({ content: [{ type: "text", text: "Cancelled by user." }], isError: true });
|
|
2349
2483
|
}
|
|
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
|
|
2484
|
+
const deleteResult = await chainCms("delete-document-block", {
|
|
2485
|
+
documentId: id,
|
|
2486
|
+
propertyAlias,
|
|
2487
|
+
culture: culture ?? null,
|
|
2488
|
+
segment: segment ?? null,
|
|
2489
|
+
contentKey
|
|
2365
2490
|
});
|
|
2491
|
+
if (!deleteResult.ok) return deleteResult.errorResult;
|
|
2492
|
+
return buildBlockWriteResult(id, pageName, contentKey, `Removed block from "${pageName}" (saved, not published)`);
|
|
2366
2493
|
}
|
|
2367
2494
|
};
|
|
2368
2495
|
var delete_block_default = withStandardDecorators(tool24);
|
|
@@ -2519,7 +2646,7 @@ function mergeValues(existing, updates) {
|
|
|
2519
2646
|
}
|
|
2520
2647
|
var tool27 = {
|
|
2521
2648
|
name: "save-and-publish",
|
|
2522
|
-
description: "Save property changes and publish a content page
|
|
2649
|
+
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
2650
|
inputSchema: inputSchema27,
|
|
2524
2651
|
outputSchema: outputSchema27,
|
|
2525
2652
|
slices: ["publish", "update"],
|
|
@@ -2579,20 +2706,53 @@ var tool27 = {
|
|
|
2579
2706
|
}
|
|
2580
2707
|
} else {
|
|
2581
2708
|
const mergedValues = mergeValues(doc.values ?? [], values ?? []);
|
|
2582
|
-
const
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2709
|
+
const variants = (doc.variants ?? []).map((v) => ({
|
|
2710
|
+
culture: v.culture ?? null,
|
|
2711
|
+
segment: v.segment ?? null,
|
|
2712
|
+
name: v.name
|
|
2713
|
+
}));
|
|
2714
|
+
if (await isCmsToolAvailable("update-and-publish-document")) {
|
|
2715
|
+
const updateAndPublishResult = await chainCms("update-and-publish-document", {
|
|
2716
|
+
id,
|
|
2717
|
+
data: {
|
|
2718
|
+
values: mergedValues,
|
|
2719
|
+
variants,
|
|
2720
|
+
template: doc.template ?? null,
|
|
2721
|
+
culturesToPublish: variantCultures.filter((c) => c !== null)
|
|
2722
|
+
}
|
|
2723
|
+
});
|
|
2724
|
+
if (!updateAndPublishResult.ok) return updateAndPublishResult.errorResult;
|
|
2725
|
+
} else {
|
|
2726
|
+
const updateResult = await chainCms("update-document", {
|
|
2727
|
+
id,
|
|
2728
|
+
data: {
|
|
2729
|
+
values: mergedValues,
|
|
2730
|
+
variants,
|
|
2731
|
+
template: doc.template ?? null
|
|
2732
|
+
}
|
|
2733
|
+
});
|
|
2734
|
+
if (!updateResult.ok) return updateResult.errorResult;
|
|
2735
|
+
const publishResult = await chainCms("publish-document", {
|
|
2736
|
+
id,
|
|
2737
|
+
data: {
|
|
2738
|
+
publishSchedules: variantCultures.map((c) => ({ culture: c }))
|
|
2739
|
+
}
|
|
2740
|
+
});
|
|
2741
|
+
if (!publishResult.ok) {
|
|
2742
|
+
if (saved) {
|
|
2743
|
+
return createToolResult({
|
|
2744
|
+
message: `Saved ${fieldNames.length} field(s) on "${pageName}" but publish failed: ${publishResult.errorResult.content?.[0]?.text ?? "unknown error"}`,
|
|
2745
|
+
id,
|
|
2746
|
+
name: pageName,
|
|
2747
|
+
saved: true,
|
|
2748
|
+
published: false,
|
|
2749
|
+
updatedFields: fieldNames,
|
|
2750
|
+
publishedUrls: []
|
|
2751
|
+
});
|
|
2752
|
+
}
|
|
2753
|
+
return publishResult.errorResult;
|
|
2593
2754
|
}
|
|
2594
|
-
}
|
|
2595
|
-
if (!updateAndPublishResult.ok) return updateAndPublishResult.errorResult;
|
|
2755
|
+
}
|
|
2596
2756
|
}
|
|
2597
2757
|
if (!includeDescendants) {
|
|
2598
2758
|
const verifyError = await verifyDocumentPublished(id, variantCultures);
|
|
@@ -3444,12 +3604,7 @@ function validateBulkIds(ids) {
|
|
|
3444
3604
|
function parseBulkError(err) {
|
|
3445
3605
|
if (err === null || err === void 0) return "Unknown error";
|
|
3446
3606
|
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;
|
|
3607
|
+
return extractInnerProblemDetails(err);
|
|
3453
3608
|
}
|
|
3454
3609
|
if (typeof err === "string") {
|
|
3455
3610
|
try {
|
|
@@ -3718,6 +3873,15 @@ var tool46 = {
|
|
|
3718
3873
|
slices: ["list"],
|
|
3719
3874
|
annotations: { readOnlyHint: true },
|
|
3720
3875
|
handler: async ({ parentId, take, skip }) => {
|
|
3876
|
+
const accessCheck = await checkSettingsAccess();
|
|
3877
|
+
if (!accessCheck.ok) return accessCheck.errorResult;
|
|
3878
|
+
if (!accessCheck.hasAccess) {
|
|
3879
|
+
return createToolResultError({
|
|
3880
|
+
status: 403,
|
|
3881
|
+
title: "Settings access required",
|
|
3882
|
+
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."
|
|
3883
|
+
});
|
|
3884
|
+
}
|
|
3721
3885
|
const cursor = buildChainedCursor(skip, take);
|
|
3722
3886
|
const result = parentId ? await chainCms("get-document-blueprint-children", { parentId, cursor }) : await chainCms("get-document-blueprint-root", { cursor });
|
|
3723
3887
|
if (!result.ok) return result.errorResult;
|
|
@@ -4616,11 +4780,11 @@ var tool64 = {
|
|
|
4616
4780
|
const headings = extractHeadings(allHtml);
|
|
4617
4781
|
const images = extractImages(allHtml);
|
|
4618
4782
|
const bodyWordCount = countWords(extractTextContent(values));
|
|
4619
|
-
const
|
|
4783
|
+
const url = await fetchPrimaryPublishedUrl(id);
|
|
4620
4784
|
return createToolResult({
|
|
4621
4785
|
id: doc.id,
|
|
4622
4786
|
name: variant?.name ?? "Unknown",
|
|
4623
|
-
url
|
|
4787
|
+
url,
|
|
4624
4788
|
hasTitle: title.length > 0,
|
|
4625
4789
|
hasMetaDescription: metaDescription.length > 0,
|
|
4626
4790
|
titleLength: title.length,
|
|
@@ -4679,12 +4843,12 @@ var tool65 = {
|
|
|
4679
4843
|
const fullBodyText = extractTextContent(values);
|
|
4680
4844
|
const bodyContent = fullBodyText.slice(0, BODY_CONTENT_MAX);
|
|
4681
4845
|
const wordCount = fullBodyText ? fullBodyText.split(/\s+/).filter(Boolean).length : 0;
|
|
4682
|
-
const extra = doc;
|
|
4683
4846
|
const dt = doc.documentType;
|
|
4847
|
+
const url = await fetchPrimaryPublishedUrl(id);
|
|
4684
4848
|
return createToolResult({
|
|
4685
4849
|
id: doc.id,
|
|
4686
4850
|
name: variant?.name ?? "Unknown",
|
|
4687
|
-
url
|
|
4851
|
+
url,
|
|
4688
4852
|
hasMetaDescription: metaDescription.length > 0,
|
|
4689
4853
|
bodyWordCount: wordCount,
|
|
4690
4854
|
metaDescription,
|
|
@@ -4735,6 +4899,9 @@ async function fetchTreeLevel(parentId, depth) {
|
|
|
4735
4899
|
}
|
|
4736
4900
|
async function buildTreeNodes(parentId, depth, maxDepth, pagesPerLevel, totalRef, maxDepthRef) {
|
|
4737
4901
|
const items = await fetchTreeLevel(parentId);
|
|
4902
|
+
const urlsById = await fetchPrimaryPublishedUrlsBatch(
|
|
4903
|
+
items.map((item) => item.id).filter((id) => typeof id === "string")
|
|
4904
|
+
);
|
|
4738
4905
|
const nodes = [];
|
|
4739
4906
|
for (const item of items) {
|
|
4740
4907
|
totalRef.count++;
|
|
@@ -4750,7 +4917,7 @@ async function buildTreeNodes(parentId, depth, maxDepth, pagesPerLevel, totalRef
|
|
|
4750
4917
|
nodes.push({
|
|
4751
4918
|
id: item.id ?? "",
|
|
4752
4919
|
name: item.name ?? item.variants?.[0]?.name ?? "Unknown",
|
|
4753
|
-
url:
|
|
4920
|
+
url: urlsById.get(item.id) ?? "",
|
|
4754
4921
|
documentType: item.documentType?.name ?? item.contentTypeName ?? "",
|
|
4755
4922
|
depth,
|
|
4756
4923
|
childCount: children.length,
|
|
@@ -4818,6 +4985,9 @@ var tool67 = {
|
|
|
4818
4985
|
if (!result.ok) return;
|
|
4819
4986
|
const data = result.data;
|
|
4820
4987
|
const items = data?.items ?? [];
|
|
4988
|
+
const urlsById = await fetchPrimaryPublishedUrlsBatch(
|
|
4989
|
+
items.map((item) => item.id).filter((id) => typeof id === "string")
|
|
4990
|
+
);
|
|
4821
4991
|
for (const item of items) {
|
|
4822
4992
|
if (scannedRef.count >= 500) break;
|
|
4823
4993
|
scannedRef.count++;
|
|
@@ -4826,7 +4996,7 @@ var tool67 = {
|
|
|
4826
4996
|
allPages.push({
|
|
4827
4997
|
id: item.id ?? "",
|
|
4828
4998
|
name,
|
|
4829
|
-
url:
|
|
4999
|
+
url: urlsById.get(item.id) ?? "",
|
|
4830
5000
|
documentType: item.documentType?.name ?? item.contentTypeName ?? "",
|
|
4831
5001
|
depth,
|
|
4832
5002
|
rawDepth: depth,
|
|
@@ -5251,7 +5421,7 @@ var inputSchema73 = {
|
|
|
5251
5421
|
contentTypeKey: z.string().uuid().describe("The block element type key to target. Use inspect-blocks to find this."),
|
|
5252
5422
|
propertyAlias: z.string().describe("The document property alias containing the blocks (e.g. 'contentRows'). Use inspect-blocks to find this."),
|
|
5253
5423
|
values: z.array(z.object({
|
|
5254
|
-
alias:
|
|
5424
|
+
alias: blockPropertyAliasSchema.describe("The property alias within the block"),
|
|
5255
5425
|
value: z.any().describe("The new value for the property")
|
|
5256
5426
|
})).min(1).describe("Properties to update on every matching block"),
|
|
5257
5427
|
culture: z.string().nullable().optional().describe("Culture code if the document property is variant"),
|
|
@@ -5267,7 +5437,8 @@ var outputSchema73 = z.object({
|
|
|
5267
5437
|
previousVersionId: z.string().optional(),
|
|
5268
5438
|
error: z.union([z.string(), z.record(z.string(), z.unknown())]).optional(),
|
|
5269
5439
|
previewUrl: previewUrlSchema.optional(),
|
|
5270
|
-
validation: validationResultSchema.optional()
|
|
5440
|
+
validation: validationResultSchema.optional(),
|
|
5441
|
+
warnings: z.array(z.string()).optional()
|
|
5271
5442
|
})),
|
|
5272
5443
|
successCount: z.number(),
|
|
5273
5444
|
failureCount: z.number(),
|
|
@@ -5311,6 +5482,7 @@ var tool73 = {
|
|
|
5311
5482
|
});
|
|
5312
5483
|
const items = [];
|
|
5313
5484
|
const pageBlocks = /* @__PURE__ */ new Map();
|
|
5485
|
+
const docValuesByItem = /* @__PURE__ */ new Map();
|
|
5314
5486
|
for (const id of ids) {
|
|
5315
5487
|
const docResult = await chainCms("get-document-by-id", { id });
|
|
5316
5488
|
if (!docResult.ok) continue;
|
|
@@ -5324,6 +5496,7 @@ var tool73 = {
|
|
|
5324
5496
|
const currentVersionId = versionData?.items?.[0]?.id ?? "";
|
|
5325
5497
|
items.push({ id, name, currentVersionId });
|
|
5326
5498
|
pageBlocks.set(id, findMatchingBlocks(doc, propertyAlias, contentTypeKey));
|
|
5499
|
+
docValuesByItem.set(id, doc.values ?? []);
|
|
5327
5500
|
}
|
|
5328
5501
|
if (items.length === 0) {
|
|
5329
5502
|
return createToolResult({
|
|
@@ -5396,28 +5569,68 @@ Changes will be saved but not published.`;
|
|
|
5396
5569
|
updates
|
|
5397
5570
|
});
|
|
5398
5571
|
if (!updateResult.ok) {
|
|
5572
|
+
const enriched = enrichBlockNotFoundError(
|
|
5573
|
+
updateResult.errorResult,
|
|
5574
|
+
docValuesByItem.get(item.id) ?? [],
|
|
5575
|
+
{ propertyAlias }
|
|
5576
|
+
);
|
|
5399
5577
|
results.push({
|
|
5400
5578
|
id: item.id,
|
|
5401
5579
|
name: item.name,
|
|
5402
5580
|
success: false,
|
|
5403
5581
|
blocksUpdated: 0,
|
|
5404
5582
|
previousVersionId: item.currentVersionId || void 0,
|
|
5405
|
-
error: parseBulkError(
|
|
5583
|
+
error: parseBulkError(enriched)
|
|
5406
5584
|
});
|
|
5407
5585
|
stopped = true;
|
|
5408
5586
|
} else {
|
|
5409
|
-
|
|
5410
|
-
|
|
5411
|
-
|
|
5412
|
-
|
|
5413
|
-
|
|
5414
|
-
|
|
5415
|
-
|
|
5416
|
-
|
|
5587
|
+
const blockResults = updateResult.data.results;
|
|
5588
|
+
if (!blockResults || blockResults.length === 0) {
|
|
5589
|
+
results.push({
|
|
5590
|
+
id: item.id,
|
|
5591
|
+
name: item.name,
|
|
5592
|
+
success: false,
|
|
5593
|
+
blocksUpdated: 0,
|
|
5594
|
+
previousVersionId: item.currentVersionId || void 0,
|
|
5595
|
+
error: "update-block-property returned no per-block result \u2014 cannot confirm the write succeeded."
|
|
5596
|
+
});
|
|
5597
|
+
stopped = true;
|
|
5598
|
+
} else {
|
|
5599
|
+
const classification = classifyBlockUpdateResults(blockResults, blocks.length * values.length, fieldNames, blocks.length);
|
|
5600
|
+
if (classification.outcome === "clean") {
|
|
5601
|
+
totalBlocksUpdated += blocks.length;
|
|
5602
|
+
results.push({
|
|
5603
|
+
id: item.id,
|
|
5604
|
+
name: item.name,
|
|
5605
|
+
success: true,
|
|
5606
|
+
blocksUpdated: blocks.length,
|
|
5607
|
+
previousVersionId: item.currentVersionId || void 0,
|
|
5608
|
+
...classification.warnings.length ? { warnings: classification.warnings } : {}
|
|
5609
|
+
});
|
|
5610
|
+
} else {
|
|
5611
|
+
totalBlocksUpdated += classification.updatedEntryCount;
|
|
5612
|
+
const totalProperties = blocks.length * values.length;
|
|
5613
|
+
results.push({
|
|
5614
|
+
id: item.id,
|
|
5615
|
+
name: item.name,
|
|
5616
|
+
success: false,
|
|
5617
|
+
blocksUpdated: classification.updatedEntryCount,
|
|
5618
|
+
previousVersionId: item.currentVersionId || void 0,
|
|
5619
|
+
error: classification.outcome === "failed" ? `Block update failed: ${classification.detail}` : {
|
|
5620
|
+
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}`,
|
|
5621
|
+
savedFields: classification.savedFields,
|
|
5622
|
+
failedFields: classification.failedFields,
|
|
5623
|
+
...classification.savedFields.length > 0 ? { note: "savedFields were written to the document and must not be retried." } : {}
|
|
5624
|
+
},
|
|
5625
|
+
...classification.warnings.length ? { warnings: classification.warnings } : {}
|
|
5626
|
+
});
|
|
5627
|
+
stopped = true;
|
|
5628
|
+
}
|
|
5629
|
+
}
|
|
5417
5630
|
}
|
|
5418
5631
|
}
|
|
5419
5632
|
for (const row of results) {
|
|
5420
|
-
if (
|
|
5633
|
+
if (row.blocksUpdated === 0) continue;
|
|
5421
5634
|
row.validation = await validateDocumentState(row.id);
|
|
5422
5635
|
row.previewUrl = await fetchPreviewUrl(row.id);
|
|
5423
5636
|
}
|
|
@@ -5502,12 +5715,10 @@ var tool74 = {
|
|
|
5502
5715
|
var search_members_default = withStandardDecorators(tool74);
|
|
5503
5716
|
|
|
5504
5717
|
// src/umbraco-api/tools/member/sensitive-data-access.ts
|
|
5505
|
-
|
|
5506
|
-
async function hasSensitiveDataAccess() {
|
|
5507
|
-
if (cachedAccess !== void 0) return cachedAccess;
|
|
5718
|
+
async function checkSensitiveDataAccess() {
|
|
5508
5719
|
const result = await chainCms("get-user-current", {});
|
|
5509
|
-
|
|
5510
|
-
return
|
|
5720
|
+
if (!result.ok) return result;
|
|
5721
|
+
return { ok: true, hasAccess: result.data.hasAccessToSensitiveData ?? false };
|
|
5511
5722
|
}
|
|
5512
5723
|
|
|
5513
5724
|
// src/umbraco-api/tools/member/get/get-member.ts
|
|
@@ -5545,7 +5756,8 @@ var tool75 = {
|
|
|
5545
5756
|
const result = await chainCms("get-member", { id });
|
|
5546
5757
|
if (!result.ok) return result.errorResult;
|
|
5547
5758
|
const data = result.data;
|
|
5548
|
-
const
|
|
5759
|
+
const accessCheck = await checkSensitiveDataAccess();
|
|
5760
|
+
const accessible = accessCheck.ok && accessCheck.hasAccess;
|
|
5549
5761
|
return createToolResult({
|
|
5550
5762
|
id: data.id ?? id,
|
|
5551
5763
|
name: data.variants?.[0]?.name ?? "Unknown",
|
|
@@ -5704,12 +5916,16 @@ var tool78 = {
|
|
|
5704
5916
|
slices: ["update"],
|
|
5705
5917
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true },
|
|
5706
5918
|
handler: async ({ id, name, email, username, newPassword, isTwoFactorEnabled, isApproved, isLockedOut, groups, values }, extra) => {
|
|
5707
|
-
if (
|
|
5708
|
-
|
|
5709
|
-
|
|
5710
|
-
|
|
5711
|
-
|
|
5712
|
-
|
|
5919
|
+
if (isApproved !== void 0 || isLockedOut !== void 0 || isTwoFactorEnabled !== void 0) {
|
|
5920
|
+
const accessCheck = await checkSensitiveDataAccess();
|
|
5921
|
+
if (!accessCheck.ok) return accessCheck.errorResult;
|
|
5922
|
+
if (!accessCheck.hasAccess) {
|
|
5923
|
+
return createToolResultError({
|
|
5924
|
+
status: 403,
|
|
5925
|
+
title: "Sensitive Data access required",
|
|
5926
|
+
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."
|
|
5927
|
+
});
|
|
5928
|
+
}
|
|
5713
5929
|
}
|
|
5714
5930
|
const memberResult = await chainCms("get-member", { id });
|
|
5715
5931
|
if (!memberResult.ok) return memberResult.errorResult;
|
|
@@ -6422,6 +6638,26 @@ var outputSchema93 = z.object({
|
|
|
6422
6638
|
).describe("Pages that reference this item"),
|
|
6423
6639
|
referenceCount: z.number().describe("Total number of pages referencing this item")
|
|
6424
6640
|
});
|
|
6641
|
+
async function buildReferencedBy(refItems) {
|
|
6642
|
+
const docRefIds = refItems.filter((ref) => ref.$type === "DocumentReferenceResponseModel").map((ref) => ref.id);
|
|
6643
|
+
const urlsById = await fetchPrimaryPublishedUrlsBatch(docRefIds);
|
|
6644
|
+
return refItems.map((ref) => {
|
|
6645
|
+
if (ref.$type === "DocumentReferenceResponseModel") {
|
|
6646
|
+
return {
|
|
6647
|
+
id: ref.id,
|
|
6648
|
+
name: ref.variants?.[0]?.name ?? ref.name ?? "(unnamed)",
|
|
6649
|
+
url: urlsById.get(ref.id) ?? "",
|
|
6650
|
+
documentType: ref.documentType?.alias ?? ""
|
|
6651
|
+
};
|
|
6652
|
+
}
|
|
6653
|
+
return {
|
|
6654
|
+
id: ref.id,
|
|
6655
|
+
name: ref.name ?? "(unnamed)",
|
|
6656
|
+
url: "",
|
|
6657
|
+
documentType: ""
|
|
6658
|
+
};
|
|
6659
|
+
});
|
|
6660
|
+
}
|
|
6425
6661
|
var tool93 = {
|
|
6426
6662
|
name: "report-content-references",
|
|
6427
6663
|
description: "Find which pages reference a given content page or media item. Useful before deleting or restructuring content to understand the impact.",
|
|
@@ -6436,32 +6672,11 @@ var tool93 = {
|
|
|
6436
6672
|
chainCms("get-document-by-id-referenced-by", { id })
|
|
6437
6673
|
]);
|
|
6438
6674
|
let name = "Unknown";
|
|
6439
|
-
let url = "";
|
|
6440
6675
|
if (docResult.ok) {
|
|
6441
|
-
|
|
6442
|
-
name = doc.variants?.[0]?.name ?? "Unknown";
|
|
6443
|
-
url = doc.urls?.[0]?.url ?? "";
|
|
6444
|
-
}
|
|
6445
|
-
const referencedBy = [];
|
|
6446
|
-
if (refResult.ok) {
|
|
6447
|
-
for (const ref of refResult.data.items ?? []) {
|
|
6448
|
-
if (ref.$type === "DocumentReferenceResponseModel") {
|
|
6449
|
-
referencedBy.push({
|
|
6450
|
-
id: ref.id,
|
|
6451
|
-
name: ref.variants?.[0]?.name ?? ref.name ?? "(unnamed)",
|
|
6452
|
-
url: ref.urls?.[0]?.url ?? ref.url ?? "",
|
|
6453
|
-
documentType: ref.documentType?.alias ?? ""
|
|
6454
|
-
});
|
|
6455
|
-
} else {
|
|
6456
|
-
referencedBy.push({
|
|
6457
|
-
id: ref.id,
|
|
6458
|
-
name: ref.name ?? "(unnamed)",
|
|
6459
|
-
url: "",
|
|
6460
|
-
documentType: ""
|
|
6461
|
-
});
|
|
6462
|
-
}
|
|
6463
|
-
}
|
|
6676
|
+
name = docResult.data.variants?.[0]?.name ?? "Unknown";
|
|
6464
6677
|
}
|
|
6678
|
+
const url = await fetchPrimaryPublishedUrl(id);
|
|
6679
|
+
const referencedBy = refResult.ok ? await buildReferencedBy(refResult.data.items ?? []) : [];
|
|
6465
6680
|
return createToolResult({
|
|
6466
6681
|
id,
|
|
6467
6682
|
name,
|
|
@@ -6485,26 +6700,7 @@ var tool93 = {
|
|
|
6485
6700
|
const entry = urlResult.data.items?.find((u) => u.id === id);
|
|
6486
6701
|
url = entry?.urlInfos?.[0]?.url ?? "";
|
|
6487
6702
|
}
|
|
6488
|
-
const referencedBy = [];
|
|
6489
|
-
if (refResult.ok) {
|
|
6490
|
-
for (const ref of refResult.data.items ?? []) {
|
|
6491
|
-
if (ref.$type === "DocumentReferenceResponseModel") {
|
|
6492
|
-
referencedBy.push({
|
|
6493
|
-
id: ref.id,
|
|
6494
|
-
name: ref.variants?.[0]?.name ?? ref.name ?? "(unnamed)",
|
|
6495
|
-
url: ref.urls?.[0]?.url ?? ref.url ?? "",
|
|
6496
|
-
documentType: ref.documentType?.alias ?? ""
|
|
6497
|
-
});
|
|
6498
|
-
} else {
|
|
6499
|
-
referencedBy.push({
|
|
6500
|
-
id: ref.id,
|
|
6501
|
-
name: ref.name ?? "(unnamed)",
|
|
6502
|
-
url: "",
|
|
6503
|
-
documentType: ""
|
|
6504
|
-
});
|
|
6505
|
-
}
|
|
6506
|
-
}
|
|
6507
|
-
}
|
|
6703
|
+
const referencedBy = refResult.ok ? await buildReferencedBy(refResult.data.items ?? []) : [];
|
|
6508
6704
|
return createToolResult({
|
|
6509
6705
|
id,
|
|
6510
6706
|
name,
|
|
@@ -6677,18 +6873,18 @@ async function resolveOutboundIds(candidateIds, excludeId) {
|
|
|
6677
6873
|
const internalPages = [];
|
|
6678
6874
|
const media = [];
|
|
6679
6875
|
const filtered = excludeId ? candidateIds.filter((cid) => cid !== excludeId.toLowerCase()) : candidateIds;
|
|
6876
|
+
const urlsById = await fetchPrimaryPublishedUrlsBatch(filtered);
|
|
6680
6877
|
await Promise.all(
|
|
6681
6878
|
filtered.map(async (refId) => {
|
|
6682
6879
|
try {
|
|
6683
6880
|
const docResult = await chainCms("get-document-by-id", { id: refId });
|
|
6684
6881
|
if (docResult.ok) {
|
|
6685
6882
|
const refDoc = docResult.data;
|
|
6686
|
-
const docExtra = refDoc;
|
|
6687
6883
|
const docType = refDoc.documentType;
|
|
6688
6884
|
internalPages.push({
|
|
6689
6885
|
id: refId,
|
|
6690
6886
|
name: refDoc.variants?.[0]?.name ?? "Unknown",
|
|
6691
|
-
url:
|
|
6887
|
+
url: urlsById.get(refId) ?? "",
|
|
6692
6888
|
documentType: docType?.alias ?? ""
|
|
6693
6889
|
});
|
|
6694
6890
|
return;
|
|
@@ -6762,7 +6958,7 @@ var tool94 = {
|
|
|
6762
6958
|
const doc = result.data;
|
|
6763
6959
|
const variant = doc.variants?.[0];
|
|
6764
6960
|
const name = variant?.name ?? "Unknown";
|
|
6765
|
-
const url =
|
|
6961
|
+
const url = await fetchPrimaryPublishedUrl(id);
|
|
6766
6962
|
const values = doc.values ?? [];
|
|
6767
6963
|
const links = extractLinksFromValues(values);
|
|
6768
6964
|
const { internalPages, media } = await resolveOutboundIds(links.allIds, id);
|