@numericoach/gskills-admin-cli 0.1.25 → 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/dist/gskills-admin.js
CHANGED
|
@@ -186,6 +186,9 @@ var loginWithGSkills = async (input) => {
|
|
|
186
186
|
if (callback.state !== state) {
|
|
187
187
|
throw new CliError("GSkills auth state mismatch", 403);
|
|
188
188
|
}
|
|
189
|
+
if (!callback.code) {
|
|
190
|
+
throw new CliError("GSkills CLI login callback did not include an auth code", 403);
|
|
191
|
+
}
|
|
189
192
|
const tokenResponse = await fetch(new URL("/api/cli/auth/token", baseUrl), {
|
|
190
193
|
method: "POST",
|
|
191
194
|
headers: {
|
|
@@ -214,6 +217,36 @@ var loginWithGSkills = async (input) => {
|
|
|
214
217
|
user: payload.user
|
|
215
218
|
};
|
|
216
219
|
};
|
|
220
|
+
var waitForGoogleSheetsOAuth = async (input) => {
|
|
221
|
+
const baseUrl = normalizeBaseUrl(input.baseUrl);
|
|
222
|
+
const host = input.host ?? "127.0.0.1";
|
|
223
|
+
const state = randomUUID();
|
|
224
|
+
const callback = await waitForLocalCallback(host, input.port ?? 0, async (redirectUri) => {
|
|
225
|
+
const startUrl = new URL("/api/cli/imported-sheets/oauth/start", baseUrl);
|
|
226
|
+
startUrl.searchParams.set("redirect_uri", redirectUri);
|
|
227
|
+
startUrl.searchParams.set("state", state);
|
|
228
|
+
startUrl.searchParams.set("instanceId", input.instanceId);
|
|
229
|
+
startUrl.searchParams.set("lang", input.lang ?? "fr");
|
|
230
|
+
if (input.ownerEmail)
|
|
231
|
+
startUrl.searchParams.set("ownerEmail", input.ownerEmail);
|
|
232
|
+
const opened = await openUrl(startUrl.toString());
|
|
233
|
+
if (opened) {
|
|
234
|
+
process.stderr.write(`Opened ${startUrl.toString()}
|
|
235
|
+
`);
|
|
236
|
+
}
|
|
237
|
+
}, {
|
|
238
|
+
timeoutMs: input.timeoutMs,
|
|
239
|
+
successMessage: "Google Sheets access connected. You can go back to Codex now.",
|
|
240
|
+
errorPrefix: "Google Sheets OAuth failed"
|
|
241
|
+
});
|
|
242
|
+
if (callback.state !== state) {
|
|
243
|
+
throw new CliError("Google Sheets OAuth state mismatch", 403);
|
|
244
|
+
}
|
|
245
|
+
return {
|
|
246
|
+
connected: true,
|
|
247
|
+
userEmail: callback.userEmail
|
|
248
|
+
};
|
|
249
|
+
};
|
|
217
250
|
var getApiSession = async () => {
|
|
218
251
|
const session = await readSession();
|
|
219
252
|
if (!session) {
|
|
@@ -235,32 +268,42 @@ var whoami = async () => {
|
|
|
235
268
|
}
|
|
236
269
|
return payload;
|
|
237
270
|
};
|
|
238
|
-
var waitForLocalCallback = async (host, port, onReady) => {
|
|
271
|
+
var waitForLocalCallback = async (host, port, onReady, options = {}) => {
|
|
239
272
|
return new Promise((resolve, reject) => {
|
|
273
|
+
const timeout = options.timeoutMs ? setTimeout(() => {
|
|
274
|
+
server.close();
|
|
275
|
+
reject(new CliError("Timed out waiting for browser OAuth callback", 408));
|
|
276
|
+
}, options.timeoutMs) : null;
|
|
277
|
+
const finish = (callback) => {
|
|
278
|
+
if (timeout)
|
|
279
|
+
clearTimeout(timeout);
|
|
280
|
+
server.close();
|
|
281
|
+
callback();
|
|
282
|
+
};
|
|
240
283
|
const server = createServer((request, response) => {
|
|
241
284
|
try {
|
|
242
285
|
const url = new URL(request.url ?? "/", `http://${host}`);
|
|
243
286
|
const code = url.searchParams.get("code");
|
|
244
287
|
const state = url.searchParams.get("state");
|
|
288
|
+
const status = url.searchParams.get("status");
|
|
289
|
+
const userEmail = url.searchParams.get("userEmail") ?? undefined;
|
|
245
290
|
const error = url.searchParams.get("error");
|
|
246
291
|
if (error) {
|
|
247
|
-
response.writeHead(403, { "content-type": "text/
|
|
248
|
-
response.end(
|
|
249
|
-
|
|
250
|
-
reject(new CliError(`GSkills CLI login failed: ${error}`, 403));
|
|
292
|
+
response.writeHead(403, { "content-type": "text/html; charset=utf-8" });
|
|
293
|
+
response.end(callbackHtml("Google Sheets access failed", `Error: ${escapeHtml(error)}`));
|
|
294
|
+
finish(() => reject(new CliError(`${options.errorPrefix ?? "GSkills CLI login failed"}: ${error}`, 403)));
|
|
251
295
|
return;
|
|
252
296
|
}
|
|
253
|
-
if (!
|
|
297
|
+
if (!state) {
|
|
254
298
|
response.writeHead(400, { "content-type": "text/plain" });
|
|
255
|
-
response.end("Missing
|
|
299
|
+
response.end("Missing callback state.");
|
|
256
300
|
return;
|
|
257
301
|
}
|
|
258
|
-
response.writeHead(200, { "content-type": "text/
|
|
259
|
-
response.end("GSkills CLI login complete. You can close this tab.");
|
|
260
|
-
|
|
261
|
-
resolve({ code, state });
|
|
302
|
+
response.writeHead(200, { "content-type": "text/html; charset=utf-8" });
|
|
303
|
+
response.end(callbackHtml("All good", options.successMessage ?? "GSkills CLI login complete. You can close this tab."));
|
|
304
|
+
finish(() => resolve({ code: code ?? undefined, state, status: status ?? undefined, userEmail }));
|
|
262
305
|
} catch (error) {
|
|
263
|
-
reject(error);
|
|
306
|
+
finish(() => reject(error));
|
|
264
307
|
}
|
|
265
308
|
});
|
|
266
309
|
server.on("error", reject);
|
|
@@ -279,6 +322,29 @@ var waitForLocalCallback = async (host, port, onReady) => {
|
|
|
279
322
|
});
|
|
280
323
|
});
|
|
281
324
|
};
|
|
325
|
+
var callbackHtml = (title, message) => `<!doctype html>
|
|
326
|
+
<html lang="en">
|
|
327
|
+
<head>
|
|
328
|
+
<meta charset="utf-8" />
|
|
329
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
330
|
+
<title>${escapeHtml(title)}</title>
|
|
331
|
+
<style>
|
|
332
|
+
body { margin: 0; min-height: 100vh; display: grid; place-items: center; font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: #f8fafc; color: #0f172a; }
|
|
333
|
+
main { width: min(520px, calc(100vw - 32px)); }
|
|
334
|
+
img { width: 40px; height: 40px; display: block; margin-bottom: 20px; }
|
|
335
|
+
h1 { margin: 0 0 10px; font-size: 24px; line-height: 1.2; }
|
|
336
|
+
p { margin: 0; color: #475569; font-size: 15px; line-height: 1.6; }
|
|
337
|
+
</style>
|
|
338
|
+
</head>
|
|
339
|
+
<body>
|
|
340
|
+
<main>
|
|
341
|
+
<img src="https://storage.googleapis.com/public-gskills/applications-icons/google-sheets-icon-2026.png" alt="" />
|
|
342
|
+
<h1>${escapeHtml(title)}</h1>
|
|
343
|
+
<p>${escapeHtml(message)}</p>
|
|
344
|
+
</main>
|
|
345
|
+
</body>
|
|
346
|
+
</html>`;
|
|
347
|
+
var escapeHtml = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
282
348
|
var normalizeBaseUrl = (value) => {
|
|
283
349
|
const url = new URL(value);
|
|
284
350
|
url.pathname = "";
|
|
@@ -324,7 +390,7 @@ var requestApi = async (path, init = {}) => {
|
|
|
324
390
|
});
|
|
325
391
|
const payload = await response.json().catch(() => null);
|
|
326
392
|
if (!response.ok) {
|
|
327
|
-
throw new CliError(payload?.error ?? `GSkills API request failed with ${response.status}`, response.status);
|
|
393
|
+
throw new CliError(payload?.error ?? `GSkills API request failed with ${response.status}`, response.status, payload?.details ?? undefined);
|
|
328
394
|
}
|
|
329
395
|
return payload;
|
|
330
396
|
};
|
|
@@ -479,6 +545,105 @@ var resources = [
|
|
|
479
545
|
aliases: ["alpha", "alpha-program", "alphas"],
|
|
480
546
|
defaultFields: ["id", "key", "name", "provider", "status", "updatedAt"]
|
|
481
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
|
+
},
|
|
482
647
|
{
|
|
483
648
|
name: "quizzes",
|
|
484
649
|
delegate: "quiz",
|
|
@@ -611,6 +776,16 @@ var resources = [
|
|
|
611
776
|
dangerousDelete: true,
|
|
612
777
|
cacheScopes: ["pages", "pages-knowledge"]
|
|
613
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
|
+
},
|
|
614
789
|
{
|
|
615
790
|
name: "imported-sheets",
|
|
616
791
|
delegate: "importedSheet",
|
|
@@ -807,6 +982,849 @@ var resourceHelpRows = () => resources.map((resource) => ({
|
|
|
807
982
|
cacheScopes: resource.cacheScopes?.join(", ") || "",
|
|
808
983
|
aliases: resource.aliases.join(", ")
|
|
809
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
|
+
|
|
810
1828
|
// ../../src/cli/commands.ts
|
|
811
1829
|
import { createReadStream } from "node:fs";
|
|
812
1830
|
import { cp, mkdir as mkdir2, readFile as readFile2, readdir, stat } from "node:fs/promises";
|
|
@@ -819,7 +1837,7 @@ var runCommand = async (ctx) => {
|
|
|
819
1837
|
return rootHelp();
|
|
820
1838
|
if (group === "schema")
|
|
821
1839
|
return schemaHelp();
|
|
822
|
-
if (group === "skills")
|
|
1840
|
+
if (group === "skills" && isBundledSkillsCommand(actionOrResource))
|
|
823
1841
|
return runSkillsCommand(actionOrResource, ctx);
|
|
824
1842
|
if (group === "auth")
|
|
825
1843
|
return runAuthCommand(actionOrResource, ctx);
|
|
@@ -888,7 +1906,7 @@ var runAuthCommand = async (action, ctx) => {
|
|
|
888
1906
|
}
|
|
889
1907
|
throw new CliError(`Unknown auth command "${action}"`, 2);
|
|
890
1908
|
};
|
|
891
|
-
var runResourceCommand = async (resource, action, maybeId,
|
|
1909
|
+
var runResourceCommand = async (resource, action, maybeId, rest, ctx) => {
|
|
892
1910
|
if (!action || action === "help")
|
|
893
1911
|
return resourceHelp(resource);
|
|
894
1912
|
if (resource.name === "internal-knowledge" && action === "sync-media") {
|
|
@@ -897,6 +1915,17 @@ var runResourceCommand = async (resource, action, maybeId, _rest, ctx) => {
|
|
|
897
1915
|
if (resource.name === "pages" && action === "backfill-field") {
|
|
898
1916
|
return runPagesBackfillFieldCommand(ctx);
|
|
899
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
|
+
}
|
|
900
1929
|
if (action === "list")
|
|
901
1930
|
return listResource(resource, ctx);
|
|
902
1931
|
if (action === "get") {
|
|
@@ -946,14 +1975,15 @@ var listResource = async (resource, ctx) => {
|
|
|
946
1975
|
return requestApi(`/api/cli/${resource.name}?${searchParams.toString()}`);
|
|
947
1976
|
};
|
|
948
1977
|
var createResource = async (resource, ctx) => {
|
|
949
|
-
|
|
1978
|
+
requireWriteConfirmation(`${resource.label} creation writes data. Add --yes or use --dry-run.`, ctx);
|
|
1979
|
+
const data = await parseJsonObjectFlag(ctx, "data", "data-file");
|
|
950
1980
|
const instanceId = getStringFlag(ctx, "instance") ?? defaultInstanceId(resource);
|
|
951
1981
|
const instanceField = resource.instanceField === undefined ? "instanceId" : resource.instanceField;
|
|
952
1982
|
if (instanceId && instanceField && !instanceField.includes(".") && data[instanceField] === undefined)
|
|
953
1983
|
data[instanceField] = instanceId;
|
|
954
1984
|
await applyUploadFileData(resource, data, ctx, { id: null, instanceId: getInstanceIdFromData(data) ?? instanceId });
|
|
955
1985
|
if (Object.keys(data).length === 0)
|
|
956
|
-
throw new CliError("Missing --data JSON", 2);
|
|
1986
|
+
throw new CliError("Missing --data or --data-file JSON", 2);
|
|
957
1987
|
if (hasFlag(ctx, "dry-run"))
|
|
958
1988
|
return { dryRun: true, resource: resource.name, data };
|
|
959
1989
|
return requestApi(`/api/cli/${resource.name}`, {
|
|
@@ -962,10 +1992,11 @@ var createResource = async (resource, ctx) => {
|
|
|
962
1992
|
});
|
|
963
1993
|
};
|
|
964
1994
|
var updateResource = async (resource, id, ctx) => {
|
|
965
|
-
|
|
1995
|
+
requireWriteConfirmation(`${resource.label} update writes data. Add --yes or use --dry-run.`, ctx);
|
|
1996
|
+
const data = await parseJsonObjectFlag(ctx, "data", "data-file");
|
|
966
1997
|
await applyUploadFileData(resource, data, ctx, { id, instanceId: getStringFlag(ctx, "instance") ?? getInstanceIdFromData(data) });
|
|
967
1998
|
if (Object.keys(data).length === 0)
|
|
968
|
-
throw new CliError("Missing --data JSON", 2);
|
|
1999
|
+
throw new CliError("Missing --data or --data-file JSON", 2);
|
|
969
2000
|
if (hasFlag(ctx, "dry-run"))
|
|
970
2001
|
return { dryRun: true, resource: resource.name, id, data };
|
|
971
2002
|
return requestApi(`/api/cli/${resource.name}/${id}`, {
|
|
@@ -1521,6 +2552,215 @@ var runPagesBackfillFieldCommand = async (ctx) => {
|
|
|
1521
2552
|
})
|
|
1522
2553
|
});
|
|
1523
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);
|
|
1524
2764
|
var runEntitiesCommand = async (action, entityId, ctx) => {
|
|
1525
2765
|
if (!action || action === "help")
|
|
1526
2766
|
return entitiesHelp();
|
|
@@ -1775,7 +3015,10 @@ var runImportedSheetsCommand = async (action, importedSheetId, ctx) => {
|
|
|
1775
3015
|
"attach-page",
|
|
1776
3016
|
"set-source",
|
|
1777
3017
|
"delete",
|
|
1778
|
-
"runs"
|
|
3018
|
+
"runs",
|
|
3019
|
+
"connect-google",
|
|
3020
|
+
"oauth",
|
|
3021
|
+
"reconnect-google"
|
|
1779
3022
|
].includes(action);
|
|
1780
3023
|
if (needsInstance && !instanceId)
|
|
1781
3024
|
throw new CliError("Missing --instance", 2);
|
|
@@ -1860,10 +3103,10 @@ var runImportedSheetsCommand = async (action, importedSheetId, ctx) => {
|
|
|
1860
3103
|
};
|
|
1861
3104
|
if (hasFlag(ctx, "dry-run"))
|
|
1862
3105
|
return { operation: "imported-sheets.set-source", importedSheetId, ...payload };
|
|
1863
|
-
return requestApi(`/api/cli/imported-sheets/${importedSheetId}/source`, {
|
|
3106
|
+
return requestImportedSheetApi(ctx, instanceId, "set-source", () => requestApi(`/api/cli/imported-sheets/${importedSheetId}/source`, {
|
|
1864
3107
|
method: "POST",
|
|
1865
3108
|
body: JSON.stringify(payload)
|
|
1866
|
-
});
|
|
3109
|
+
}));
|
|
1867
3110
|
}
|
|
1868
3111
|
if (action === "runs") {
|
|
1869
3112
|
const searchParams = importedSheetSearchParams(ctx);
|
|
@@ -1874,10 +3117,13 @@ var runImportedSheetsCommand = async (action, importedSheetId, ctx) => {
|
|
|
1874
3117
|
const sourceInput = getStringFlag(ctx, "source");
|
|
1875
3118
|
if (!sourceInput)
|
|
1876
3119
|
throw new CliError("Missing --source", 2);
|
|
1877
|
-
return requestApi("/api/cli/imported-sheets/resolve", {
|
|
3120
|
+
return requestImportedSheetApi(ctx, instanceId, "resolve", () => requestApi("/api/cli/imported-sheets/resolve", {
|
|
1878
3121
|
method: "POST",
|
|
1879
3122
|
body: JSON.stringify({ instanceId, sourceInput })
|
|
1880
|
-
});
|
|
3123
|
+
}));
|
|
3124
|
+
}
|
|
3125
|
+
if (action === "connect-google" || action === "oauth" || action === "reconnect-google") {
|
|
3126
|
+
return openImportedSheetGoogleOAuthHandoff(ctx, instanceId, getStringFlag(ctx, "owner-email") ?? getStringFlag(ctx, "account-email"));
|
|
1881
3127
|
}
|
|
1882
3128
|
if (["create", "update", "sync", "enable-locales", "translate", "retranslate", "replace-grid", "patch-cells", "vectorize", "repair-french", "delete"].includes(action)) {
|
|
1883
3129
|
requireWriteConfirmation("Imported sheet operation writes production data. Add --yes or use --dry-run.", ctx);
|
|
@@ -1886,27 +3132,34 @@ var runImportedSheetsCommand = async (action, importedSheetId, ctx) => {
|
|
|
1886
3132
|
const payload = await importedSheetCreatePayload(ctx);
|
|
1887
3133
|
if (hasFlag(ctx, "dry-run"))
|
|
1888
3134
|
return { dryRun: true, operation: "imported-sheets.create", payload };
|
|
1889
|
-
return requestApi("/api/cli/imported-sheets", {
|
|
3135
|
+
return requestImportedSheetApi(ctx, instanceId, "create", () => requestApi("/api/cli/imported-sheets", {
|
|
1890
3136
|
method: "POST",
|
|
1891
3137
|
body: JSON.stringify(payload)
|
|
1892
|
-
});
|
|
3138
|
+
}), importedSheetOwnerEmailFromPayload(payload));
|
|
1893
3139
|
}
|
|
1894
3140
|
if (!importedSheetId)
|
|
1895
3141
|
throw new CliError("Missing imported sheet id", 2);
|
|
1896
3142
|
if (action === "update") {
|
|
3143
|
+
const data = await parseJsonObjectFlag(ctx, "data", "data-file");
|
|
3144
|
+
const ownerUserId = getStringFlag(ctx, "owner-user") ?? getStringFlag(ctx, "owner-user-id");
|
|
3145
|
+
const ownerEmail = getStringFlag(ctx, "owner-email") ?? getStringFlag(ctx, "account-email");
|
|
3146
|
+
if (ownerUserId)
|
|
3147
|
+
data.ownerUserId = ownerUserId;
|
|
3148
|
+
if (ownerEmail)
|
|
3149
|
+
data.ownerEmail = ownerEmail;
|
|
1897
3150
|
const payload = {
|
|
1898
3151
|
instanceId,
|
|
1899
|
-
data
|
|
3152
|
+
data,
|
|
1900
3153
|
dryRun: hasFlag(ctx, "dry-run")
|
|
1901
3154
|
};
|
|
1902
3155
|
if (Object.keys(payload.data).length === 0)
|
|
1903
3156
|
throw new CliError("Missing --data or --data-file JSON", 2);
|
|
1904
3157
|
if (hasFlag(ctx, "dry-run"))
|
|
1905
3158
|
return { operation: "imported-sheets.update", importedSheetId, ...payload };
|
|
1906
|
-
return requestApi(`/api/cli/imported-sheets/${importedSheetId}`, {
|
|
3159
|
+
return requestImportedSheetApi(ctx, instanceId, "update", () => requestApi(`/api/cli/imported-sheets/${importedSheetId}`, {
|
|
1907
3160
|
method: "PATCH",
|
|
1908
3161
|
body: JSON.stringify(payload)
|
|
1909
|
-
});
|
|
3162
|
+
}), importedSheetOwnerEmailFromPayload(data));
|
|
1910
3163
|
}
|
|
1911
3164
|
if (action === "sync") {
|
|
1912
3165
|
const payload = {
|
|
@@ -1916,10 +3169,10 @@ var runImportedSheetsCommand = async (action, importedSheetId, ctx) => {
|
|
|
1916
3169
|
};
|
|
1917
3170
|
if (hasFlag(ctx, "dry-run"))
|
|
1918
3171
|
return { operation: "imported-sheets.sync", importedSheetId, ...payload };
|
|
1919
|
-
return requestApi(`/api/cli/imported-sheets/${importedSheetId}/sync`, {
|
|
3172
|
+
return requestImportedSheetApi(ctx, instanceId, "sync", () => requestApi(`/api/cli/imported-sheets/${importedSheetId}/sync`, {
|
|
1920
3173
|
method: "POST",
|
|
1921
3174
|
body: JSON.stringify(payload)
|
|
1922
|
-
});
|
|
3175
|
+
}));
|
|
1923
3176
|
}
|
|
1924
3177
|
if (action === "enable-locales" || action === "translate") {
|
|
1925
3178
|
const locales = splitCsv(getStringFlag(ctx, "locales") ?? getStringFlag(ctx, "languages") ?? getStringFlag(ctx, "to"));
|
|
@@ -1935,10 +3188,10 @@ var runImportedSheetsCommand = async (action, importedSheetId, ctx) => {
|
|
|
1935
3188
|
};
|
|
1936
3189
|
if (hasFlag(ctx, "dry-run"))
|
|
1937
3190
|
return { operation: `imported-sheets.${action}`, importedSheetId, ...payload };
|
|
1938
|
-
return requestApi(`/api/cli/imported-sheets/${importedSheetId}/translate`, {
|
|
3191
|
+
return requestImportedSheetApi(ctx, instanceId, action, () => requestApi(`/api/cli/imported-sheets/${importedSheetId}/translate`, {
|
|
1939
3192
|
method: "POST",
|
|
1940
3193
|
body: JSON.stringify(payload)
|
|
1941
|
-
});
|
|
3194
|
+
}));
|
|
1942
3195
|
}
|
|
1943
3196
|
if (action === "retranslate") {
|
|
1944
3197
|
const locales = splitCsv(getStringFlag(ctx, "locales") ?? getStringFlag(ctx, "languages") ?? getStringFlag(ctx, "to"));
|
|
@@ -1956,10 +3209,10 @@ var runImportedSheetsCommand = async (action, importedSheetId, ctx) => {
|
|
|
1956
3209
|
};
|
|
1957
3210
|
if (hasFlag(ctx, "dry-run"))
|
|
1958
3211
|
return { operation: "imported-sheets.retranslate", importedSheetId, ...payload };
|
|
1959
|
-
return requestApi(`/api/cli/imported-sheets/${importedSheetId}/retranslate`, {
|
|
3212
|
+
return requestImportedSheetApi(ctx, instanceId, "retranslate", () => requestApi(`/api/cli/imported-sheets/${importedSheetId}/retranslate`, {
|
|
1960
3213
|
method: "POST",
|
|
1961
3214
|
body: JSON.stringify(payload)
|
|
1962
|
-
});
|
|
3215
|
+
}));
|
|
1963
3216
|
}
|
|
1964
3217
|
if (action === "replace-grid") {
|
|
1965
3218
|
const locale = getStringFlag(ctx, "locale") ?? getStringFlag(ctx, "language");
|
|
@@ -1978,10 +3231,10 @@ var runImportedSheetsCommand = async (action, importedSheetId, ctx) => {
|
|
|
1978
3231
|
};
|
|
1979
3232
|
if (hasFlag(ctx, "dry-run"))
|
|
1980
3233
|
return { operation: "imported-sheets.replace-grid", importedSheetId, ...payload };
|
|
1981
|
-
return requestApi(`/api/cli/imported-sheets/${importedSheetId}/replace-grid`, {
|
|
3234
|
+
return requestImportedSheetApi(ctx, instanceId, "replace-grid", () => requestApi(`/api/cli/imported-sheets/${importedSheetId}/replace-grid`, {
|
|
1982
3235
|
method: "POST",
|
|
1983
3236
|
body: JSON.stringify(payload)
|
|
1984
|
-
});
|
|
3237
|
+
}));
|
|
1985
3238
|
}
|
|
1986
3239
|
if (action === "patch-cells") {
|
|
1987
3240
|
const data = await parseJsonObjectFlag(ctx, "data", "data-file");
|
|
@@ -1996,10 +3249,10 @@ var runImportedSheetsCommand = async (action, importedSheetId, ctx) => {
|
|
|
1996
3249
|
cacheScope: getStringFlag(ctx, "cache-scope") ?? data.cacheScope,
|
|
1997
3250
|
dryRun: hasFlag(ctx, "dry-run")
|
|
1998
3251
|
};
|
|
1999
|
-
return requestApi(`/api/cli/imported-sheets/${importedSheetId}/patch-cells`, {
|
|
3252
|
+
return requestImportedSheetApi(ctx, instanceId, "patch-cells", () => requestApi(`/api/cli/imported-sheets/${importedSheetId}/patch-cells`, {
|
|
2000
3253
|
method: "POST",
|
|
2001
3254
|
body: JSON.stringify(payload)
|
|
2002
|
-
});
|
|
3255
|
+
}));
|
|
2003
3256
|
}
|
|
2004
3257
|
if (action === "vectorize") {
|
|
2005
3258
|
const payload = {
|
|
@@ -2009,10 +3262,10 @@ var runImportedSheetsCommand = async (action, importedSheetId, ctx) => {
|
|
|
2009
3262
|
};
|
|
2010
3263
|
if (hasFlag(ctx, "dry-run"))
|
|
2011
3264
|
return { operation: "imported-sheets.vectorize", importedSheetId, ...payload };
|
|
2012
|
-
return requestApi(`/api/cli/imported-sheets/${importedSheetId}/vectorize`, {
|
|
3265
|
+
return requestImportedSheetApi(ctx, instanceId, "vectorize", () => requestApi(`/api/cli/imported-sheets/${importedSheetId}/vectorize`, {
|
|
2013
3266
|
method: "POST",
|
|
2014
3267
|
body: JSON.stringify(payload)
|
|
2015
|
-
});
|
|
3268
|
+
}));
|
|
2016
3269
|
}
|
|
2017
3270
|
if (action === "repair-french") {
|
|
2018
3271
|
const payload = {
|
|
@@ -2023,10 +3276,10 @@ var runImportedSheetsCommand = async (action, importedSheetId, ctx) => {
|
|
|
2023
3276
|
};
|
|
2024
3277
|
if (hasFlag(ctx, "dry-run"))
|
|
2025
3278
|
return { operation: "imported-sheets.repair-french", importedSheetId, ...payload };
|
|
2026
|
-
return requestApi(`/api/cli/imported-sheets/${importedSheetId}/repair-french`, {
|
|
3279
|
+
return requestImportedSheetApi(ctx, instanceId, "repair-french", () => requestApi(`/api/cli/imported-sheets/${importedSheetId}/repair-french`, {
|
|
2027
3280
|
method: "POST",
|
|
2028
3281
|
body: JSON.stringify(payload)
|
|
2029
|
-
});
|
|
3282
|
+
}));
|
|
2030
3283
|
}
|
|
2031
3284
|
if (action === "delete") {
|
|
2032
3285
|
const expectedConfirmation = `imported-sheets:${importedSheetId}`;
|
|
@@ -2247,9 +3500,82 @@ var importedSheetSearchParams = (ctx) => {
|
|
|
2247
3500
|
searchParams.set("pageSize", pageSize);
|
|
2248
3501
|
return searchParams;
|
|
2249
3502
|
};
|
|
3503
|
+
var requestImportedSheetApi = async (ctx, instanceId, operation, request, ownerEmail) => {
|
|
3504
|
+
try {
|
|
3505
|
+
return await request();
|
|
3506
|
+
} catch (error) {
|
|
3507
|
+
if (!isCliError(error) || !isGoogleSheetsPermissionError(error.message))
|
|
3508
|
+
throw error;
|
|
3509
|
+
const handoff = await runImportedSheetGoogleOAuth(ctx, instanceId, ownerEmail);
|
|
3510
|
+
if (handoff.waited) {
|
|
3511
|
+
return request();
|
|
3512
|
+
}
|
|
3513
|
+
throw new CliError(error.message, error.exitCode, {
|
|
3514
|
+
...error.details ?? {},
|
|
3515
|
+
googleOAuth: {
|
|
3516
|
+
...handoff,
|
|
3517
|
+
operation,
|
|
3518
|
+
retry: "Complete the browser Google flow, then run the same CLI command again."
|
|
3519
|
+
}
|
|
3520
|
+
});
|
|
3521
|
+
}
|
|
3522
|
+
};
|
|
3523
|
+
var runImportedSheetGoogleOAuth = async (ctx, instanceId, ownerEmail) => {
|
|
3524
|
+
if (hasFlag(ctx, "dry-run") || hasFlag(ctx, "no-open") || hasFlag(ctx, "no-oauth-wait")) {
|
|
3525
|
+
return openImportedSheetGoogleOAuthHandoff(ctx, instanceId, ownerEmail);
|
|
3526
|
+
}
|
|
3527
|
+
const session = await getApiSession();
|
|
3528
|
+
const timeoutMs = getNumberFlag(ctx, "oauth-timeout-ms") ?? 5 * 60 * 1000;
|
|
3529
|
+
const result = await waitForGoogleSheetsOAuth({
|
|
3530
|
+
baseUrl: session.baseUrl,
|
|
3531
|
+
instanceId,
|
|
3532
|
+
ownerEmail,
|
|
3533
|
+
lang: getStringFlag(ctx, "lang") ?? getStringFlag(ctx, "language") ?? "fr",
|
|
3534
|
+
timeoutMs
|
|
3535
|
+
});
|
|
3536
|
+
return {
|
|
3537
|
+
operation: "imported-sheets.connect-google",
|
|
3538
|
+
instanceId,
|
|
3539
|
+
opened: true,
|
|
3540
|
+
waited: true,
|
|
3541
|
+
connected: result.connected,
|
|
3542
|
+
userEmail: result.userEmail,
|
|
3543
|
+
note: "Google Sheets access was granted in the browser.",
|
|
3544
|
+
retry: "OAuth completed in the browser. Retrying the CLI operation now."
|
|
3545
|
+
};
|
|
3546
|
+
};
|
|
3547
|
+
var openImportedSheetGoogleOAuthHandoff = async (ctx, instanceId, ownerEmail) => {
|
|
3548
|
+
const url = await buildImportedSheetGoogleOAuthUrl(ctx, instanceId, ownerEmail);
|
|
3549
|
+
const opened = hasFlag(ctx, "dry-run") || hasFlag(ctx, "no-open") ? false : await openUrl(url);
|
|
3550
|
+
return {
|
|
3551
|
+
operation: "imported-sheets.connect-google",
|
|
3552
|
+
instanceId,
|
|
3553
|
+
url,
|
|
3554
|
+
opened,
|
|
3555
|
+
waited: false,
|
|
3556
|
+
note: "This opens the GSkills browser flow that asks Google for Sheets access. The browser user must be the owner account you pass to imported-sheets create/update."
|
|
3557
|
+
};
|
|
3558
|
+
};
|
|
3559
|
+
var buildImportedSheetGoogleOAuthUrl = async (ctx, instanceId, ownerEmail) => {
|
|
3560
|
+
const baseUrl = getStringFlag(ctx, "base-url") ?? process.env.GSKILLS_CLI_BASE_URL ?? (hasFlag(ctx, "dry-run") ? "https://g-skills.fr" : (await getApiSession()).baseUrl);
|
|
3561
|
+
const lang = getStringFlag(ctx, "lang") ?? getStringFlag(ctx, "language") ?? "fr";
|
|
3562
|
+
const reconnectUrl = new URL(`/${lang}/super-admin/${instanceId}/imported-sheets`, baseUrl);
|
|
3563
|
+
reconnectUrl.searchParams.set("googleSheetsOAuth", "1");
|
|
3564
|
+
if (ownerEmail)
|
|
3565
|
+
reconnectUrl.searchParams.set("ownerEmail", ownerEmail);
|
|
3566
|
+
return reconnectUrl.toString();
|
|
3567
|
+
};
|
|
3568
|
+
var importedSheetOwnerEmailFromPayload = (payload) => getObjectString(payload, "ownerEmail") ?? getObjectString(payload, "accountEmail") ?? getObjectString(payload, "googleAccountEmail");
|
|
3569
|
+
var isGoogleSheetsPermissionError = (message) => {
|
|
3570
|
+
const normalized = message.toLowerCase();
|
|
3571
|
+
return normalized.includes("google sheets permission is missing") || normalized.includes("google account not connected") || normalized.includes("grant sheets access");
|
|
3572
|
+
};
|
|
2250
3573
|
var importedSheetCreatePayload = async (ctx) => {
|
|
2251
3574
|
const data = await parseJsonObjectFlag(ctx, "data", "data-file");
|
|
2252
3575
|
if (Object.keys(data).length > 0) {
|
|
3576
|
+
if (!hasImportedSheetOwnerInput(data)) {
|
|
3577
|
+
throw new CliError("Imported sheet creation needs a Google owner account. Pass ownerEmail/ownerUserId in --data or use --owner-email / --owner-user.", 2);
|
|
3578
|
+
}
|
|
2253
3579
|
return {
|
|
2254
3580
|
...data,
|
|
2255
3581
|
dryRun: hasFlag(ctx, "dry-run")
|
|
@@ -2264,6 +3590,11 @@ var importedSheetCreatePayload = async (ctx) => {
|
|
|
2264
3590
|
throw new CliError("Missing --source", 2);
|
|
2265
3591
|
if (!tabName)
|
|
2266
3592
|
throw new CliError("Missing --tab", 2);
|
|
3593
|
+
const ownerUserId = getStringFlag(ctx, "owner-user") ?? getStringFlag(ctx, "owner-user-id");
|
|
3594
|
+
const ownerEmail = getStringFlag(ctx, "owner-email") ?? getStringFlag(ctx, "account-email");
|
|
3595
|
+
if (!ownerUserId && !ownerEmail) {
|
|
3596
|
+
throw new CliError("Imported sheet creation needs a Google owner account. Pass --owner-email or --owner-user.", 2);
|
|
3597
|
+
}
|
|
2267
3598
|
return {
|
|
2268
3599
|
instanceId,
|
|
2269
3600
|
displayName: getStringFlag(ctx, "display-name"),
|
|
@@ -2274,11 +3605,18 @@ var importedSheetCreatePayload = async (ctx) => {
|
|
|
2274
3605
|
sourceInput,
|
|
2275
3606
|
tabName
|
|
2276
3607
|
},
|
|
3608
|
+
ownerUserId,
|
|
3609
|
+
ownerEmail,
|
|
2277
3610
|
enableVectorization: hasFlag(ctx, "enable-vectorization"),
|
|
2278
3611
|
vectorHeaders: splitCsv(getStringFlag(ctx, "vector-headers") ?? getStringFlag(ctx, "vector-columns")),
|
|
2279
3612
|
dryRun: hasFlag(ctx, "dry-run")
|
|
2280
3613
|
};
|
|
2281
3614
|
};
|
|
3615
|
+
var hasImportedSheetOwnerInput = (data) => Boolean(getObjectString(data, "ownerUserId") || getObjectString(data, "ownerUser") || getObjectString(data, "accountUserId") || getObjectString(data, "ownerEmail") || getObjectString(data, "accountEmail") || getObjectString(data, "googleAccountEmail"));
|
|
3616
|
+
var getObjectString = (data, key) => {
|
|
3617
|
+
const value = data[key];
|
|
3618
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
3619
|
+
};
|
|
2282
3620
|
var splitCsv = (value) => value ? value.split(",").map((item) => item.trim()).filter(Boolean) : [];
|
|
2283
3621
|
var setWhereValue = (where, fieldPath, value) => {
|
|
2284
3622
|
const parts = fieldPath.split(".").map((part) => part.trim()).filter(Boolean);
|
|
@@ -2305,7 +3643,13 @@ var GLOBAL_DEFAULT_RESOURCES = new Set([
|
|
|
2305
3643
|
"menus",
|
|
2306
3644
|
"menu-sections",
|
|
2307
3645
|
"workflows",
|
|
2308
|
-
"chromebook-exercises"
|
|
3646
|
+
"chromebook-exercises",
|
|
3647
|
+
"skill-applications",
|
|
3648
|
+
"skill-capabilities",
|
|
3649
|
+
"skill-clusters",
|
|
3650
|
+
"skills",
|
|
3651
|
+
"skill-sets",
|
|
3652
|
+
"skill-objectives"
|
|
2309
3653
|
]);
|
|
2310
3654
|
var defaultInstanceId = (resource) => GLOBAL_DEFAULT_RESOURCES.has(resource.name) ? "global" : undefined;
|
|
2311
3655
|
var skillsSourceRootDir = async () => {
|
|
@@ -2358,6 +3702,23 @@ var parseJsonObjectFlag = async (ctx, inlineName, fileName) => {
|
|
|
2358
3702
|
const text = await getTextFlag(ctx, inlineName, fileName);
|
|
2359
3703
|
return parseJsonObject(text, `--${inlineName}`);
|
|
2360
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";
|
|
2361
3722
|
var getNumberFlag = (ctx, name) => {
|
|
2362
3723
|
const value = getStringFlag(ctx, name);
|
|
2363
3724
|
if (!value)
|
|
@@ -2380,11 +3741,14 @@ var rootHelp = () => ({
|
|
|
2380
3741
|
"gskills-admin auth whoami",
|
|
2381
3742
|
"gskills-admin pages list",
|
|
2382
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",
|
|
2383
3747
|
"gskills-admin pages delete <id> --force --confirm-delete pages:<id> # soft-disables only",
|
|
2384
3748
|
"gskills-admin sync run --target <instanceId> --only pages,quizzes --yes",
|
|
2385
3749
|
"gskills-admin sync repair-source-links --target <instanceId> --dry-run",
|
|
2386
3750
|
"gskills-admin translate pages <id> --to en,es --dry-run",
|
|
2387
|
-
"gskills-admin imported-sheets create --instance <id> --source <url> --tab <name> --locales fr,en --enable-vectorization --dry-run",
|
|
3751
|
+
"gskills-admin imported-sheets create --instance <id> --source <url> --tab <name> --default-locale en --locales fr,en --owner-email admin@example.com --enable-vectorization --dry-run",
|
|
2388
3752
|
`gskills-admin internal-knowledge create --instance <instanceId> --upload-file ./video.mp4 --data '{"title":"...","language":"fr"}' --yes`,
|
|
2389
3753
|
`gskills-admin resources create --instance <instanceId> --upload-file ./webinar.mp4 --data '{"title":"...","type":"WEBINAR","language":"fr"}' --yes`,
|
|
2390
3754
|
"gskills-admin internal-knowledge sync-media --since today --languages fr --all-targets --dry-run",
|
|
@@ -2429,9 +3793,10 @@ var schemaHelp = () => ({
|
|
|
2429
3793
|
{ name: "imported-sheets locales", args: ["id"], required: ["--instance"], writes: false },
|
|
2430
3794
|
{ name: "imported-sheets runs", args: ["id?"], required: ["--instance"], flags: ["--take"], writes: false },
|
|
2431
3795
|
{ name: "imported-sheets resolve", required: ["--instance", "--source"], writes: false },
|
|
2432
|
-
{ name: "imported-sheets
|
|
2433
|
-
{ name: "imported-sheets
|
|
2434
|
-
{ name: "imported-sheets
|
|
3796
|
+
{ name: "imported-sheets connect-google", required: ["--instance"], flags: ["--base-url", "--lang", "--owner-email", "--no-open", "--dry-run"], writes: false },
|
|
3797
|
+
{ name: "imported-sheets create", required: ["--instance", "--source", "--tab", "--owner-email or --owner-user"], flags: ["--display-name", "--locales", "--mode", "--default-locale", "--owner-email", "--owner-user", "--enable-vectorization", "--vector-headers", "--data", "--data-file", "--oauth-timeout-ms", "--no-oauth-wait", "--yes", "--dry-run"], writes: true },
|
|
3798
|
+
{ name: "imported-sheets update", args: ["id"], required: ["--instance", "--data or --data-file or --owner-email"], flags: ["--owner-email", "--owner-user", "--oauth-timeout-ms", "--no-oauth-wait", "--yes", "--dry-run"], writes: true },
|
|
3799
|
+
{ name: "imported-sheets sync", args: ["id"], required: ["--instance"], flags: ["--locales", "--oauth-timeout-ms", "--no-oauth-wait", "--yes", "--dry-run"], writes: true },
|
|
2435
3800
|
{ name: "imported-sheets enable-locales", args: ["id"], required: ["--instance", "--locales"], flags: ["--yes", "--dry-run"], writes: true },
|
|
2436
3801
|
{ name: "imported-sheets translate", args: ["id"], required: ["--instance", "--to"], flags: ["--yes", "--dry-run"], writes: true },
|
|
2437
3802
|
{ name: "imported-sheets retranslate", args: ["id"], required: ["--instance", "--to"], flags: ["--from", "--revectorize", "--yes", "--dry-run"], writes: true },
|
|
@@ -2445,6 +3810,15 @@ var schemaHelp = () => ({
|
|
|
2445
3810
|
{ name: "imported-sheets delete", args: ["id"], required: ["--instance", "--force", "--confirm-delete"], flags: ["--yes", "--dry-run"], writes: true, destructive: true },
|
|
2446
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 },
|
|
2447
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 },
|
|
2448
3822
|
{ name: "feedback inspect", args: ["feedbackId or URL"], writes: false },
|
|
2449
3823
|
{ name: "feedback translation-status", args: ["feedbackId or URL"], writes: false },
|
|
2450
3824
|
{ name: "feedback import-email", flags: ["--data", "--data-file", "--yes", "--dry-run"], writes: true },
|
|
@@ -2475,9 +3849,9 @@ var schemaHelp = () => ({
|
|
|
2475
3849
|
...resources.flatMap((resource) => [
|
|
2476
3850
|
{ name: `${resource.name} list`, writes: false, flags: ["--where", "--fields", "--take", "--skip", "--order-by", "--instance", "--dry-run"] },
|
|
2477
3851
|
{ name: `${resource.name} get`, args: ["id"], writes: false },
|
|
2478
|
-
{ name: `${resource.name} create`, flags: ["--data", "--instance", ...UPLOADABLE_RESOURCE_NAMES.has(resource.name) ? ["--upload-file", "--upload-name", "--mime-type"] : [], "--dry-run"], writes: true },
|
|
2479
|
-
{ 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 },
|
|
2480
|
-
{ 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 }
|
|
2481
3855
|
])
|
|
2482
3856
|
],
|
|
2483
3857
|
resources: resources.map((resource) => ({
|
|
@@ -2574,8 +3948,10 @@ var importedSheetsHelp = () => ({
|
|
|
2574
3948
|
usage: [
|
|
2575
3949
|
"gskills-admin imported-sheets list --instance <instanceId>",
|
|
2576
3950
|
"gskills-admin imported-sheets get <sheetId> --instance <instanceId> --locale en --page-size 100",
|
|
3951
|
+
"gskills-admin imported-sheets connect-google --instance <instanceId> --base-url https://g-skills.fr",
|
|
2577
3952
|
"gskills-admin imported-sheets resolve --instance <instanceId> --source <sheet-url>",
|
|
2578
|
-
"gskills-admin imported-sheets create --instance <instanceId> --source <sheet-url> --tab
|
|
3953
|
+
"gskills-admin imported-sheets create --instance <instanceId> --source <sheet-url> --tab EN --default-locale en --display-name 'Use cases' --locales fr,en --owner-email admin@example.com --enable-vectorization --vector-headers 'Use case,Description,Full prompt' --dry-run",
|
|
3954
|
+
"gskills-admin imported-sheets update <sheetId> --instance <instanceId> --owner-email admin@example.com --dry-run",
|
|
2579
3955
|
"gskills-admin imported-sheets update <sheetId> --instance <instanceId> --data-file ./settings.json --dry-run",
|
|
2580
3956
|
"gskills-admin imported-sheets sync <sheetId> --instance <instanceId> --dry-run",
|
|
2581
3957
|
"gskills-admin imported-sheets translate <sheetId> --instance <instanceId> --to en,es --dry-run",
|
|
@@ -2590,6 +3966,7 @@ var importedSheetsHelp = () => ({
|
|
|
2590
3966
|
"gskills-admin imported-sheets delete <sheetId> --instance <instanceId> --force --confirm-delete imported-sheets:<sheetId> --dry-run"
|
|
2591
3967
|
],
|
|
2592
3968
|
writes: "create, update, sync, translate, retranslate, replace-grid, patch-cells, vectorize, repair-french, copy-to, attach-page, set-source and delete require --yes or --dry-run.",
|
|
3969
|
+
oauth: "When Google Sheets access is missing, create/update/sync open the browser OAuth flow, wait for completion, then retry automatically. Use --no-oauth-wait to only print/open the reconnect URL.",
|
|
2593
3970
|
patchCellsDataShape: {
|
|
2594
3971
|
patches: [
|
|
2595
3972
|
{
|
|
@@ -2612,12 +3989,14 @@ var importedSheetsHelp = () => ({
|
|
|
2612
3989
|
enabledLocales: ["fr", "en", "es"],
|
|
2613
3990
|
multilangMode: "AI_TRANSLATION",
|
|
2614
3991
|
defaultLocaleSource: { locale: "fr", sourceInput: "https://docs.google.com/spreadsheets/d/...", tabName: "FR" },
|
|
2615
|
-
localeSources: [{ locale: "
|
|
3992
|
+
localeSources: [{ locale: "fr", sourceInput: "https://docs.google.com/spreadsheets/d/...", tabName: "FR" }],
|
|
3993
|
+
ownerEmail: "admin@example.com",
|
|
2616
3994
|
enableVectorization: true,
|
|
2617
3995
|
vectorHeaders: ["Titre", "Description", "Prompt"]
|
|
2618
3996
|
},
|
|
2619
3997
|
updateDataShape: {
|
|
2620
3998
|
displayName: "Cas d'usage Gemini",
|
|
3999
|
+
ownerEmail: "admin@example.com",
|
|
2621
4000
|
viewMode: "LINE",
|
|
2622
4001
|
enableVectorization: true,
|
|
2623
4002
|
columns: [{ id: "column_id", isVisible: true, includeInVectorization: true, displayType: "TITLE", showLabel: false, displayOrder: 0 }],
|
|
@@ -2760,13 +4139,16 @@ var resourceHelp = (resource) => ({
|
|
|
2760
4139
|
usage: [
|
|
2761
4140
|
`gskills-admin ${resource.name} list --instance global`,
|
|
2762
4141
|
`gskills-admin ${resource.name} get <id>`,
|
|
2763
|
-
`gskills-admin ${resource.name} create --data
|
|
2764
|
-
`gskills-admin ${resource.name} update <id> --data '{"disabled":true}'`,
|
|
2765
|
-
`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`,
|
|
2766
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`] : [],
|
|
2767
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`] : [],
|
|
2768
4147
|
...resource.name === "internal-knowledge" ? [`gskills-admin ${resource.name} sync-media --since today --languages fr --all-targets --dry-run`] : [],
|
|
2769
|
-
...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`] : []
|
|
2770
4152
|
],
|
|
2771
4153
|
defaultFields: resource.defaultFields,
|
|
2772
4154
|
cache: {
|
|
@@ -2774,7 +4156,50 @@ var resourceHelp = (resource) => ({
|
|
|
2774
4156
|
invalidate: resource.cacheScopes?.length ? `gskills-admin cache invalidate --instance <instanceId> --scope ${resource.cacheScopes[0]} --dry-run` : null,
|
|
2775
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."
|
|
2776
4158
|
},
|
|
2777
|
-
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."
|
|
2778
4203
|
});
|
|
2779
4204
|
|
|
2780
4205
|
// ../../src/cli/gskills-admin.ts
|