@numericoach/gskills-admin-cli 0.1.26 → 0.1.27
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/README.md +46 -1
- package/dist/gskills-admin.js +1270 -15
- package/package.json +1 -1
- package/skills/gskills-admin-cli/SKILL.md +45 -4
- package/skills/gskills-page-content-blocks/SKILL.md +107 -0
package/dist/gskills-admin.js
CHANGED
|
@@ -545,6 +545,105 @@ var resources = [
|
|
|
545
545
|
aliases: ["alpha", "alpha-program", "alphas"],
|
|
546
546
|
defaultFields: ["id", "key", "name", "provider", "status", "updatedAt"]
|
|
547
547
|
},
|
|
548
|
+
{
|
|
549
|
+
name: "skill-applications",
|
|
550
|
+
delegate: "skillApplication",
|
|
551
|
+
label: "Skill applications",
|
|
552
|
+
aliases: ["skill-application", "skill-apps", "skill-app"],
|
|
553
|
+
defaultFields: ["id", "key", "name", "scope", "instanceId", "sourceLanguage", "status", "provider", "requiresAI", "alphaProgramIds", "updatedAt"],
|
|
554
|
+
dangerousDelete: true,
|
|
555
|
+
cacheScopes: ["pages", "pages-knowledge"]
|
|
556
|
+
},
|
|
557
|
+
{
|
|
558
|
+
name: "skill-capabilities",
|
|
559
|
+
delegate: "skillCapability",
|
|
560
|
+
label: "Skill capabilities",
|
|
561
|
+
aliases: ["skill-capability"],
|
|
562
|
+
defaultFields: ["id", "applicationId", "key", "name", "scope", "instanceId", "sourceLanguage", "status", "order", "requiresAI", "alphaProgramIds", "updatedAt"],
|
|
563
|
+
instanceField: "instanceId",
|
|
564
|
+
dangerousDelete: true,
|
|
565
|
+
cacheScopes: ["pages", "pages-knowledge"]
|
|
566
|
+
},
|
|
567
|
+
{
|
|
568
|
+
name: "skill-clusters",
|
|
569
|
+
delegate: "skillCluster",
|
|
570
|
+
label: "Skill clusters",
|
|
571
|
+
aliases: ["skill-cluster", "skill-domains", "skill-domain"],
|
|
572
|
+
defaultFields: ["id", "capabilityId", "key", "name", "scope", "instanceId", "sourceLanguage", "status", "order", "requiresAI", "alphaProgramIds", "updatedAt"],
|
|
573
|
+
instanceField: "instanceId",
|
|
574
|
+
dangerousDelete: true,
|
|
575
|
+
cacheScopes: ["pages", "pages-knowledge"]
|
|
576
|
+
},
|
|
577
|
+
{
|
|
578
|
+
name: "skills",
|
|
579
|
+
delegate: "skill",
|
|
580
|
+
label: "Skills",
|
|
581
|
+
aliases: ["skill", "gskills-skills", "catalog-skills", "skill-catalog-skills"],
|
|
582
|
+
defaultFields: ["id", "clusterId", "key", "name", "scope", "instanceId", "sourceLanguage", "difficulty", "status", "validationTypes", "requiresAI", "alphaProgramIds", "updatedAt"],
|
|
583
|
+
instanceField: "instanceId",
|
|
584
|
+
dangerousDelete: true,
|
|
585
|
+
cacheScopes: ["pages", "pages-knowledge"]
|
|
586
|
+
},
|
|
587
|
+
{
|
|
588
|
+
name: "skill-translations",
|
|
589
|
+
delegate: "skillTranslation",
|
|
590
|
+
label: "Skill translations",
|
|
591
|
+
aliases: ["skill-translation"],
|
|
592
|
+
defaultFields: ["id", "skillId", "language", "name", "source", "translatedAt", "updatedAt"],
|
|
593
|
+
instanceField: null,
|
|
594
|
+
dangerousDelete: true,
|
|
595
|
+
cacheScopes: ["pages", "pages-knowledge"]
|
|
596
|
+
},
|
|
597
|
+
{
|
|
598
|
+
name: "skill-dependencies",
|
|
599
|
+
delegate: "skillDependency",
|
|
600
|
+
label: "Skill dependencies",
|
|
601
|
+
aliases: ["skill-dependency"],
|
|
602
|
+
defaultFields: ["id", "skillId", "dependsOnSkillId", "type", "weight", "createdAt"],
|
|
603
|
+
instanceField: null,
|
|
604
|
+
dangerousDelete: true,
|
|
605
|
+
cacheScopes: ["pages", "pages-knowledge"]
|
|
606
|
+
},
|
|
607
|
+
{
|
|
608
|
+
name: "skill-content-links",
|
|
609
|
+
delegate: "skillContentLink",
|
|
610
|
+
label: "Skill content links",
|
|
611
|
+
aliases: ["skill-content-link", "content-skill-links", "content-skill-link"],
|
|
612
|
+
defaultFields: ["id", "skillId", "contentType", "contentId", "contentFamilyId", "contentLanguage", "role", "canValidate", "canMaster", "updatedAt"],
|
|
613
|
+
instanceField: null,
|
|
614
|
+
dangerousDelete: true,
|
|
615
|
+
cacheScopes: ["pages", "pages-knowledge"]
|
|
616
|
+
},
|
|
617
|
+
{
|
|
618
|
+
name: "skill-sets",
|
|
619
|
+
delegate: "skillSet",
|
|
620
|
+
label: "Skill sets",
|
|
621
|
+
aliases: ["skill-set"],
|
|
622
|
+
defaultFields: ["id", "key", "name", "scope", "instanceId", "sourceLanguage", "status", "badgeId", "requiresAI", "alphaProgramIds", "updatedAt"],
|
|
623
|
+
instanceField: "instanceId",
|
|
624
|
+
dangerousDelete: true,
|
|
625
|
+
cacheScopes: ["pages", "pages-knowledge"]
|
|
626
|
+
},
|
|
627
|
+
{
|
|
628
|
+
name: "skill-set-skills",
|
|
629
|
+
delegate: "skillSetSkill",
|
|
630
|
+
label: "Skill set skills",
|
|
631
|
+
aliases: ["skill-set-skill"],
|
|
632
|
+
defaultFields: ["id", "skillSetId", "skillId", "requiredStatus", "weight"],
|
|
633
|
+
instanceField: null,
|
|
634
|
+
dangerousDelete: true,
|
|
635
|
+
cacheScopes: ["pages", "pages-knowledge"]
|
|
636
|
+
},
|
|
637
|
+
{
|
|
638
|
+
name: "skill-objectives",
|
|
639
|
+
delegate: "skillObjective",
|
|
640
|
+
label: "Skill objectives",
|
|
641
|
+
aliases: ["skill-objective"],
|
|
642
|
+
defaultFields: ["id", "instanceId", "key", "name", "skillSetId", "skillIds", "isActive", "dueAt", "updatedAt"],
|
|
643
|
+
instanceField: "instanceId",
|
|
644
|
+
dangerousDelete: true,
|
|
645
|
+
cacheScopes: ["pages", "pages-knowledge"]
|
|
646
|
+
},
|
|
548
647
|
{
|
|
549
648
|
name: "quizzes",
|
|
550
649
|
delegate: "quiz",
|
|
@@ -677,6 +776,16 @@ var resources = [
|
|
|
677
776
|
dangerousDelete: true,
|
|
678
777
|
cacheScopes: ["pages", "pages-knowledge"]
|
|
679
778
|
},
|
|
779
|
+
{
|
|
780
|
+
name: "workflow-actions",
|
|
781
|
+
delegate: "workflowAction",
|
|
782
|
+
label: "Workflow actions",
|
|
783
|
+
aliases: ["workflow-action", "actions", "workflow-steps", "workflow-step"],
|
|
784
|
+
defaultFields: ["id", "workflowId", "actionType", "order", "isActive", "sourceActionId", "updatedAt"],
|
|
785
|
+
instanceField: null,
|
|
786
|
+
dangerousDelete: true,
|
|
787
|
+
cacheScopes: ["pages", "pages-knowledge"]
|
|
788
|
+
},
|
|
680
789
|
{
|
|
681
790
|
name: "imported-sheets",
|
|
682
791
|
delegate: "importedSheet",
|
|
@@ -873,6 +982,849 @@ var resourceHelpRows = () => resources.map((resource) => ({
|
|
|
873
982
|
cacheScopes: resource.cacheScopes?.join(", ") || "",
|
|
874
983
|
aliases: resource.aliases.join(", ")
|
|
875
984
|
}));
|
|
985
|
+
// ../../src/cli/page-content-schema.ts
|
|
986
|
+
var block = (type, input) => ({ type, ...input });
|
|
987
|
+
var pageContentSchema = {
|
|
988
|
+
name: "gskills-page-content-blocks",
|
|
989
|
+
version: 1,
|
|
990
|
+
command: "gskills-admin pages content-schema --output json",
|
|
991
|
+
storage: {
|
|
992
|
+
field: "Pages.content",
|
|
993
|
+
format: "JSON.stringify(EditorJS OutputData)",
|
|
994
|
+
topLevelShape: {
|
|
995
|
+
time: "optional number",
|
|
996
|
+
version: "optional string",
|
|
997
|
+
blocks: "array of EditorJS blocks"
|
|
998
|
+
},
|
|
999
|
+
blockShape: {
|
|
1000
|
+
id: "stable EditorJS block id. Preserve existing ids when patching.",
|
|
1001
|
+
type: "one of blockTypes[].type",
|
|
1002
|
+
data: "block-specific object"
|
|
1003
|
+
}
|
|
1004
|
+
},
|
|
1005
|
+
agentRules: [
|
|
1006
|
+
"Before creating or patching page content, read this schema and inspect nearby real pages.",
|
|
1007
|
+
"Prefer gskills-admin pages block commands for granular single-block edits.",
|
|
1008
|
+
"Use gskills-admin pages patch-content with RFC 6902 patches for expert multi-path edits.",
|
|
1009
|
+
"Use JSON Patch test operations on type, id, or expected text before replace/remove.",
|
|
1010
|
+
"Do not rewrite the whole content field for ordinary page edits.",
|
|
1011
|
+
"Never translate IDs, URLs, slugs, quiz ids, page ids, resource ids, importedSheetId, or file metadata.",
|
|
1012
|
+
"Preserve block ids and nested structure unless the user explicitly asks to restructure the page.",
|
|
1013
|
+
"Run dry-run first, then write with --expect-version or --expect-content-sha1."
|
|
1014
|
+
],
|
|
1015
|
+
patching: {
|
|
1016
|
+
preferredBlockCommand: "gskills-admin pages block replace-text <pageId> --block-id <blockId> --text-file ./block.txt --dry-run --output json",
|
|
1017
|
+
preferredCommand: "gskills-admin pages patch-content <pageId> --patch-file ./page.patch.json --dry-run --output json",
|
|
1018
|
+
writeCommand: "gskills-admin pages patch-content <pageId> --patch-file ./page.patch.json --expect-version <version> --yes --output json",
|
|
1019
|
+
patchFormat: "RFC 6902 JSON Patch against the parsed EditorJS object",
|
|
1020
|
+
examplePatch: [
|
|
1021
|
+
{ op: "test", path: "/blocks/0/type", value: "paragraph" },
|
|
1022
|
+
{ op: "replace", path: "/blocks/0/data/text", value: "Texte mis a jour." }
|
|
1023
|
+
]
|
|
1024
|
+
},
|
|
1025
|
+
nestedContainers: [
|
|
1026
|
+
{
|
|
1027
|
+
blockTypes: ["columns"],
|
|
1028
|
+
childBlocksPath: "/blocks/<i>/data/cols/<j>/blocks",
|
|
1029
|
+
note: "Each column owns its own EditorJS block array."
|
|
1030
|
+
},
|
|
1031
|
+
{
|
|
1032
|
+
blockTypes: ["accordion_tool", "vertical_accordion"],
|
|
1033
|
+
childBlocksPath: "/blocks/<i>/data/sections/<j>/content/blocks",
|
|
1034
|
+
note: "Each section has a title and a nested EditorJS content object."
|
|
1035
|
+
},
|
|
1036
|
+
{
|
|
1037
|
+
blockTypes: ["section_tool"],
|
|
1038
|
+
childBlocksPath: "/blocks/<i>/data/content/blocks",
|
|
1039
|
+
note: "A section is a visual wrapper around nested blocks. Gemini sections set data.gemini=true."
|
|
1040
|
+
},
|
|
1041
|
+
{
|
|
1042
|
+
blockTypes: ["tabs"],
|
|
1043
|
+
childBlocksPath: "/blocks/<i>/data/tabs/<j>/content/blocks",
|
|
1044
|
+
note: "Each tab has its own nested EditorJS content object."
|
|
1045
|
+
},
|
|
1046
|
+
{
|
|
1047
|
+
blockTypes: ["slider"],
|
|
1048
|
+
childBlocksPath: "/blocks/<i>/data/slides/<j>/content/blocks",
|
|
1049
|
+
note: "Each slide has its own nested EditorJS content object."
|
|
1050
|
+
}
|
|
1051
|
+
],
|
|
1052
|
+
immutableReferenceFields: [
|
|
1053
|
+
"quiz.quizId",
|
|
1054
|
+
"pageTag.pageId",
|
|
1055
|
+
"learningPathTag.pathId",
|
|
1056
|
+
"resourceTag.resourceId",
|
|
1057
|
+
"importedSheet.importedSheetId",
|
|
1058
|
+
"pointRedemption.blockId",
|
|
1059
|
+
"image.file.url",
|
|
1060
|
+
"video.file.url",
|
|
1061
|
+
"vimeo.videoId",
|
|
1062
|
+
"boardly.dashboardId"
|
|
1063
|
+
],
|
|
1064
|
+
blockTypes: [
|
|
1065
|
+
block("paragraph", {
|
|
1066
|
+
label: "Paragraph",
|
|
1067
|
+
category: "text",
|
|
1068
|
+
purpose: "Plain prose. Inline HTML from EditorJS may appear in text.",
|
|
1069
|
+
data: { text: "string" },
|
|
1070
|
+
example: { text: "Un paragraphe court et utile." }
|
|
1071
|
+
}),
|
|
1072
|
+
block("header", {
|
|
1073
|
+
label: "Heading",
|
|
1074
|
+
category: "text",
|
|
1075
|
+
purpose: "Section heading. Also used as an anchor source when the block has an id.",
|
|
1076
|
+
data: { text: "string", level: "number, usually 2 or 3" },
|
|
1077
|
+
example: { text: "Comprendre les partages Drive", level: 2 }
|
|
1078
|
+
}),
|
|
1079
|
+
block("list", {
|
|
1080
|
+
label: "List",
|
|
1081
|
+
category: "text",
|
|
1082
|
+
purpose: "Ordered, unordered, or checklist content.",
|
|
1083
|
+
data: { style: "unordered | ordered | checklist", items: "array of strings or list item objects" },
|
|
1084
|
+
example: { style: "unordered", items: ["Verifier le destinataire", "Controler les droits"] }
|
|
1085
|
+
}),
|
|
1086
|
+
block("quote", {
|
|
1087
|
+
label: "Quote",
|
|
1088
|
+
category: "text",
|
|
1089
|
+
purpose: "Callout-like quote from EditorJS.",
|
|
1090
|
+
data: { text: "string", caption: "optional string", alignment: "optional string" },
|
|
1091
|
+
example: { text: "Astuce: commencez par un dossier de test.", caption: "", alignment: "left" }
|
|
1092
|
+
}),
|
|
1093
|
+
block("table", {
|
|
1094
|
+
label: "Table",
|
|
1095
|
+
category: "text",
|
|
1096
|
+
purpose: "Simple tabular data.",
|
|
1097
|
+
data: { withHeadings: "boolean", content: "array of row arrays" },
|
|
1098
|
+
example: { withHeadings: true, content: [["Action", "Quand"], ["Partager", "Projet lance"]] }
|
|
1099
|
+
}),
|
|
1100
|
+
block("code", {
|
|
1101
|
+
label: "Code",
|
|
1102
|
+
category: "text",
|
|
1103
|
+
purpose: "Code snippet. The sanitizer preserves data.code as raw text.",
|
|
1104
|
+
data: { code: "string" },
|
|
1105
|
+
example: { code: "console.log('Hello GSkills')" }
|
|
1106
|
+
}),
|
|
1107
|
+
block("image", {
|
|
1108
|
+
label: "Image",
|
|
1109
|
+
category: "media",
|
|
1110
|
+
purpose: "Page image uploaded or linked through the editor image tool.",
|
|
1111
|
+
data: { file: "object with url", caption: "optional string", withBorder: "optional boolean", stretched: "optional boolean", withBackground: "optional boolean" },
|
|
1112
|
+
example: { file: { url: "https://storage.googleapis.com/..." }, caption: "Capture d'ecran", withBorder: false },
|
|
1113
|
+
notes: ["Do not invent storage URLs. Upload or reuse a real asset."]
|
|
1114
|
+
}),
|
|
1115
|
+
block("video", {
|
|
1116
|
+
label: "Video",
|
|
1117
|
+
category: "media",
|
|
1118
|
+
purpose: "Page video uploaded or linked through the editor video tool.",
|
|
1119
|
+
data: { file: "object with url", caption: "optional string" },
|
|
1120
|
+
example: { file: { url: "https://storage.googleapis.com/..." }, caption: "Demonstration" },
|
|
1121
|
+
notes: ["Use CLI signed uploads for local videos."]
|
|
1122
|
+
}),
|
|
1123
|
+
block("iframe", {
|
|
1124
|
+
label: "Iframe",
|
|
1125
|
+
category: "embed",
|
|
1126
|
+
purpose: "Embedded external frame.",
|
|
1127
|
+
data: { url: "string", height: "optional number" },
|
|
1128
|
+
example: { url: "https://example.com/embed", height: 480 }
|
|
1129
|
+
}),
|
|
1130
|
+
block("vimeo", {
|
|
1131
|
+
label: "Vimeo",
|
|
1132
|
+
category: "embed",
|
|
1133
|
+
purpose: "Vimeo video embed.",
|
|
1134
|
+
data: { url: "string", videoId: "string", title: "optional string" },
|
|
1135
|
+
example: { url: "https://vimeo.com/123456789", videoId: "123456789", title: "Replay" }
|
|
1136
|
+
}),
|
|
1137
|
+
block("anchor", {
|
|
1138
|
+
label: "Anchor",
|
|
1139
|
+
category: "system",
|
|
1140
|
+
purpose: "Named anchor for menu or learning-path section links.",
|
|
1141
|
+
data: { title: "string" },
|
|
1142
|
+
example: { title: "Configurer les acces" }
|
|
1143
|
+
}),
|
|
1144
|
+
block("columns", {
|
|
1145
|
+
label: "Columns",
|
|
1146
|
+
category: "layout",
|
|
1147
|
+
purpose: "Multi-column layout. Each column contains nested blocks.",
|
|
1148
|
+
data: { cols: "array of { blocks: EditorBlock[] }" },
|
|
1149
|
+
example: { cols: [{ blocks: [{ type: "paragraph", data: { text: "Colonne gauche" } }] }, { blocks: [{ type: "paragraph", data: { text: "Colonne droite" } }] }] },
|
|
1150
|
+
notes: ["Avoid deep nesting. The editor limits recursive tools to prevent loops."]
|
|
1151
|
+
}),
|
|
1152
|
+
block("accordion_tool", {
|
|
1153
|
+
label: "Accordion",
|
|
1154
|
+
category: "layout",
|
|
1155
|
+
purpose: "Primary course module layout. Each section is a collapsible mini-module.",
|
|
1156
|
+
data: { sections: "array of { title, content, isOpen }", color: "hex color string" },
|
|
1157
|
+
example: { color: "#388ae5", sections: [{ title: "1. Comprendre", content: { blocks: [{ type: "paragraph", data: { text: "Explication." } }] }, isOpen: false }] },
|
|
1158
|
+
notes: ["Common for courses. Keep each section rich enough to stand alone."]
|
|
1159
|
+
}),
|
|
1160
|
+
block("vertical_accordion", {
|
|
1161
|
+
label: "Vertical Accordion",
|
|
1162
|
+
category: "layout",
|
|
1163
|
+
purpose: "Vertical variant of accordion, usually for compact sequences.",
|
|
1164
|
+
data: { sections: "array of { title, content, isOpen }", color: "hex color string", orientation: "vertical" },
|
|
1165
|
+
example: { color: "#2E5FAC", orientation: "vertical", sections: [{ title: "Etape 1", content: { blocks: [] }, isOpen: false }] }
|
|
1166
|
+
}),
|
|
1167
|
+
block("section_tool", {
|
|
1168
|
+
label: "Section",
|
|
1169
|
+
category: "layout",
|
|
1170
|
+
purpose: "Visual section wrapper. Gemini sections use gemini=true.",
|
|
1171
|
+
data: { backgroundColor: "hex color string", padding: "number", content: "EditorJS OutputData", gemini: "boolean" },
|
|
1172
|
+
example: { backgroundColor: "#eff6ff", padding: 16, gemini: true, content: { blocks: [{ type: "header", data: { text: "Avec Gemini", level: 2 } }] } }
|
|
1173
|
+
}),
|
|
1174
|
+
block("tabs", {
|
|
1175
|
+
label: "Tabs",
|
|
1176
|
+
category: "layout",
|
|
1177
|
+
purpose: "Tabbed layout, each tab containing nested blocks.",
|
|
1178
|
+
data: { tabs: "array of { id, title, content }", activeTab: "string" },
|
|
1179
|
+
example: { activeTab: "tab-1", tabs: [{ id: "tab-1", title: "Admin", content: { blocks: [] } }] }
|
|
1180
|
+
}),
|
|
1181
|
+
block("slider", {
|
|
1182
|
+
label: "Slider",
|
|
1183
|
+
category: "layout",
|
|
1184
|
+
purpose: "Slide-based layout, each slide containing nested blocks.",
|
|
1185
|
+
data: { slides: "array of { id, title, content }", activeSlide: "string", sliderColor: "hex color string" },
|
|
1186
|
+
example: { activeSlide: "slide-1", sliderColor: "#2E5FAC", slides: [{ id: "slide-1", title: "Avant", content: { blocks: [] } }] }
|
|
1187
|
+
}),
|
|
1188
|
+
block("quiz", {
|
|
1189
|
+
label: "Embedded Quiz",
|
|
1190
|
+
category: "interactive",
|
|
1191
|
+
purpose: "Embeds an existing quiz in a page.",
|
|
1192
|
+
data: { quizId: "string", quizTitle: "string", quizLang: "string" },
|
|
1193
|
+
example: { quizId: "quiz_abc123", quizTitle: "Quiz Gmail", quizLang: "fr" },
|
|
1194
|
+
notes: ["Use a real quiz id. Translate/relink to same-language quiz when translating page content."]
|
|
1195
|
+
}),
|
|
1196
|
+
block("pointRedemption", {
|
|
1197
|
+
label: "Point Redemption",
|
|
1198
|
+
category: "interactive",
|
|
1199
|
+
purpose: "Completion/reward button tied to a block id.",
|
|
1200
|
+
data: { text: "string", points: "number", blockId: "string", color: "string", redeemedText: "string" },
|
|
1201
|
+
example: { text: "Completer cette etape", points: 10, blockId: "drive-share-step", color: "#2E5FAC", redeemedText: "Etape terminee" }
|
|
1202
|
+
}),
|
|
1203
|
+
block("pageTag", {
|
|
1204
|
+
label: "Page Tag",
|
|
1205
|
+
category: "reference",
|
|
1206
|
+
purpose: "Reference card linking to another GSkills page.",
|
|
1207
|
+
data: { pageId: "string", pageName: "string", pageSlug: "string", description: "optional string", pageIcon: "optional string", categoryIcon: "optional string" },
|
|
1208
|
+
example: { pageId: "page_abc123", pageName: "Gmail", pageSlug: "gmail", description: "Aller plus loin" }
|
|
1209
|
+
}),
|
|
1210
|
+
block("learningPathTag", {
|
|
1211
|
+
label: "Learning Path Tag",
|
|
1212
|
+
category: "reference",
|
|
1213
|
+
purpose: "Reference card linking to a parcours.",
|
|
1214
|
+
data: { pathId: "string", pathName: "string", pathSlug: "string", description: "optional string" },
|
|
1215
|
+
example: { pathId: "lp_abc123", pathName: "Parcours Gemini", pathSlug: "parcours-gemini" }
|
|
1216
|
+
}),
|
|
1217
|
+
block("resourceTag", {
|
|
1218
|
+
label: "Resource Tag",
|
|
1219
|
+
category: "reference",
|
|
1220
|
+
purpose: "Reference card linking to a resource.",
|
|
1221
|
+
data: { resourceId: "string", resourceName: "string", description: "optional string", resourceType: "optional string" },
|
|
1222
|
+
example: { resourceId: "resource_abc123", resourceName: "Replay webinar", resourceType: "WEBINAR" }
|
|
1223
|
+
}),
|
|
1224
|
+
block("card", {
|
|
1225
|
+
label: "Card",
|
|
1226
|
+
category: "reference",
|
|
1227
|
+
purpose: "Manual card-style callout.",
|
|
1228
|
+
data: { title: "string", description: "string", iconUrl: "optional string", url: "optional string" },
|
|
1229
|
+
example: { title: "A retenir", description: "Un conseil actionnable.", iconUrl: "" }
|
|
1230
|
+
}),
|
|
1231
|
+
block("importedSheet", {
|
|
1232
|
+
label: "Imported Sheet",
|
|
1233
|
+
category: "reference",
|
|
1234
|
+
purpose: "Embeds an imported Google Sheet widget.",
|
|
1235
|
+
data: { importedSheetId: "string", locale: "language code" },
|
|
1236
|
+
example: { importedSheetId: "sheet_abc123", locale: "fr" },
|
|
1237
|
+
notes: ["Use imported-sheets CLI commands to create or inspect the sheet first."]
|
|
1238
|
+
}),
|
|
1239
|
+
block("boardly", {
|
|
1240
|
+
label: "Boardly",
|
|
1241
|
+
category: "embed",
|
|
1242
|
+
purpose: "Embeds a Boardly dashboard.",
|
|
1243
|
+
data: { dashboardId: "string", title: "optional string" },
|
|
1244
|
+
example: { dashboardId: "boardly_abc123", title: "Tableau de bord" }
|
|
1245
|
+
}),
|
|
1246
|
+
block("keystroke", {
|
|
1247
|
+
label: "Keystroke",
|
|
1248
|
+
category: "interactive",
|
|
1249
|
+
purpose: "Displays keyboard shortcuts.",
|
|
1250
|
+
data: { keys: "array or string depending on saved editor state", description: "string", borderColor: "optional string" },
|
|
1251
|
+
example: { keys: ["Ctrl", "K"], description: "Ouvrir la recherche", borderColor: "#2E5FAC" }
|
|
1252
|
+
}),
|
|
1253
|
+
block("actualitesNumeriblog", {
|
|
1254
|
+
label: "Numeriblog News",
|
|
1255
|
+
category: "embed",
|
|
1256
|
+
purpose: "Embeds Numeriblog news feed.",
|
|
1257
|
+
data: { title: "optional string", limit: "optional number" },
|
|
1258
|
+
example: { title: "Actualites Numeriblog", limit: 4 }
|
|
1259
|
+
}),
|
|
1260
|
+
block("googleWorkspaceNews", {
|
|
1261
|
+
label: "Google Workspace News",
|
|
1262
|
+
category: "embed",
|
|
1263
|
+
purpose: "Embeds Google Workspace news feed.",
|
|
1264
|
+
data: { title: "optional string", limit: "optional number" },
|
|
1265
|
+
example: { title: "Actualites Google Workspace", limit: 4 }
|
|
1266
|
+
}),
|
|
1267
|
+
block("sustainability", {
|
|
1268
|
+
label: "Sustainability",
|
|
1269
|
+
category: "interactive",
|
|
1270
|
+
purpose: "Sustainability impact calculator/content block.",
|
|
1271
|
+
data: { title: "string", description: "optional string", values: "tool-specific object" },
|
|
1272
|
+
example: { title: "Impact environnemental", description: "Estimation indicative" }
|
|
1273
|
+
}),
|
|
1274
|
+
block("rankingBadge", {
|
|
1275
|
+
label: "Ranking Badge",
|
|
1276
|
+
category: "interactive",
|
|
1277
|
+
purpose: "Badge/ranking visual block.",
|
|
1278
|
+
data: { title: "string", rank: "optional number", label: "optional string" },
|
|
1279
|
+
example: { title: "Champion Drive", rank: 1, label: "Top contributeur" }
|
|
1280
|
+
}),
|
|
1281
|
+
block("headerStyle", {
|
|
1282
|
+
label: "Header Style",
|
|
1283
|
+
category: "system",
|
|
1284
|
+
purpose: "Custom heading style tool. Prefer normal header unless matching an existing page.",
|
|
1285
|
+
data: { text: "string", level: "optional number", style: "optional string" },
|
|
1286
|
+
example: { text: "Titre stylise", level: 2, style: "default" }
|
|
1287
|
+
})
|
|
1288
|
+
],
|
|
1289
|
+
highRiskBlocks: [
|
|
1290
|
+
"quiz",
|
|
1291
|
+
"pageTag",
|
|
1292
|
+
"learningPathTag",
|
|
1293
|
+
"resourceTag",
|
|
1294
|
+
"importedSheet",
|
|
1295
|
+
"pointRedemption",
|
|
1296
|
+
"image",
|
|
1297
|
+
"video",
|
|
1298
|
+
"vimeo",
|
|
1299
|
+
"boardly"
|
|
1300
|
+
],
|
|
1301
|
+
validationChecklist: [
|
|
1302
|
+
"JSON parses and top-level blocks is an array.",
|
|
1303
|
+
"Every block has type and data.",
|
|
1304
|
+
"Nested containers use EditorJS OutputData objects with blocks arrays.",
|
|
1305
|
+
"Reference blocks use real ids from CLI reads, never invented ids.",
|
|
1306
|
+
"A dry-run page patch shows expected block/text deltas.",
|
|
1307
|
+
"After write, verify currentVersion changed and cache scopes are clear when visible content changed."
|
|
1308
|
+
]
|
|
1309
|
+
};
|
|
1310
|
+
|
|
1311
|
+
// ../../src/cli/page-blocks.ts
|
|
1312
|
+
import { createHash, randomUUID as randomUUID2 } from "node:crypto";
|
|
1313
|
+
var blockTypeSet = new Set(pageContentSchema.blockTypes.map((block2) => block2.type));
|
|
1314
|
+
var sha1String = (value) => createHash("sha1").update(value, "utf8").digest("hex");
|
|
1315
|
+
var parseEditorDocument = (rawContent) => {
|
|
1316
|
+
if (typeof rawContent !== "string") {
|
|
1317
|
+
throw new CliError("Page row does not include a string content field", 2);
|
|
1318
|
+
}
|
|
1319
|
+
let parsed;
|
|
1320
|
+
try {
|
|
1321
|
+
parsed = JSON.parse(rawContent);
|
|
1322
|
+
} catch {
|
|
1323
|
+
throw new CliError("Page content is not valid JSON", 2);
|
|
1324
|
+
}
|
|
1325
|
+
if (!isPlainRecord(parsed) || !Array.isArray(parsed.blocks)) {
|
|
1326
|
+
throw new CliError("Page content must be an EditorJS object with a blocks array", 2);
|
|
1327
|
+
}
|
|
1328
|
+
return parsed;
|
|
1329
|
+
};
|
|
1330
|
+
var validatePageContent = (content) => {
|
|
1331
|
+
const errors = [];
|
|
1332
|
+
const warnings = [];
|
|
1333
|
+
const blockIds = new Map;
|
|
1334
|
+
const unsupportedTypes = new Set;
|
|
1335
|
+
const locations = collectBlockLocations(content);
|
|
1336
|
+
for (const location of locations) {
|
|
1337
|
+
const path = toJsonPointer(location.blockPath);
|
|
1338
|
+
const block2 = location.block;
|
|
1339
|
+
if (!isPlainRecord(block2)) {
|
|
1340
|
+
errors.push(`${path} must be an object`);
|
|
1341
|
+
continue;
|
|
1342
|
+
}
|
|
1343
|
+
if (typeof block2.type !== "string" || block2.type.trim() === "") {
|
|
1344
|
+
errors.push(`${path}/type must be a non-empty string`);
|
|
1345
|
+
} else if (!blockTypeSet.has(block2.type)) {
|
|
1346
|
+
errors.push(`${path}/type "${block2.type}" is not in pages content-schema`);
|
|
1347
|
+
unsupportedTypes.add(block2.type);
|
|
1348
|
+
}
|
|
1349
|
+
if (block2.data === undefined) {
|
|
1350
|
+
errors.push(`${path}/data is required`);
|
|
1351
|
+
} else if (!isPlainRecord(block2.data)) {
|
|
1352
|
+
errors.push(`${path}/data must be an object`);
|
|
1353
|
+
}
|
|
1354
|
+
if (typeof block2.id === "string" && block2.id.trim()) {
|
|
1355
|
+
const firstPath = blockIds.get(block2.id);
|
|
1356
|
+
if (firstPath) {
|
|
1357
|
+
warnings.push(`${path}/id duplicates ${firstPath}/id (${block2.id})`);
|
|
1358
|
+
} else {
|
|
1359
|
+
blockIds.set(block2.id, path);
|
|
1360
|
+
}
|
|
1361
|
+
} else {
|
|
1362
|
+
warnings.push(`${path}/id is missing. Granular updates work best with stable block ids.`);
|
|
1363
|
+
}
|
|
1364
|
+
validateContainerShape(block2, path, errors);
|
|
1365
|
+
}
|
|
1366
|
+
return {
|
|
1367
|
+
ok: errors.length === 0,
|
|
1368
|
+
schema: {
|
|
1369
|
+
name: pageContentSchema.name,
|
|
1370
|
+
version: pageContentSchema.version
|
|
1371
|
+
},
|
|
1372
|
+
blockCount: locations.length,
|
|
1373
|
+
errors,
|
|
1374
|
+
warnings,
|
|
1375
|
+
unsupportedTypes: Array.from(unsupportedTypes).sort()
|
|
1376
|
+
};
|
|
1377
|
+
};
|
|
1378
|
+
var summarizeBlocks = (content) => collectBlockLocations(content).map((location) => ({
|
|
1379
|
+
id: location.block.id ?? null,
|
|
1380
|
+
type: location.block.type ?? null,
|
|
1381
|
+
path: toJsonPointer(location.blockPath),
|
|
1382
|
+
depth: location.depth,
|
|
1383
|
+
dataKeys: isPlainRecord(location.block.data) ? Object.keys(location.block.data).sort() : [],
|
|
1384
|
+
textPreview: getBlockTextPreview(location.block)
|
|
1385
|
+
}));
|
|
1386
|
+
var getBlockById = (content, blockId) => {
|
|
1387
|
+
const location = findBlockLocationById(content, blockId);
|
|
1388
|
+
if (!location) {
|
|
1389
|
+
throw new CliError(`Block not found: ${blockId}`, 2);
|
|
1390
|
+
}
|
|
1391
|
+
return {
|
|
1392
|
+
id: location.block.id ?? null,
|
|
1393
|
+
type: location.block.type ?? null,
|
|
1394
|
+
path: toJsonPointer(location.blockPath),
|
|
1395
|
+
depth: location.depth,
|
|
1396
|
+
dataKeys: isPlainRecord(location.block.data) ? Object.keys(location.block.data).sort() : [],
|
|
1397
|
+
textPreview: getBlockTextPreview(location.block),
|
|
1398
|
+
block: location.block
|
|
1399
|
+
};
|
|
1400
|
+
};
|
|
1401
|
+
var planReplaceText = (content, input) => {
|
|
1402
|
+
const beforeValidation = validatePageContent(content);
|
|
1403
|
+
const beforeBlock = requireBlock(content, input.blockId, input.expectType);
|
|
1404
|
+
const fieldSegments = resolveTextFieldSegments(beforeBlock.block, input.field);
|
|
1405
|
+
const currentValue = getObjectPathValue(beforeBlock.block, fieldSegments);
|
|
1406
|
+
if (typeof currentValue !== "string") {
|
|
1407
|
+
throw new CliError(`${toJsonPointer(beforeBlock.blockPath.concat(fieldSegments))} is not a string`, 2);
|
|
1408
|
+
}
|
|
1409
|
+
if (input.expectText !== undefined && currentValue !== input.expectText) {
|
|
1410
|
+
throw new CliError("Current block text does not match --expect-text", 2, {
|
|
1411
|
+
blockId: input.blockId,
|
|
1412
|
+
expected: input.expectText,
|
|
1413
|
+
actual: currentValue
|
|
1414
|
+
});
|
|
1415
|
+
}
|
|
1416
|
+
const patch = [
|
|
1417
|
+
{ op: "test", path: `${toJsonPointer(beforeBlock.blockPath)}/id`, value: input.blockId },
|
|
1418
|
+
{ op: "test", path: `${toJsonPointer(beforeBlock.blockPath)}/type`, value: beforeBlock.block.type },
|
|
1419
|
+
{ op: "test", path: toJsonPointer(beforeBlock.blockPath.concat(fieldSegments)), value: currentValue },
|
|
1420
|
+
{ op: "replace", path: toJsonPointer(beforeBlock.blockPath.concat(fieldSegments)), value: input.text }
|
|
1421
|
+
];
|
|
1422
|
+
const afterContent = cloneEditorDocument(content);
|
|
1423
|
+
const afterTarget = requireBlock(afterContent, input.blockId, input.expectType);
|
|
1424
|
+
setObjectPathValue(afterTarget.block, fieldSegments, input.text);
|
|
1425
|
+
const afterValidation = validatePageContent(afterContent);
|
|
1426
|
+
assertNoNewValidationErrors(beforeValidation, afterValidation);
|
|
1427
|
+
return {
|
|
1428
|
+
patch,
|
|
1429
|
+
beforeContent: content,
|
|
1430
|
+
afterContent,
|
|
1431
|
+
beforeValidation,
|
|
1432
|
+
afterValidation,
|
|
1433
|
+
beforeBlock,
|
|
1434
|
+
afterBlock: requireBlock(afterContent, input.blockId, input.expectType),
|
|
1435
|
+
changedBlockId: input.blockId
|
|
1436
|
+
};
|
|
1437
|
+
};
|
|
1438
|
+
var planReplaceBlock = (content, input) => {
|
|
1439
|
+
const beforeValidation = validatePageContent(content);
|
|
1440
|
+
const beforeBlock = requireBlock(content, input.blockId, input.expectType);
|
|
1441
|
+
const nextBlock = normalizeInputBlock(input.block, beforeBlock.block.id ?? input.blockId);
|
|
1442
|
+
if (!input.allowIdChange && nextBlock.id !== input.blockId) {
|
|
1443
|
+
throw new CliError("Replacement block id must match --block-id unless --allow-id-change is passed", 2);
|
|
1444
|
+
}
|
|
1445
|
+
const blockValidation = validateStandaloneBlock(nextBlock);
|
|
1446
|
+
if (!blockValidation.ok) {
|
|
1447
|
+
throw new CliError("Replacement block does not match the page block schema", 2, {
|
|
1448
|
+
errors: blockValidation.errors,
|
|
1449
|
+
warnings: blockValidation.warnings
|
|
1450
|
+
});
|
|
1451
|
+
}
|
|
1452
|
+
const patch = [
|
|
1453
|
+
{ op: "test", path: `${toJsonPointer(beforeBlock.blockPath)}/id`, value: input.blockId },
|
|
1454
|
+
{ op: "test", path: `${toJsonPointer(beforeBlock.blockPath)}/type`, value: beforeBlock.block.type },
|
|
1455
|
+
{ op: "replace", path: toJsonPointer(beforeBlock.blockPath), value: nextBlock }
|
|
1456
|
+
];
|
|
1457
|
+
const afterContent = cloneEditorDocument(content);
|
|
1458
|
+
const afterTarget = requireBlock(afterContent, input.blockId, input.expectType);
|
|
1459
|
+
const container = getArrayAtPath(afterContent, afterTarget.containerPath);
|
|
1460
|
+
container[afterTarget.index] = nextBlock;
|
|
1461
|
+
const afterValidation = validatePageContent(afterContent);
|
|
1462
|
+
assertNoNewValidationErrors(beforeValidation, afterValidation);
|
|
1463
|
+
return {
|
|
1464
|
+
patch,
|
|
1465
|
+
beforeContent: content,
|
|
1466
|
+
afterContent,
|
|
1467
|
+
beforeValidation,
|
|
1468
|
+
afterValidation,
|
|
1469
|
+
beforeBlock,
|
|
1470
|
+
afterBlock: findBlockLocationById(afterContent, nextBlock.id ?? input.blockId) ?? undefined,
|
|
1471
|
+
changedBlockId: nextBlock.id ?? input.blockId
|
|
1472
|
+
};
|
|
1473
|
+
};
|
|
1474
|
+
var planInsertAfterBlock = (content, input) => {
|
|
1475
|
+
const beforeValidation = validatePageContent(content);
|
|
1476
|
+
const beforeBlock = requireBlock(content, input.anchorBlockId);
|
|
1477
|
+
const nextBlock = normalizeInputBlock(input.block);
|
|
1478
|
+
const blockValidation = validateStandaloneBlock(nextBlock);
|
|
1479
|
+
if (!blockValidation.ok) {
|
|
1480
|
+
throw new CliError("Inserted block does not match the page block schema", 2, {
|
|
1481
|
+
errors: blockValidation.errors,
|
|
1482
|
+
warnings: blockValidation.warnings
|
|
1483
|
+
});
|
|
1484
|
+
}
|
|
1485
|
+
const insertPath = beforeBlock.containerPath.concat(beforeBlock.index + 1);
|
|
1486
|
+
const patch = [
|
|
1487
|
+
{ op: "test", path: `${toJsonPointer(beforeBlock.blockPath)}/id`, value: input.anchorBlockId },
|
|
1488
|
+
{ op: "test", path: `${toJsonPointer(beforeBlock.blockPath)}/type`, value: beforeBlock.block.type },
|
|
1489
|
+
{ op: "add", path: toJsonPointer(insertPath), value: nextBlock }
|
|
1490
|
+
];
|
|
1491
|
+
const afterContent = cloneEditorDocument(content);
|
|
1492
|
+
const afterAnchor = requireBlock(afterContent, input.anchorBlockId);
|
|
1493
|
+
getArrayAtPath(afterContent, afterAnchor.containerPath).splice(afterAnchor.index + 1, 0, nextBlock);
|
|
1494
|
+
const afterValidation = validatePageContent(afterContent);
|
|
1495
|
+
assertNoNewValidationErrors(beforeValidation, afterValidation);
|
|
1496
|
+
return {
|
|
1497
|
+
patch,
|
|
1498
|
+
beforeContent: content,
|
|
1499
|
+
afterContent,
|
|
1500
|
+
beforeValidation,
|
|
1501
|
+
afterValidation,
|
|
1502
|
+
beforeBlock,
|
|
1503
|
+
afterBlock: nextBlock.id ? findBlockLocationById(afterContent, nextBlock.id) ?? undefined : undefined,
|
|
1504
|
+
changedBlockId: nextBlock.id
|
|
1505
|
+
};
|
|
1506
|
+
};
|
|
1507
|
+
var planInsertBeforeBlock = (content, input) => {
|
|
1508
|
+
const beforeValidation = validatePageContent(content);
|
|
1509
|
+
const beforeBlock = requireBlock(content, input.anchorBlockId);
|
|
1510
|
+
const nextBlock = normalizeInputBlock(input.block);
|
|
1511
|
+
const blockValidation = validateStandaloneBlock(nextBlock);
|
|
1512
|
+
if (!blockValidation.ok) {
|
|
1513
|
+
throw new CliError("Inserted block does not match the page block schema", 2, {
|
|
1514
|
+
errors: blockValidation.errors,
|
|
1515
|
+
warnings: blockValidation.warnings
|
|
1516
|
+
});
|
|
1517
|
+
}
|
|
1518
|
+
const insertPath = beforeBlock.containerPath.concat(beforeBlock.index);
|
|
1519
|
+
const patch = [
|
|
1520
|
+
{ op: "test", path: `${toJsonPointer(beforeBlock.blockPath)}/id`, value: input.anchorBlockId },
|
|
1521
|
+
{ op: "test", path: `${toJsonPointer(beforeBlock.blockPath)}/type`, value: beforeBlock.block.type },
|
|
1522
|
+
{ op: "add", path: toJsonPointer(insertPath), value: nextBlock }
|
|
1523
|
+
];
|
|
1524
|
+
const afterContent = cloneEditorDocument(content);
|
|
1525
|
+
const afterAnchor = requireBlock(afterContent, input.anchorBlockId);
|
|
1526
|
+
getArrayAtPath(afterContent, afterAnchor.containerPath).splice(afterAnchor.index, 0, nextBlock);
|
|
1527
|
+
const afterValidation = validatePageContent(afterContent);
|
|
1528
|
+
assertNoNewValidationErrors(beforeValidation, afterValidation);
|
|
1529
|
+
return {
|
|
1530
|
+
patch,
|
|
1531
|
+
beforeContent: content,
|
|
1532
|
+
afterContent,
|
|
1533
|
+
beforeValidation,
|
|
1534
|
+
afterValidation,
|
|
1535
|
+
beforeBlock,
|
|
1536
|
+
afterBlock: nextBlock.id ? findBlockLocationById(afterContent, nextBlock.id) ?? undefined : undefined,
|
|
1537
|
+
changedBlockId: nextBlock.id
|
|
1538
|
+
};
|
|
1539
|
+
};
|
|
1540
|
+
var planRemoveBlock = (content, input) => {
|
|
1541
|
+
const beforeValidation = validatePageContent(content);
|
|
1542
|
+
const beforeBlock = requireBlock(content, input.blockId, input.expectType);
|
|
1543
|
+
const patch = [
|
|
1544
|
+
{ op: "test", path: `${toJsonPointer(beforeBlock.blockPath)}/id`, value: input.blockId },
|
|
1545
|
+
{ op: "test", path: `${toJsonPointer(beforeBlock.blockPath)}/type`, value: beforeBlock.block.type },
|
|
1546
|
+
{ op: "remove", path: toJsonPointer(beforeBlock.blockPath) }
|
|
1547
|
+
];
|
|
1548
|
+
const afterContent = cloneEditorDocument(content);
|
|
1549
|
+
const afterTarget = requireBlock(afterContent, input.blockId, input.expectType);
|
|
1550
|
+
getArrayAtPath(afterContent, afterTarget.containerPath).splice(afterTarget.index, 1);
|
|
1551
|
+
const afterValidation = validatePageContent(afterContent);
|
|
1552
|
+
assertNoNewValidationErrors(beforeValidation, afterValidation);
|
|
1553
|
+
return {
|
|
1554
|
+
patch,
|
|
1555
|
+
beforeContent: content,
|
|
1556
|
+
afterContent,
|
|
1557
|
+
beforeValidation,
|
|
1558
|
+
afterValidation,
|
|
1559
|
+
beforeBlock,
|
|
1560
|
+
changedBlockId: input.blockId
|
|
1561
|
+
};
|
|
1562
|
+
};
|
|
1563
|
+
var validateStandaloneBlock = (block2) => validatePageContent({ blocks: [block2] });
|
|
1564
|
+
var assertNoNewValidationErrors = (before, after) => {
|
|
1565
|
+
const beforeErrors = new Set(before.errors);
|
|
1566
|
+
const newErrors = after.errors.filter((error) => !beforeErrors.has(error));
|
|
1567
|
+
if (newErrors.length > 0) {
|
|
1568
|
+
throw new CliError("Block operation would make page content invalid", 2, {
|
|
1569
|
+
errors: newErrors,
|
|
1570
|
+
warnings: after.warnings
|
|
1571
|
+
});
|
|
1572
|
+
}
|
|
1573
|
+
};
|
|
1574
|
+
var requireBlock = (content, blockId, expectType) => {
|
|
1575
|
+
const location = findBlockLocationById(content, blockId);
|
|
1576
|
+
if (!location) {
|
|
1577
|
+
throw new CliError(`Block not found: ${blockId}`, 2);
|
|
1578
|
+
}
|
|
1579
|
+
if (expectType && location.block.type !== expectType) {
|
|
1580
|
+
throw new CliError("Block type does not match --expect-type", 2, {
|
|
1581
|
+
blockId,
|
|
1582
|
+
expected: expectType,
|
|
1583
|
+
actual: location.block.type ?? null
|
|
1584
|
+
});
|
|
1585
|
+
}
|
|
1586
|
+
if (typeof location.block.type !== "string") {
|
|
1587
|
+
throw new CliError(`Block ${blockId} has no type`, 2);
|
|
1588
|
+
}
|
|
1589
|
+
return location;
|
|
1590
|
+
};
|
|
1591
|
+
var findBlockLocationById = (content, blockId) => collectBlockLocations(content).find((location) => location.block.id === blockId);
|
|
1592
|
+
var collectBlockLocations = (content) => {
|
|
1593
|
+
const locations = [];
|
|
1594
|
+
visitBlockArray(content.blocks, ["blocks"], 0, locations);
|
|
1595
|
+
return locations;
|
|
1596
|
+
};
|
|
1597
|
+
var visitBlockArray = (blocks, containerPath, depth, locations) => {
|
|
1598
|
+
blocks.forEach((candidate, index) => {
|
|
1599
|
+
if (!isPlainRecord(candidate)) {
|
|
1600
|
+
locations.push({
|
|
1601
|
+
block: candidate,
|
|
1602
|
+
index,
|
|
1603
|
+
depth,
|
|
1604
|
+
blockPath: containerPath.concat(index),
|
|
1605
|
+
containerPath
|
|
1606
|
+
});
|
|
1607
|
+
return;
|
|
1608
|
+
}
|
|
1609
|
+
const block2 = candidate;
|
|
1610
|
+
const blockPath = containerPath.concat(index);
|
|
1611
|
+
locations.push({ block: block2, index, depth, blockPath, containerPath });
|
|
1612
|
+
for (const childContainer of childBlockContainers(block2, blockPath)) {
|
|
1613
|
+
visitBlockArray(childContainer.blocks, childContainer.path, depth + 1, locations);
|
|
1614
|
+
}
|
|
1615
|
+
});
|
|
1616
|
+
};
|
|
1617
|
+
var childBlockContainers = (block2, blockPath) => {
|
|
1618
|
+
const containers = [];
|
|
1619
|
+
const data = isPlainRecord(block2.data) ? block2.data : null;
|
|
1620
|
+
if (!data)
|
|
1621
|
+
return containers;
|
|
1622
|
+
if (block2.type === "columns" && Array.isArray(data.cols)) {
|
|
1623
|
+
data.cols.forEach((column, columnIndex) => {
|
|
1624
|
+
if (isPlainRecord(column) && Array.isArray(column.blocks)) {
|
|
1625
|
+
containers.push({
|
|
1626
|
+
path: blockPath.concat(["data", "cols", columnIndex, "blocks"]),
|
|
1627
|
+
blocks: column.blocks
|
|
1628
|
+
});
|
|
1629
|
+
}
|
|
1630
|
+
});
|
|
1631
|
+
}
|
|
1632
|
+
if ((block2.type === "accordion_tool" || block2.type === "vertical_accordion") && Array.isArray(data.sections)) {
|
|
1633
|
+
data.sections.forEach((section, sectionIndex) => {
|
|
1634
|
+
if (isPlainRecord(section) && isPlainRecord(section.content) && Array.isArray(section.content.blocks)) {
|
|
1635
|
+
containers.push({
|
|
1636
|
+
path: blockPath.concat(["data", "sections", sectionIndex, "content", "blocks"]),
|
|
1637
|
+
blocks: section.content.blocks
|
|
1638
|
+
});
|
|
1639
|
+
}
|
|
1640
|
+
});
|
|
1641
|
+
}
|
|
1642
|
+
if (block2.type === "section_tool" && isPlainRecord(data.content) && Array.isArray(data.content.blocks)) {
|
|
1643
|
+
containers.push({
|
|
1644
|
+
path: blockPath.concat(["data", "content", "blocks"]),
|
|
1645
|
+
blocks: data.content.blocks
|
|
1646
|
+
});
|
|
1647
|
+
}
|
|
1648
|
+
if (block2.type === "tabs" && Array.isArray(data.tabs)) {
|
|
1649
|
+
data.tabs.forEach((tab, tabIndex) => {
|
|
1650
|
+
if (isPlainRecord(tab) && isPlainRecord(tab.content) && Array.isArray(tab.content.blocks)) {
|
|
1651
|
+
containers.push({
|
|
1652
|
+
path: blockPath.concat(["data", "tabs", tabIndex, "content", "blocks"]),
|
|
1653
|
+
blocks: tab.content.blocks
|
|
1654
|
+
});
|
|
1655
|
+
}
|
|
1656
|
+
});
|
|
1657
|
+
}
|
|
1658
|
+
if (block2.type === "slider" && Array.isArray(data.slides)) {
|
|
1659
|
+
data.slides.forEach((slide, slideIndex) => {
|
|
1660
|
+
if (isPlainRecord(slide) && isPlainRecord(slide.content) && Array.isArray(slide.content.blocks)) {
|
|
1661
|
+
containers.push({
|
|
1662
|
+
path: blockPath.concat(["data", "slides", slideIndex, "content", "blocks"]),
|
|
1663
|
+
blocks: slide.content.blocks
|
|
1664
|
+
});
|
|
1665
|
+
}
|
|
1666
|
+
});
|
|
1667
|
+
}
|
|
1668
|
+
return containers;
|
|
1669
|
+
};
|
|
1670
|
+
var validateContainerShape = (block2, path, errors) => {
|
|
1671
|
+
const data = isPlainRecord(block2.data) ? block2.data : null;
|
|
1672
|
+
if (!data)
|
|
1673
|
+
return;
|
|
1674
|
+
if (block2.type === "columns") {
|
|
1675
|
+
if (!Array.isArray(data.cols)) {
|
|
1676
|
+
errors.push(`${path}/data/cols must be an array`);
|
|
1677
|
+
return;
|
|
1678
|
+
}
|
|
1679
|
+
data.cols.forEach((column, index) => {
|
|
1680
|
+
if (!isPlainRecord(column) || !Array.isArray(column.blocks)) {
|
|
1681
|
+
errors.push(`${path}/data/cols/${index}/blocks must be an array`);
|
|
1682
|
+
}
|
|
1683
|
+
});
|
|
1684
|
+
}
|
|
1685
|
+
if (block2.type === "accordion_tool" || block2.type === "vertical_accordion") {
|
|
1686
|
+
if (!Array.isArray(data.sections)) {
|
|
1687
|
+
errors.push(`${path}/data/sections must be an array`);
|
|
1688
|
+
return;
|
|
1689
|
+
}
|
|
1690
|
+
data.sections.forEach((section, index) => {
|
|
1691
|
+
if (!isPlainRecord(section) || !isPlainRecord(section.content) || !Array.isArray(section.content.blocks)) {
|
|
1692
|
+
errors.push(`${path}/data/sections/${index}/content/blocks must be an array`);
|
|
1693
|
+
}
|
|
1694
|
+
});
|
|
1695
|
+
}
|
|
1696
|
+
if (block2.type === "section_tool" && (!isPlainRecord(data.content) || !Array.isArray(data.content.blocks))) {
|
|
1697
|
+
errors.push(`${path}/data/content/blocks must be an array`);
|
|
1698
|
+
}
|
|
1699
|
+
if (block2.type === "tabs") {
|
|
1700
|
+
if (!Array.isArray(data.tabs)) {
|
|
1701
|
+
errors.push(`${path}/data/tabs must be an array`);
|
|
1702
|
+
return;
|
|
1703
|
+
}
|
|
1704
|
+
data.tabs.forEach((tab, index) => {
|
|
1705
|
+
if (!isPlainRecord(tab) || !isPlainRecord(tab.content) || !Array.isArray(tab.content.blocks)) {
|
|
1706
|
+
errors.push(`${path}/data/tabs/${index}/content/blocks must be an array`);
|
|
1707
|
+
}
|
|
1708
|
+
});
|
|
1709
|
+
}
|
|
1710
|
+
if (block2.type === "slider") {
|
|
1711
|
+
if (!Array.isArray(data.slides)) {
|
|
1712
|
+
errors.push(`${path}/data/slides must be an array`);
|
|
1713
|
+
return;
|
|
1714
|
+
}
|
|
1715
|
+
data.slides.forEach((slide, index) => {
|
|
1716
|
+
if (!isPlainRecord(slide) || !isPlainRecord(slide.content) || !Array.isArray(slide.content.blocks)) {
|
|
1717
|
+
errors.push(`${path}/data/slides/${index}/content/blocks must be an array`);
|
|
1718
|
+
}
|
|
1719
|
+
});
|
|
1720
|
+
}
|
|
1721
|
+
};
|
|
1722
|
+
var normalizeInputBlock = (input, fallbackId = randomUUID2().replaceAll("-", "").slice(0, 12)) => {
|
|
1723
|
+
if (typeof input.type !== "string" || input.type.trim() === "") {
|
|
1724
|
+
throw new CliError("Block JSON must include a non-empty type", 2);
|
|
1725
|
+
}
|
|
1726
|
+
if (!isPlainRecord(input.data)) {
|
|
1727
|
+
throw new CliError("Block JSON must include a data object", 2);
|
|
1728
|
+
}
|
|
1729
|
+
return {
|
|
1730
|
+
...input,
|
|
1731
|
+
id: typeof input.id === "string" && input.id.trim() ? input.id : fallbackId,
|
|
1732
|
+
type: input.type,
|
|
1733
|
+
data: input.data
|
|
1734
|
+
};
|
|
1735
|
+
};
|
|
1736
|
+
var resolveTextFieldSegments = (block2, field) => {
|
|
1737
|
+
if (field)
|
|
1738
|
+
return parseFieldPath(field);
|
|
1739
|
+
if (isPlainRecord(block2.data)) {
|
|
1740
|
+
if (typeof block2.data.text === "string")
|
|
1741
|
+
return ["data", "text"];
|
|
1742
|
+
if (typeof block2.data.code === "string")
|
|
1743
|
+
return ["data", "code"];
|
|
1744
|
+
if (typeof block2.data.title === "string")
|
|
1745
|
+
return ["data", "title"];
|
|
1746
|
+
if (typeof block2.data.caption === "string")
|
|
1747
|
+
return ["data", "caption"];
|
|
1748
|
+
if (typeof block2.data.description === "string")
|
|
1749
|
+
return ["data", "description"];
|
|
1750
|
+
}
|
|
1751
|
+
throw new CliError("Could not infer a text field. Pass --field, for example --field data.text.", 2);
|
|
1752
|
+
};
|
|
1753
|
+
var parseFieldPath = (field) => {
|
|
1754
|
+
const trimmed = field.trim();
|
|
1755
|
+
if (!trimmed)
|
|
1756
|
+
throw new CliError("--field cannot be empty", 2);
|
|
1757
|
+
if (trimmed.startsWith("/"))
|
|
1758
|
+
return parseJsonPointer(trimmed);
|
|
1759
|
+
const rawSegments = trimmed.startsWith("data.") ? trimmed.split(".") : ["data", ...trimmed.split(".")];
|
|
1760
|
+
return rawSegments.map((segment) => {
|
|
1761
|
+
if (!segment)
|
|
1762
|
+
throw new CliError("--field contains an empty path segment", 2);
|
|
1763
|
+
return segment;
|
|
1764
|
+
});
|
|
1765
|
+
};
|
|
1766
|
+
var getBlockTextPreview = (block2) => {
|
|
1767
|
+
const data = isPlainRecord(block2.data) ? block2.data : {};
|
|
1768
|
+
const candidates = [data.text, data.title, data.description, data.code, data.caption];
|
|
1769
|
+
const text = candidates.find((value) => typeof value === "string");
|
|
1770
|
+
if (text)
|
|
1771
|
+
return text.replace(/\s+/g, " ").slice(0, 160);
|
|
1772
|
+
if (Array.isArray(data.items))
|
|
1773
|
+
return data.items.map((item) => String(item)).join(" ").slice(0, 160);
|
|
1774
|
+
return "";
|
|
1775
|
+
};
|
|
1776
|
+
var cloneEditorDocument = (content) => JSON.parse(JSON.stringify(content));
|
|
1777
|
+
var toJsonPointer = (segments) => `/${segments.map((segment) => String(segment).replaceAll("~", "~0").replaceAll("/", "~1")).join("/")}`;
|
|
1778
|
+
var parseJsonPointer = (pointer) => {
|
|
1779
|
+
if (pointer === "")
|
|
1780
|
+
return [];
|
|
1781
|
+
if (!pointer.startsWith("/"))
|
|
1782
|
+
throw new CliError(`Invalid JSON pointer: ${pointer}`, 2);
|
|
1783
|
+
return pointer.slice(1).split("/").map((segment) => segment.replaceAll("~1", "/").replaceAll("~0", "~"));
|
|
1784
|
+
};
|
|
1785
|
+
var getArrayAtPath = (root, path) => {
|
|
1786
|
+
const value = getObjectPathValue(root, path);
|
|
1787
|
+
if (!Array.isArray(value)) {
|
|
1788
|
+
throw new CliError(`${toJsonPointer(path)} is not an array`, 2);
|
|
1789
|
+
}
|
|
1790
|
+
return value;
|
|
1791
|
+
};
|
|
1792
|
+
var getObjectPathValue = (root, path) => {
|
|
1793
|
+
let cursor = root;
|
|
1794
|
+
for (const segment of path) {
|
|
1795
|
+
if (Array.isArray(cursor)) {
|
|
1796
|
+
const index = Number(segment);
|
|
1797
|
+
cursor = cursor[index];
|
|
1798
|
+
continue;
|
|
1799
|
+
}
|
|
1800
|
+
if (!isPlainRecord(cursor)) {
|
|
1801
|
+
return;
|
|
1802
|
+
}
|
|
1803
|
+
cursor = cursor[String(segment)];
|
|
1804
|
+
}
|
|
1805
|
+
return cursor;
|
|
1806
|
+
};
|
|
1807
|
+
var setObjectPathValue = (root, path, value) => {
|
|
1808
|
+
const target = getObjectPathParent(root, path);
|
|
1809
|
+
if (Array.isArray(target.parent)) {
|
|
1810
|
+
target.parent[Number(target.key)] = value;
|
|
1811
|
+
return;
|
|
1812
|
+
}
|
|
1813
|
+
target.parent[String(target.key)] = value;
|
|
1814
|
+
};
|
|
1815
|
+
var getObjectPathParent = (root, path) => {
|
|
1816
|
+
if (path.length === 0)
|
|
1817
|
+
throw new CliError("Cannot mutate document root in a block helper", 2);
|
|
1818
|
+
const parentPath = path.slice(0, -1);
|
|
1819
|
+
const key = path[path.length - 1];
|
|
1820
|
+
const parent = getObjectPathValue(root, parentPath);
|
|
1821
|
+
if (!isPlainRecord(parent) && !Array.isArray(parent)) {
|
|
1822
|
+
throw new CliError(`${toJsonPointer(parentPath)} is not mutable`, 2);
|
|
1823
|
+
}
|
|
1824
|
+
return { parent, key };
|
|
1825
|
+
};
|
|
1826
|
+
var isPlainRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
1827
|
+
|
|
876
1828
|
// ../../src/cli/commands.ts
|
|
877
1829
|
import { createReadStream } from "node:fs";
|
|
878
1830
|
import { cp, mkdir as mkdir2, readFile as readFile2, readdir, stat } from "node:fs/promises";
|
|
@@ -885,7 +1837,7 @@ var runCommand = async (ctx) => {
|
|
|
885
1837
|
return rootHelp();
|
|
886
1838
|
if (group === "schema")
|
|
887
1839
|
return schemaHelp();
|
|
888
|
-
if (group === "skills")
|
|
1840
|
+
if (group === "skills" && isBundledSkillsCommand(actionOrResource))
|
|
889
1841
|
return runSkillsCommand(actionOrResource, ctx);
|
|
890
1842
|
if (group === "auth")
|
|
891
1843
|
return runAuthCommand(actionOrResource, ctx);
|
|
@@ -954,7 +1906,7 @@ var runAuthCommand = async (action, ctx) => {
|
|
|
954
1906
|
}
|
|
955
1907
|
throw new CliError(`Unknown auth command "${action}"`, 2);
|
|
956
1908
|
};
|
|
957
|
-
var runResourceCommand = async (resource, action, maybeId,
|
|
1909
|
+
var runResourceCommand = async (resource, action, maybeId, rest, ctx) => {
|
|
958
1910
|
if (!action || action === "help")
|
|
959
1911
|
return resourceHelp(resource);
|
|
960
1912
|
if (resource.name === "internal-knowledge" && action === "sync-media") {
|
|
@@ -963,6 +1915,17 @@ var runResourceCommand = async (resource, action, maybeId, _rest, ctx) => {
|
|
|
963
1915
|
if (resource.name === "pages" && action === "backfill-field") {
|
|
964
1916
|
return runPagesBackfillFieldCommand(ctx);
|
|
965
1917
|
}
|
|
1918
|
+
if (resource.name === "pages" && (action === "block" || action === "blocks" && maybeId && isPageBlockAction(maybeId))) {
|
|
1919
|
+
return runPagesBlockCommand(maybeId, rest[0], ctx);
|
|
1920
|
+
}
|
|
1921
|
+
if (resource.name === "pages" && (action === "content-schema" || action === "block-schema" || action === "blocks")) {
|
|
1922
|
+
return pageContentSchema;
|
|
1923
|
+
}
|
|
1924
|
+
if (resource.name === "pages" && action === "patch-content") {
|
|
1925
|
+
if (!maybeId)
|
|
1926
|
+
throw new CliError("Missing pages id", 2);
|
|
1927
|
+
return runPagesPatchContentCommand(maybeId, ctx);
|
|
1928
|
+
}
|
|
966
1929
|
if (action === "list")
|
|
967
1930
|
return listResource(resource, ctx);
|
|
968
1931
|
if (action === "get") {
|
|
@@ -1012,14 +1975,15 @@ var listResource = async (resource, ctx) => {
|
|
|
1012
1975
|
return requestApi(`/api/cli/${resource.name}?${searchParams.toString()}`);
|
|
1013
1976
|
};
|
|
1014
1977
|
var createResource = async (resource, ctx) => {
|
|
1015
|
-
|
|
1978
|
+
requireWriteConfirmation(`${resource.label} creation writes data. Add --yes or use --dry-run.`, ctx);
|
|
1979
|
+
const data = await parseJsonObjectFlag(ctx, "data", "data-file");
|
|
1016
1980
|
const instanceId = getStringFlag(ctx, "instance") ?? defaultInstanceId(resource);
|
|
1017
1981
|
const instanceField = resource.instanceField === undefined ? "instanceId" : resource.instanceField;
|
|
1018
1982
|
if (instanceId && instanceField && !instanceField.includes(".") && data[instanceField] === undefined)
|
|
1019
1983
|
data[instanceField] = instanceId;
|
|
1020
1984
|
await applyUploadFileData(resource, data, ctx, { id: null, instanceId: getInstanceIdFromData(data) ?? instanceId });
|
|
1021
1985
|
if (Object.keys(data).length === 0)
|
|
1022
|
-
throw new CliError("Missing --data JSON", 2);
|
|
1986
|
+
throw new CliError("Missing --data or --data-file JSON", 2);
|
|
1023
1987
|
if (hasFlag(ctx, "dry-run"))
|
|
1024
1988
|
return { dryRun: true, resource: resource.name, data };
|
|
1025
1989
|
return requestApi(`/api/cli/${resource.name}`, {
|
|
@@ -1028,10 +1992,11 @@ var createResource = async (resource, ctx) => {
|
|
|
1028
1992
|
});
|
|
1029
1993
|
};
|
|
1030
1994
|
var updateResource = async (resource, id, ctx) => {
|
|
1031
|
-
|
|
1995
|
+
requireWriteConfirmation(`${resource.label} update writes data. Add --yes or use --dry-run.`, ctx);
|
|
1996
|
+
const data = await parseJsonObjectFlag(ctx, "data", "data-file");
|
|
1032
1997
|
await applyUploadFileData(resource, data, ctx, { id, instanceId: getStringFlag(ctx, "instance") ?? getInstanceIdFromData(data) });
|
|
1033
1998
|
if (Object.keys(data).length === 0)
|
|
1034
|
-
throw new CliError("Missing --data JSON", 2);
|
|
1999
|
+
throw new CliError("Missing --data or --data-file JSON", 2);
|
|
1035
2000
|
if (hasFlag(ctx, "dry-run"))
|
|
1036
2001
|
return { dryRun: true, resource: resource.name, id, data };
|
|
1037
2002
|
return requestApi(`/api/cli/${resource.name}/${id}`, {
|
|
@@ -1587,6 +2552,215 @@ var runPagesBackfillFieldCommand = async (ctx) => {
|
|
|
1587
2552
|
})
|
|
1588
2553
|
});
|
|
1589
2554
|
};
|
|
2555
|
+
var runPagesPatchContentCommand = async (pageId, ctx) => {
|
|
2556
|
+
requireWriteConfirmation("Page content patch writes content. Add --yes or use --dry-run.", ctx);
|
|
2557
|
+
const patch = await parseJsonArrayFlag(ctx, "patch", "patch-file");
|
|
2558
|
+
if (patch.length === 0)
|
|
2559
|
+
throw new CliError("Missing --patch or --patch-file JSON array", 2);
|
|
2560
|
+
return requestApi(`/api/cli/pages/${pageId}/patch-content`, {
|
|
2561
|
+
method: "POST",
|
|
2562
|
+
body: JSON.stringify({
|
|
2563
|
+
patch,
|
|
2564
|
+
reason: getStringFlag(ctx, "reason"),
|
|
2565
|
+
expectedUpdatedAt: getStringFlag(ctx, "expect-updated-at"),
|
|
2566
|
+
expectedCurrentVersion: getNumberFlag(ctx, "expect-version"),
|
|
2567
|
+
expectedContentSha1: getStringFlag(ctx, "expect-content-sha1"),
|
|
2568
|
+
dryRun: hasFlag(ctx, "dry-run")
|
|
2569
|
+
})
|
|
2570
|
+
});
|
|
2571
|
+
};
|
|
2572
|
+
var PAGE_BLOCK_ACTIONS = new Set(["list", "get", "replace-text", "replace", "insert-before", "insert-after", "remove", "help"]);
|
|
2573
|
+
var isPageBlockAction = (value) => typeof value === "string" && PAGE_BLOCK_ACTIONS.has(value);
|
|
2574
|
+
var runPagesBlockCommand = async (action, pageId, ctx) => {
|
|
2575
|
+
if (!action || action === "help")
|
|
2576
|
+
return pagesBlockHelp();
|
|
2577
|
+
if (!pageId)
|
|
2578
|
+
throw new CliError("Missing page id", 2);
|
|
2579
|
+
const page = await loadPageForBlockCommand(pageId);
|
|
2580
|
+
const content = parseEditorDocument(page.content);
|
|
2581
|
+
const pageSummary = summarizePageForBlockCommand(page, content);
|
|
2582
|
+
const includeContent = hasFlag(ctx, "include-content");
|
|
2583
|
+
if (action === "list") {
|
|
2584
|
+
return {
|
|
2585
|
+
page: pageSummary,
|
|
2586
|
+
fullContentRead: true,
|
|
2587
|
+
validation: validatePageContent(content),
|
|
2588
|
+
blocks: summarizeBlocks(content),
|
|
2589
|
+
...includeContent ? { content } : {}
|
|
2590
|
+
};
|
|
2591
|
+
}
|
|
2592
|
+
if (action === "get") {
|
|
2593
|
+
const blockId = requireStringFlag(ctx, "block-id");
|
|
2594
|
+
return {
|
|
2595
|
+
page: pageSummary,
|
|
2596
|
+
fullContentRead: true,
|
|
2597
|
+
validation: validatePageContent(content),
|
|
2598
|
+
block: getBlockById(content, blockId),
|
|
2599
|
+
...includeContent ? { content } : {}
|
|
2600
|
+
};
|
|
2601
|
+
}
|
|
2602
|
+
requireWriteConfirmation("Page block operation writes content. Add --yes or use --dry-run.", ctx);
|
|
2603
|
+
const plan = await buildPageBlockOperationPlan(action, content, ctx);
|
|
2604
|
+
const expectedContentSha1 = getStringFlag(ctx, "expect-content-sha1") ?? pageSummary.contentSha1;
|
|
2605
|
+
const expectedCurrentVersion = getNumberFlag(ctx, "expect-version") ?? pageSummary.currentVersion;
|
|
2606
|
+
const serverResult = await requestApi(`/api/cli/pages/${pageId}/patch-content`, {
|
|
2607
|
+
method: "POST",
|
|
2608
|
+
body: JSON.stringify({
|
|
2609
|
+
patch: plan.patch,
|
|
2610
|
+
reason: getStringFlag(ctx, "reason") ?? `CLI ${action} block ${plan.changedBlockId ?? ""}`.trim(),
|
|
2611
|
+
expectedUpdatedAt: getStringFlag(ctx, "expect-updated-at"),
|
|
2612
|
+
expectedCurrentVersion,
|
|
2613
|
+
expectedContentSha1,
|
|
2614
|
+
dryRun: hasFlag(ctx, "dry-run")
|
|
2615
|
+
})
|
|
2616
|
+
});
|
|
2617
|
+
if (hasFlag(ctx, "dry-run")) {
|
|
2618
|
+
return {
|
|
2619
|
+
success: true,
|
|
2620
|
+
dryRun: true,
|
|
2621
|
+
operation: {
|
|
2622
|
+
action,
|
|
2623
|
+
pageId,
|
|
2624
|
+
blockId: plan.changedBlockId ?? null,
|
|
2625
|
+
patchOperationCount: plan.patch.length
|
|
2626
|
+
},
|
|
2627
|
+
page: pageSummary,
|
|
2628
|
+
fullContentRead: true,
|
|
2629
|
+
block: summarizeBeforeAfterBlocks(plan.beforeContent, plan.afterContent, plan.changedBlockId),
|
|
2630
|
+
patch: plan.patch,
|
|
2631
|
+
validation: {
|
|
2632
|
+
before: plan.beforeValidation,
|
|
2633
|
+
after: plan.afterValidation
|
|
2634
|
+
},
|
|
2635
|
+
server: serverResult,
|
|
2636
|
+
...includeContent ? { predictedContent: plan.afterContent } : {}
|
|
2637
|
+
};
|
|
2638
|
+
}
|
|
2639
|
+
const afterPage = await loadPageForBlockCommand(pageId);
|
|
2640
|
+
const afterContent = parseEditorDocument(afterPage.content);
|
|
2641
|
+
const afterValidation = validatePageContent(afterContent);
|
|
2642
|
+
return {
|
|
2643
|
+
success: true,
|
|
2644
|
+
dryRun: false,
|
|
2645
|
+
operation: {
|
|
2646
|
+
action,
|
|
2647
|
+
pageId,
|
|
2648
|
+
blockId: plan.changedBlockId ?? null,
|
|
2649
|
+
patchOperationCount: plan.patch.length
|
|
2650
|
+
},
|
|
2651
|
+
page: summarizePageForBlockCommand(afterPage, afterContent),
|
|
2652
|
+
fullContentRead: true,
|
|
2653
|
+
block: plan.changedBlockId ? getBlockById(afterContent, plan.changedBlockId) : null,
|
|
2654
|
+
patch: plan.patch,
|
|
2655
|
+
validation: {
|
|
2656
|
+
before: plan.beforeValidation,
|
|
2657
|
+
predicted: plan.afterValidation,
|
|
2658
|
+
after: afterValidation
|
|
2659
|
+
},
|
|
2660
|
+
server: serverResult,
|
|
2661
|
+
...includeContent ? { content: afterContent } : {}
|
|
2662
|
+
};
|
|
2663
|
+
};
|
|
2664
|
+
var buildPageBlockOperationPlan = async (action, content, ctx) => {
|
|
2665
|
+
if (action === "replace-text") {
|
|
2666
|
+
const text = await getTextFlag(ctx, "text", "text-file");
|
|
2667
|
+
if (text === undefined)
|
|
2668
|
+
throw new CliError("Missing --text or --text-file", 2);
|
|
2669
|
+
const expectText = await getTextFlag(ctx, "expect-text", "expect-text-file");
|
|
2670
|
+
return planReplaceText(content, {
|
|
2671
|
+
blockId: requireStringFlag(ctx, "block-id"),
|
|
2672
|
+
text,
|
|
2673
|
+
field: getStringFlag(ctx, "field"),
|
|
2674
|
+
expectText,
|
|
2675
|
+
expectType: getStringFlag(ctx, "expect-type")
|
|
2676
|
+
});
|
|
2677
|
+
}
|
|
2678
|
+
if (action === "replace") {
|
|
2679
|
+
const block2 = await parseJsonObjectFlag(ctx, "block", "block-file");
|
|
2680
|
+
if (Object.keys(block2).length === 0)
|
|
2681
|
+
throw new CliError("Missing --block or --block-file JSON object", 2);
|
|
2682
|
+
return planReplaceBlock(content, {
|
|
2683
|
+
blockId: requireStringFlag(ctx, "block-id"),
|
|
2684
|
+
block: block2,
|
|
2685
|
+
expectType: getStringFlag(ctx, "expect-type"),
|
|
2686
|
+
allowIdChange: hasFlag(ctx, "allow-id-change")
|
|
2687
|
+
});
|
|
2688
|
+
}
|
|
2689
|
+
if (action === "insert-after") {
|
|
2690
|
+
const block2 = await parseJsonObjectFlag(ctx, "block", "block-file");
|
|
2691
|
+
if (Object.keys(block2).length === 0)
|
|
2692
|
+
throw new CliError("Missing --block or --block-file JSON object", 2);
|
|
2693
|
+
return planInsertAfterBlock(content, {
|
|
2694
|
+
anchorBlockId: requireStringFlag(ctx, "block-id"),
|
|
2695
|
+
block: block2
|
|
2696
|
+
});
|
|
2697
|
+
}
|
|
2698
|
+
if (action === "insert-before") {
|
|
2699
|
+
const block2 = await parseJsonObjectFlag(ctx, "block", "block-file");
|
|
2700
|
+
if (Object.keys(block2).length === 0)
|
|
2701
|
+
throw new CliError("Missing --block or --block-file JSON object", 2);
|
|
2702
|
+
return planInsertBeforeBlock(content, {
|
|
2703
|
+
anchorBlockId: requireStringFlag(ctx, "block-id"),
|
|
2704
|
+
block: block2
|
|
2705
|
+
});
|
|
2706
|
+
}
|
|
2707
|
+
if (action === "remove") {
|
|
2708
|
+
return planRemoveBlock(content, {
|
|
2709
|
+
blockId: requireStringFlag(ctx, "block-id"),
|
|
2710
|
+
expectType: getStringFlag(ctx, "expect-type")
|
|
2711
|
+
});
|
|
2712
|
+
}
|
|
2713
|
+
throw new CliError(`Unknown pages block command "${action}"`, 2);
|
|
2714
|
+
};
|
|
2715
|
+
var loadPageForBlockCommand = async (pageId) => {
|
|
2716
|
+
const page = await requestApi(`/api/cli/pages/${pageId}`);
|
|
2717
|
+
if (!isRecord(page) || typeof page.id !== "string" || typeof page.content !== "string") {
|
|
2718
|
+
throw new CliError("CLI page response did not include id and content", 1);
|
|
2719
|
+
}
|
|
2720
|
+
return {
|
|
2721
|
+
id: page.id,
|
|
2722
|
+
name: typeof page.name === "string" ? page.name : null,
|
|
2723
|
+
slug: typeof page.slug === "string" ? page.slug : null,
|
|
2724
|
+
language: typeof page.language === "string" ? page.language : null,
|
|
2725
|
+
instanceId: typeof page.instanceId === "string" ? page.instanceId : null,
|
|
2726
|
+
updatedAt: typeof page.updatedAt === "string" || page.updatedAt instanceof Date ? page.updatedAt : null,
|
|
2727
|
+
currentVersion: typeof page.currentVersion === "number" ? page.currentVersion : null,
|
|
2728
|
+
content: page.content
|
|
2729
|
+
};
|
|
2730
|
+
};
|
|
2731
|
+
var summarizePageForBlockCommand = (page, content) => ({
|
|
2732
|
+
id: page.id,
|
|
2733
|
+
name: page.name ?? null,
|
|
2734
|
+
slug: page.slug ?? null,
|
|
2735
|
+
language: page.language ?? null,
|
|
2736
|
+
instanceId: page.instanceId ?? null,
|
|
2737
|
+
updatedAt: page.updatedAt instanceof Date ? page.updatedAt.toISOString() : page.updatedAt ?? null,
|
|
2738
|
+
currentVersion: page.currentVersion ?? undefined,
|
|
2739
|
+
contentSha1: sha1String(page.content),
|
|
2740
|
+
blockCount: summarizeBlocks(content).length
|
|
2741
|
+
});
|
|
2742
|
+
var summarizeBeforeAfterBlocks = (beforeContent, afterContent, blockId) => {
|
|
2743
|
+
if (!blockId)
|
|
2744
|
+
return null;
|
|
2745
|
+
return {
|
|
2746
|
+
before: tryGetBlockById(beforeContent, blockId),
|
|
2747
|
+
after: tryGetBlockById(afterContent, blockId)
|
|
2748
|
+
};
|
|
2749
|
+
};
|
|
2750
|
+
var tryGetBlockById = (content, blockId) => {
|
|
2751
|
+
try {
|
|
2752
|
+
return getBlockById(content, blockId);
|
|
2753
|
+
} catch {
|
|
2754
|
+
return null;
|
|
2755
|
+
}
|
|
2756
|
+
};
|
|
2757
|
+
var requireStringFlag = (ctx, name) => {
|
|
2758
|
+
const value = getStringFlag(ctx, name);
|
|
2759
|
+
if (!value)
|
|
2760
|
+
throw new CliError(`Missing --${name}`, 2);
|
|
2761
|
+
return value;
|
|
2762
|
+
};
|
|
2763
|
+
var isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
1590
2764
|
var runEntitiesCommand = async (action, entityId, ctx) => {
|
|
1591
2765
|
if (!action || action === "help")
|
|
1592
2766
|
return entitiesHelp();
|
|
@@ -2469,7 +3643,13 @@ var GLOBAL_DEFAULT_RESOURCES = new Set([
|
|
|
2469
3643
|
"menus",
|
|
2470
3644
|
"menu-sections",
|
|
2471
3645
|
"workflows",
|
|
2472
|
-
"chromebook-exercises"
|
|
3646
|
+
"chromebook-exercises",
|
|
3647
|
+
"skill-applications",
|
|
3648
|
+
"skill-capabilities",
|
|
3649
|
+
"skill-clusters",
|
|
3650
|
+
"skills",
|
|
3651
|
+
"skill-sets",
|
|
3652
|
+
"skill-objectives"
|
|
2473
3653
|
]);
|
|
2474
3654
|
var defaultInstanceId = (resource) => GLOBAL_DEFAULT_RESOURCES.has(resource.name) ? "global" : undefined;
|
|
2475
3655
|
var skillsSourceRootDir = async () => {
|
|
@@ -2522,6 +3702,23 @@ var parseJsonObjectFlag = async (ctx, inlineName, fileName) => {
|
|
|
2522
3702
|
const text = await getTextFlag(ctx, inlineName, fileName);
|
|
2523
3703
|
return parseJsonObject(text, `--${inlineName}`);
|
|
2524
3704
|
};
|
|
3705
|
+
var parseJsonArrayFlag = async (ctx, inlineName, fileName) => {
|
|
3706
|
+
const text = await getTextFlag(ctx, inlineName, fileName);
|
|
3707
|
+
if (!text)
|
|
3708
|
+
return [];
|
|
3709
|
+
try {
|
|
3710
|
+
const parsed = JSON.parse(text);
|
|
3711
|
+
if (!Array.isArray(parsed)) {
|
|
3712
|
+
throw new CliError(`--${inlineName} must be a JSON array`, 2);
|
|
3713
|
+
}
|
|
3714
|
+
return parsed;
|
|
3715
|
+
} catch (error) {
|
|
3716
|
+
if (error instanceof CliError)
|
|
3717
|
+
throw error;
|
|
3718
|
+
throw new CliError(`Could not parse --${inlineName} as JSON`, 2);
|
|
3719
|
+
}
|
|
3720
|
+
};
|
|
3721
|
+
var isBundledSkillsCommand = (action) => !action || action === "help" || action === "install" || action === "path";
|
|
2525
3722
|
var getNumberFlag = (ctx, name) => {
|
|
2526
3723
|
const value = getStringFlag(ctx, name);
|
|
2527
3724
|
if (!value)
|
|
@@ -2544,6 +3741,9 @@ var rootHelp = () => ({
|
|
|
2544
3741
|
"gskills-admin auth whoami",
|
|
2545
3742
|
"gskills-admin pages list",
|
|
2546
3743
|
`gskills-admin pages update <id> --data '{"disabled":true}'`,
|
|
3744
|
+
"gskills-admin pages content-schema --output json",
|
|
3745
|
+
"gskills-admin pages patch-content <id> --patch-file ./page.patch.json --dry-run",
|
|
3746
|
+
"gskills-admin pages block replace-text <id> --block-id <blockId> --text-file ./block.txt --dry-run",
|
|
2547
3747
|
"gskills-admin pages delete <id> --force --confirm-delete pages:<id> # soft-disables only",
|
|
2548
3748
|
"gskills-admin sync run --target <instanceId> --only pages,quizzes --yes",
|
|
2549
3749
|
"gskills-admin sync repair-source-links --target <instanceId> --dry-run",
|
|
@@ -2610,6 +3810,15 @@ var schemaHelp = () => ({
|
|
|
2610
3810
|
{ name: "imported-sheets delete", args: ["id"], required: ["--instance", "--force", "--confirm-delete"], flags: ["--yes", "--dry-run"], writes: true, destructive: true },
|
|
2611
3811
|
{ name: "internal-knowledge sync-media", flags: ["--source", "--target", "--targets", "--all-targets", "--languages", "--since", "--updated-after", "--fields", "--mime", "--source-type", "--include-disabled", "--include-archived", "--no-cache", "--yes", "--dry-run"], writes: true },
|
|
2612
3812
|
{ name: "pages backfill-field", required: ["--field", "--target or --targets or --all-targets"], flags: ["--source", "--languages", "--no-cache", "--yes", "--dry-run"], writes: true },
|
|
3813
|
+
{ name: "pages content-schema", aliases: ["pages blocks", "pages block-schema"], writes: false },
|
|
3814
|
+
{ name: "pages patch-content", args: ["id"], required: ["--patch or --patch-file", "--yes or --dry-run"], flags: ["--reason", "--expect-updated-at", "--expect-version", "--expect-content-sha1"], writes: true },
|
|
3815
|
+
{ name: "pages block list", args: ["id"], flags: ["--include-content"], writes: false },
|
|
3816
|
+
{ name: "pages block get", args: ["id"], required: ["--block-id"], flags: ["--include-content"], writes: false },
|
|
3817
|
+
{ name: "pages block replace-text", args: ["id"], required: ["--block-id", "--text or --text-file", "--yes or --dry-run"], flags: ["--field", "--expect-text", "--expect-text-file", "--expect-type", "--expect-updated-at", "--expect-version", "--expect-content-sha1", "--reason", "--include-content"], writes: true },
|
|
3818
|
+
{ name: "pages block replace", args: ["id"], required: ["--block-id", "--block or --block-file", "--yes or --dry-run"], flags: ["--expect-type", "--allow-id-change", "--expect-updated-at", "--expect-version", "--expect-content-sha1", "--reason", "--include-content"], writes: true },
|
|
3819
|
+
{ name: "pages block insert-before", args: ["id"], required: ["--block-id", "--block or --block-file", "--yes or --dry-run"], flags: ["--expect-updated-at", "--expect-version", "--expect-content-sha1", "--reason", "--include-content"], writes: true },
|
|
3820
|
+
{ name: "pages block insert-after", args: ["id"], required: ["--block-id", "--block or --block-file", "--yes or --dry-run"], flags: ["--expect-updated-at", "--expect-version", "--expect-content-sha1", "--reason", "--include-content"], writes: true },
|
|
3821
|
+
{ name: "pages block remove", args: ["id"], required: ["--block-id", "--yes or --dry-run"], flags: ["--expect-type", "--expect-updated-at", "--expect-version", "--expect-content-sha1", "--reason", "--include-content"], writes: true },
|
|
2613
3822
|
{ name: "feedback inspect", args: ["feedbackId or URL"], writes: false },
|
|
2614
3823
|
{ name: "feedback translation-status", args: ["feedbackId or URL"], writes: false },
|
|
2615
3824
|
{ name: "feedback import-email", flags: ["--data", "--data-file", "--yes", "--dry-run"], writes: true },
|
|
@@ -2640,9 +3849,9 @@ var schemaHelp = () => ({
|
|
|
2640
3849
|
...resources.flatMap((resource) => [
|
|
2641
3850
|
{ name: `${resource.name} list`, writes: false, flags: ["--where", "--fields", "--take", "--skip", "--order-by", "--instance", "--dry-run"] },
|
|
2642
3851
|
{ name: `${resource.name} get`, args: ["id"], writes: false },
|
|
2643
|
-
{ name: `${resource.name} create`, flags: ["--data", "--instance", ...UPLOADABLE_RESOURCE_NAMES.has(resource.name) ? ["--upload-file", "--upload-name", "--mime-type"] : [], "--dry-run"], writes: true },
|
|
2644
|
-
{ name: `${resource.name} update`, args: ["id"], flags: ["--data", "--instance", ...UPLOADABLE_RESOURCE_NAMES.has(resource.name) ? ["--upload-file", "--upload-name", "--mime-type"] : [], "--dry-run"], writes: true },
|
|
2645
|
-
{ name: `${resource.name} delete`, args: ["id"], flags: ["--force", "--confirm-delete", "--dry-run"], writes: true, destructive: false, softOnly: true }
|
|
3852
|
+
{ name: `${resource.name} create`, flags: ["--data", "--data-file", "--instance", ...UPLOADABLE_RESOURCE_NAMES.has(resource.name) ? ["--upload-file", "--upload-name", "--mime-type"] : [], "--yes", "--dry-run"], writes: true },
|
|
3853
|
+
{ name: `${resource.name} update`, args: ["id"], flags: ["--data", "--data-file", "--instance", ...UPLOADABLE_RESOURCE_NAMES.has(resource.name) ? ["--upload-file", "--upload-name", "--mime-type"] : [], "--yes", "--dry-run"], writes: true },
|
|
3854
|
+
{ name: `${resource.name} delete`, args: ["id"], flags: ["--force", "--confirm-delete", "--yes", "--dry-run"], writes: true, destructive: false, softOnly: true }
|
|
2646
3855
|
])
|
|
2647
3856
|
],
|
|
2648
3857
|
resources: resources.map((resource) => ({
|
|
@@ -2930,13 +4139,16 @@ var resourceHelp = (resource) => ({
|
|
|
2930
4139
|
usage: [
|
|
2931
4140
|
`gskills-admin ${resource.name} list --instance global`,
|
|
2932
4141
|
`gskills-admin ${resource.name} get <id>`,
|
|
2933
|
-
`gskills-admin ${resource.name} create --data
|
|
2934
|
-
`gskills-admin ${resource.name} update <id> --data '{"disabled":true}'`,
|
|
2935
|
-
`gskills-admin ${resource.name} delete <id> --force --confirm-delete ${resource.name}:<id
|
|
4142
|
+
`gskills-admin ${resource.name} create --data-file ./payload.json --dry-run`,
|
|
4143
|
+
`gskills-admin ${resource.name} update <id> --data '{"disabled":true}' --yes`,
|
|
4144
|
+
`gskills-admin ${resource.name} delete <id> --force --confirm-delete ${resource.name}:<id> --yes`,
|
|
2936
4145
|
...resource.name === "internal-knowledge" ? [`gskills-admin ${resource.name} create --instance <instanceId> --upload-file ./video.mp4 --data '{"title":"Video","language":"fr","isActive":true}' --dry-run`] : [],
|
|
2937
4146
|
...resource.name === "resources" ? [`gskills-admin ${resource.name} create --instance <instanceId> --upload-file ./webinar.mp4 --data '{"title":"Webinar","type":"WEBINAR","language":"fr","isActive":true}' --dry-run`] : [],
|
|
2938
4147
|
...resource.name === "internal-knowledge" ? [`gskills-admin ${resource.name} sync-media --since today --languages fr --all-targets --dry-run`] : [],
|
|
2939
|
-
...resource.name === "pages" ? [`gskills-admin ${resource.name} backfill-field --field headerColor --all-targets --dry-run`] : []
|
|
4148
|
+
...resource.name === "pages" ? [`gskills-admin ${resource.name} backfill-field --field headerColor --all-targets --dry-run`] : [],
|
|
4149
|
+
...resource.name === "pages" ? [`gskills-admin ${resource.name} content-schema --output json`] : [],
|
|
4150
|
+
...resource.name === "pages" ? [`gskills-admin ${resource.name} patch-content <id> --patch-file ./page.patch.json --dry-run`] : [],
|
|
4151
|
+
...resource.name === "pages" ? [`gskills-admin ${resource.name} block replace-text <id> --block-id <blockId> --text-file ./block.txt --dry-run`] : []
|
|
2940
4152
|
],
|
|
2941
4153
|
defaultFields: resource.defaultFields,
|
|
2942
4154
|
cache: {
|
|
@@ -2944,7 +4156,50 @@ var resourceHelp = (resource) => ({
|
|
|
2944
4156
|
invalidate: resource.cacheScopes?.length ? `gskills-admin cache invalidate --instance <instanceId> --scope ${resource.cacheScopes[0]} --dry-run` : null,
|
|
2945
4157
|
note: resource.cacheScopes?.length ? "After create/update/soft-delete, deploy views may still show cached content. Dry-run and invalidate the relevant scope, then verify the visible page." : "No deploy-cache scope is listed for this raw resource. If the write affects visible content indirectly, use cache scopes to choose a broader invalidation."
|
|
2946
4158
|
},
|
|
2947
|
-
deleteWarning: "Delete is soft-only in the CLI. It writes disabled, archived, isActive=false, or active=false when the resource supports it."
|
|
4159
|
+
deleteWarning: "Delete is soft-only in the CLI. It writes disabled, archived, isActive=false, or active=false when the resource supports it.",
|
|
4160
|
+
...resource.name === "pages" ? {
|
|
4161
|
+
patchContent: {
|
|
4162
|
+
format: "RFC 6902 JSON Patch applied to the parsed EditorJS content object.",
|
|
4163
|
+
guardRails: ["dry-run preview", "test operations", "optional updatedAt/version/content SHA checks", "page history snapshot"],
|
|
4164
|
+
schema: "gskills-admin pages content-schema --output json",
|
|
4165
|
+
examplePatch: [
|
|
4166
|
+
{ op: "test", path: "/blocks/0/type", value: "paragraph" },
|
|
4167
|
+
{ op: "replace", path: "/blocks/0/data/text", value: "New paragraph text" }
|
|
4168
|
+
]
|
|
4169
|
+
},
|
|
4170
|
+
blockHelpers: {
|
|
4171
|
+
usage: [
|
|
4172
|
+
"gskills-admin pages block list <pageId>",
|
|
4173
|
+
"gskills-admin pages block get <pageId> --block-id <blockId>",
|
|
4174
|
+
"gskills-admin pages block replace-text <pageId> --block-id <blockId> --text-file ./block.txt --dry-run",
|
|
4175
|
+
"gskills-admin pages block replace <pageId> --block-id <blockId> --block-file ./block.json --dry-run",
|
|
4176
|
+
"gskills-admin pages block insert-before <pageId> --block-id <anchorBlockId> --block-file ./block.json --dry-run",
|
|
4177
|
+
"gskills-admin pages block insert-after <pageId> --block-id <anchorBlockId> --block-file ./block.json --dry-run",
|
|
4178
|
+
"gskills-admin pages block remove <pageId> --block-id <blockId> --dry-run"
|
|
4179
|
+
],
|
|
4180
|
+
note: "Block helpers read the full page content, find nested blocks by id, generate guarded JSON Patch, validate against pages content-schema, and use pages patch-content for the write."
|
|
4181
|
+
}
|
|
4182
|
+
} : {}
|
|
4183
|
+
});
|
|
4184
|
+
var pagesBlockHelp = () => ({
|
|
4185
|
+
usage: [
|
|
4186
|
+
"gskills-admin pages block list <pageId> --output json",
|
|
4187
|
+
"gskills-admin pages block get <pageId> --block-id <blockId> --output json",
|
|
4188
|
+
"gskills-admin pages block replace-text <pageId> --block-id <blockId> --text-file ./block.txt --dry-run --output json",
|
|
4189
|
+
"gskills-admin pages block replace <pageId> --block-id <blockId> --block-file ./block.json --dry-run --output json",
|
|
4190
|
+
"gskills-admin pages block insert-before <pageId> --block-id <anchorBlockId> --block-file ./block.json --dry-run --output json",
|
|
4191
|
+
"gskills-admin pages block insert-after <pageId> --block-id <anchorBlockId> --block-file ./block.json --dry-run --output json",
|
|
4192
|
+
"gskills-admin pages block remove <pageId> --block-id <blockId> --dry-run --output json"
|
|
4193
|
+
],
|
|
4194
|
+
safety: [
|
|
4195
|
+
"Reads the full page content before planning.",
|
|
4196
|
+
"Finds blocks recursively by stable block id.",
|
|
4197
|
+
"Generates JSON Patch with id, type, and old-value test guards.",
|
|
4198
|
+
"Validates the predicted full page against pages content-schema.",
|
|
4199
|
+
"Uses pages patch-content so history, vector refresh, cache, personalization refresh, and admin logs still happen.",
|
|
4200
|
+
"After real writes, rereads the full page content and validates it again."
|
|
4201
|
+
],
|
|
4202
|
+
note: "Use --include-content only when the agent needs the full parsed content in the CLI output."
|
|
2948
4203
|
});
|
|
2949
4204
|
|
|
2950
4205
|
// ../../src/cli/gskills-admin.ts
|