@numericoach/gskills-admin-cli 0.1.24 → 0.1.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/gskills-admin.js +167 -4
- package/package.json +1 -1
- package/skills/gskills-admin-cli/SKILL.md +11 -0
package/README.md
CHANGED
|
@@ -50,6 +50,17 @@ gskills-admin topics help --output json
|
|
|
50
50
|
|
|
51
51
|
Use the listed `cache.scopes` with `gskills-admin cache invalidate` after create, update, or soft-delete when the end-user view must reflect the change immediately.
|
|
52
52
|
|
|
53
|
+
Large local videos can be uploaded directly to GSkills storage before creating or updating internal knowledge and resources. The CLI asks the app for a signed upload URL, streams the local file directly to GCS, then writes the normal row with the returned URL. Use `--instance` for client-specific content.
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
gskills-admin internal-knowledge create --instance dev-numericoach --upload-file ./capsule.mp4 --data '{"title":"Capsule test","language":"fr","isActive":true,"isAIAllowed":false}' --dry-run --output json
|
|
57
|
+
gskills-admin internal-knowledge create --instance dev-numericoach --upload-file ./capsule.mp4 --data '{"title":"Capsule test","language":"fr","isActive":true,"isAIAllowed":false}' --output json
|
|
58
|
+
gskills-admin resources create --instance dev-numericoach --upload-file ./webinar.mp4 --data '{"title":"Webinar test","type":"WEBINAR","language":"fr","isActive":true}' --dry-run --output json
|
|
59
|
+
gskills-admin resources update <resourceId> --upload-file ./webinar-v2.mp4 --data '{}' --output json
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Use `--mime-type` when the extension is ambiguous, and `--upload-name` when the stored file name needs a cleaner label.
|
|
63
|
+
|
|
53
64
|
AI translation is available for content that has native AI translation in the editor:
|
|
54
65
|
|
|
55
66
|
Warning: `translate pages` rewrites each translated page from the source page. It is not a diff update. Recreating translated pages this way can lose activity-specific fields, quiz ids, embedded ids, or future custom block data if the translator does not preserve them. Prefer the app diff update flow for pages with activities or custom blocks.
|
package/dist/gskills-admin.js
CHANGED
|
@@ -808,8 +808,10 @@ var resourceHelpRows = () => resources.map((resource) => ({
|
|
|
808
808
|
aliases: resource.aliases.join(", ")
|
|
809
809
|
}));
|
|
810
810
|
// ../../src/cli/commands.ts
|
|
811
|
+
import { createReadStream } from "node:fs";
|
|
811
812
|
import { cp, mkdir as mkdir2, readFile as readFile2, readdir, stat } from "node:fs/promises";
|
|
812
|
-
import { dirname as dirname2, join as join2 } from "node:path";
|
|
813
|
+
import { basename, dirname as dirname2, extname, join as join2, resolve } from "node:path";
|
|
814
|
+
import { homedir as homedir2 } from "node:os";
|
|
813
815
|
import { fileURLToPath } from "node:url";
|
|
814
816
|
var runCommand = async (ctx) => {
|
|
815
817
|
const [group, actionOrResource, maybeAction, ...rest] = ctx.args;
|
|
@@ -821,7 +823,7 @@ var runCommand = async (ctx) => {
|
|
|
821
823
|
return runSkillsCommand(actionOrResource, ctx);
|
|
822
824
|
if (group === "auth")
|
|
823
825
|
return runAuthCommand(actionOrResource, ctx);
|
|
824
|
-
if (group === "resources")
|
|
826
|
+
if (group === "resources" && !actionOrResource)
|
|
825
827
|
return resourceHelpRows();
|
|
826
828
|
if (group === "sync")
|
|
827
829
|
return runSyncCommand(actionOrResource, ctx);
|
|
@@ -949,6 +951,7 @@ var createResource = async (resource, ctx) => {
|
|
|
949
951
|
const instanceField = resource.instanceField === undefined ? "instanceId" : resource.instanceField;
|
|
950
952
|
if (instanceId && instanceField && !instanceField.includes(".") && data[instanceField] === undefined)
|
|
951
953
|
data[instanceField] = instanceId;
|
|
954
|
+
await applyUploadFileData(resource, data, ctx, { id: null, instanceId: getInstanceIdFromData(data) ?? instanceId });
|
|
952
955
|
if (Object.keys(data).length === 0)
|
|
953
956
|
throw new CliError("Missing --data JSON", 2);
|
|
954
957
|
if (hasFlag(ctx, "dry-run"))
|
|
@@ -960,6 +963,7 @@ var createResource = async (resource, ctx) => {
|
|
|
960
963
|
};
|
|
961
964
|
var updateResource = async (resource, id, ctx) => {
|
|
962
965
|
const data = parseJsonObject(getStringFlag(ctx, "data"), "--data");
|
|
966
|
+
await applyUploadFileData(resource, data, ctx, { id, instanceId: getStringFlag(ctx, "instance") ?? getInstanceIdFromData(data) });
|
|
963
967
|
if (Object.keys(data).length === 0)
|
|
964
968
|
throw new CliError("Missing --data JSON", 2);
|
|
965
969
|
if (hasFlag(ctx, "dry-run"))
|
|
@@ -969,6 +973,161 @@ var updateResource = async (resource, id, ctx) => {
|
|
|
969
973
|
body: JSON.stringify({ data })
|
|
970
974
|
});
|
|
971
975
|
};
|
|
976
|
+
var UPLOADABLE_RESOURCE_NAMES = new Set(["internal-knowledge", "resources"]);
|
|
977
|
+
var applyUploadFileData = async (resource, data, ctx, target) => {
|
|
978
|
+
const uploadFilePath = getStringFlag(ctx, "upload-file");
|
|
979
|
+
if (!uploadFilePath)
|
|
980
|
+
return;
|
|
981
|
+
if (!UPLOADABLE_RESOURCE_NAMES.has(resource.name)) {
|
|
982
|
+
throw new CliError(`--upload-file is not supported for ${resource.name}`, 2);
|
|
983
|
+
}
|
|
984
|
+
const upload = await prepareDirectUpload(resource, uploadFilePath, ctx, target);
|
|
985
|
+
if (hasFlag(ctx, "dry-run")) {
|
|
986
|
+
data.__upload = upload;
|
|
987
|
+
applyUploadedMediaData(resource, data, upload);
|
|
988
|
+
return;
|
|
989
|
+
}
|
|
990
|
+
if (!isPreparedSignedUpload(upload)) {
|
|
991
|
+
throw new CliError("Signed upload response was invalid", 1);
|
|
992
|
+
}
|
|
993
|
+
if (!target.id) {
|
|
994
|
+
setUploadInstanceData(resource, data, upload.instanceId);
|
|
995
|
+
}
|
|
996
|
+
await uploadToSignedUrl(upload.signedUrl, upload.filePath, upload.contentType, upload.size);
|
|
997
|
+
applyUploadedMediaData(resource, data, upload);
|
|
998
|
+
};
|
|
999
|
+
var prepareDirectUpload = async (resource, uploadFilePath, ctx, target) => {
|
|
1000
|
+
const filePath = resolveLocalPath(uploadFilePath);
|
|
1001
|
+
const fileStat = await stat(filePath).catch(() => null);
|
|
1002
|
+
if (!fileStat?.isFile()) {
|
|
1003
|
+
throw new CliError(`Upload file not found: ${uploadFilePath}`, 2);
|
|
1004
|
+
}
|
|
1005
|
+
const contentType = getStringFlag(ctx, "mime-type") ?? inferMimeType(filePath);
|
|
1006
|
+
const instanceId = await resolveUploadInstanceId(resource, target);
|
|
1007
|
+
const fileName = getStringFlag(ctx, "upload-name") ?? basename(filePath);
|
|
1008
|
+
if (hasFlag(ctx, "dry-run")) {
|
|
1009
|
+
return {
|
|
1010
|
+
filePath,
|
|
1011
|
+
fileName,
|
|
1012
|
+
contentType,
|
|
1013
|
+
size: fileStat.size,
|
|
1014
|
+
instanceId,
|
|
1015
|
+
directUpload: true
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
1018
|
+
const result = await requestApi("/api/cli/uploads/signed-url", {
|
|
1019
|
+
method: "POST",
|
|
1020
|
+
body: JSON.stringify({
|
|
1021
|
+
resource: resource.name,
|
|
1022
|
+
instanceId,
|
|
1023
|
+
fileName,
|
|
1024
|
+
contentType
|
|
1025
|
+
})
|
|
1026
|
+
});
|
|
1027
|
+
if (!isSignedUploadResult(result)) {
|
|
1028
|
+
throw new CliError("Signed upload response was invalid", 1);
|
|
1029
|
+
}
|
|
1030
|
+
return {
|
|
1031
|
+
...result,
|
|
1032
|
+
filePath,
|
|
1033
|
+
contentType,
|
|
1034
|
+
size: fileStat.size,
|
|
1035
|
+
instanceId: result.instanceId
|
|
1036
|
+
};
|
|
1037
|
+
};
|
|
1038
|
+
var resolveUploadInstanceId = async (resource, target) => {
|
|
1039
|
+
if (target.instanceId)
|
|
1040
|
+
return target.instanceId;
|
|
1041
|
+
if (target.id) {
|
|
1042
|
+
const row = await requestApi(`/api/cli/${resource.name}/${target.id}`);
|
|
1043
|
+
const rowInstanceId = getInstanceIdFromData(row);
|
|
1044
|
+
if (rowInstanceId)
|
|
1045
|
+
return rowInstanceId;
|
|
1046
|
+
}
|
|
1047
|
+
const fallback = defaultInstanceId(resource);
|
|
1048
|
+
if (fallback)
|
|
1049
|
+
return fallback;
|
|
1050
|
+
throw new CliError("Missing --instance for upload target", 2);
|
|
1051
|
+
};
|
|
1052
|
+
var applyUploadedMediaData = (resource, data, upload) => {
|
|
1053
|
+
if (!upload.fileUrl)
|
|
1054
|
+
return;
|
|
1055
|
+
if (resource.name === "internal-knowledge") {
|
|
1056
|
+
data.sourceType = "UPLOAD";
|
|
1057
|
+
data.url = upload.fileUrl;
|
|
1058
|
+
data.mimeType = upload.contentType;
|
|
1059
|
+
data.size = upload.size;
|
|
1060
|
+
return;
|
|
1061
|
+
}
|
|
1062
|
+
if (resource.name === "resources") {
|
|
1063
|
+
data.sourceType = "UPLOAD";
|
|
1064
|
+
data.fileUrl = upload.fileUrl;
|
|
1065
|
+
data.linkUrl = upload.fileUrl;
|
|
1066
|
+
}
|
|
1067
|
+
};
|
|
1068
|
+
var setUploadInstanceData = (resource, data, instanceId) => {
|
|
1069
|
+
const instanceField = resource.instanceField === undefined ? "instanceId" : resource.instanceField;
|
|
1070
|
+
if (instanceField && !instanceField.includes(".")) {
|
|
1071
|
+
data[instanceField] = instanceId;
|
|
1072
|
+
}
|
|
1073
|
+
};
|
|
1074
|
+
var uploadToSignedUrl = async (signedUrl, filePath, contentType, size) => {
|
|
1075
|
+
const response = await fetch(signedUrl, {
|
|
1076
|
+
method: "PUT",
|
|
1077
|
+
body: createReadStream(filePath),
|
|
1078
|
+
duplex: "half",
|
|
1079
|
+
headers: {
|
|
1080
|
+
"Content-Type": contentType,
|
|
1081
|
+
"Content-Length": String(size)
|
|
1082
|
+
}
|
|
1083
|
+
});
|
|
1084
|
+
if (!response.ok) {
|
|
1085
|
+
throw new CliError(`Direct upload failed with ${response.status}`, 1);
|
|
1086
|
+
}
|
|
1087
|
+
};
|
|
1088
|
+
var isSignedUploadResult = (value) => {
|
|
1089
|
+
if (!value || typeof value !== "object")
|
|
1090
|
+
return false;
|
|
1091
|
+
const upload = value;
|
|
1092
|
+
return typeof upload.signedUrl === "string" && typeof upload.fileUrl === "string" && typeof upload.filePath === "string" && typeof upload.contentType === "string" && typeof upload.instanceId === "string";
|
|
1093
|
+
};
|
|
1094
|
+
var isPreparedSignedUpload = (value) => {
|
|
1095
|
+
if (!value || typeof value !== "object")
|
|
1096
|
+
return false;
|
|
1097
|
+
const upload = value;
|
|
1098
|
+
return typeof upload.signedUrl === "string" && typeof upload.fileUrl === "string" && typeof upload.filePath === "string" && typeof upload.contentType === "string" && typeof upload.size === "number" && typeof upload.instanceId === "string";
|
|
1099
|
+
};
|
|
1100
|
+
var getInstanceIdFromData = (value) => {
|
|
1101
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
1102
|
+
return null;
|
|
1103
|
+
const row = value;
|
|
1104
|
+
const instanceId = row.instanceId ?? row.instanceID;
|
|
1105
|
+
return typeof instanceId === "string" && instanceId.length > 0 ? instanceId : null;
|
|
1106
|
+
};
|
|
1107
|
+
var resolveLocalPath = (filePath) => {
|
|
1108
|
+
if (filePath === "~")
|
|
1109
|
+
return homedir2();
|
|
1110
|
+
if (filePath.startsWith("~/"))
|
|
1111
|
+
return join2(homedir2(), filePath.slice(2));
|
|
1112
|
+
return resolve(filePath);
|
|
1113
|
+
};
|
|
1114
|
+
var inferMimeType = (filePath) => {
|
|
1115
|
+
const ext = extname(filePath).toLowerCase();
|
|
1116
|
+
const mimeByExtension = {
|
|
1117
|
+
".mp4": "video/mp4",
|
|
1118
|
+
".m4v": "video/mp4",
|
|
1119
|
+
".mov": "video/quicktime",
|
|
1120
|
+
".webm": "video/webm",
|
|
1121
|
+
".pdf": "application/pdf",
|
|
1122
|
+
".txt": "text/plain",
|
|
1123
|
+
".md": "text/markdown",
|
|
1124
|
+
".html": "text/html",
|
|
1125
|
+
".htm": "text/html",
|
|
1126
|
+
".doc": "application/msword",
|
|
1127
|
+
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
|
1128
|
+
};
|
|
1129
|
+
return mimeByExtension[ext] ?? "application/octet-stream";
|
|
1130
|
+
};
|
|
972
1131
|
var getSoftDeleteData = (resource) => {
|
|
973
1132
|
if (resource.defaultFields.includes("disabled"))
|
|
974
1133
|
return { disabled: true };
|
|
@@ -2226,6 +2385,8 @@ var rootHelp = () => ({
|
|
|
2226
2385
|
"gskills-admin sync repair-source-links --target <instanceId> --dry-run",
|
|
2227
2386
|
"gskills-admin translate pages <id> --to en,es --dry-run",
|
|
2228
2387
|
"gskills-admin imported-sheets create --instance <id> --source <url> --tab <name> --locales fr,en --enable-vectorization --dry-run",
|
|
2388
|
+
`gskills-admin internal-knowledge create --instance <instanceId> --upload-file ./video.mp4 --data '{"title":"...","language":"fr"}' --yes`,
|
|
2389
|
+
`gskills-admin resources create --instance <instanceId> --upload-file ./webinar.mp4 --data '{"title":"...","type":"WEBINAR","language":"fr"}' --yes`,
|
|
2229
2390
|
"gskills-admin internal-knowledge sync-media --since today --languages fr --all-targets --dry-run",
|
|
2230
2391
|
"gskills-admin progress learning-path-quiz-mismatches --instance <instanceId>",
|
|
2231
2392
|
"gskills-admin sessions invalidate --email user@example.com --dry-run",
|
|
@@ -2314,8 +2475,8 @@ var schemaHelp = () => ({
|
|
|
2314
2475
|
...resources.flatMap((resource) => [
|
|
2315
2476
|
{ name: `${resource.name} list`, writes: false, flags: ["--where", "--fields", "--take", "--skip", "--order-by", "--instance", "--dry-run"] },
|
|
2316
2477
|
{ name: `${resource.name} get`, args: ["id"], writes: false },
|
|
2317
|
-
{ name: `${resource.name} create`, flags: ["--data", "--instance", "--dry-run"], writes: true },
|
|
2318
|
-
{ name: `${resource.name} update`, args: ["id"], flags: ["--data", "--dry-run"], writes: true },
|
|
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 },
|
|
2319
2480
|
{ name: `${resource.name} delete`, args: ["id"], flags: ["--force", "--confirm-delete", "--dry-run"], writes: true, destructive: false, softOnly: true }
|
|
2320
2481
|
])
|
|
2321
2482
|
],
|
|
@@ -2602,6 +2763,8 @@ var resourceHelp = (resource) => ({
|
|
|
2602
2763
|
`gskills-admin ${resource.name} create --data '{"instanceId":"global"}'`,
|
|
2603
2764
|
`gskills-admin ${resource.name} update <id> --data '{"disabled":true}'`,
|
|
2604
2765
|
`gskills-admin ${resource.name} delete <id> --force --confirm-delete ${resource.name}:<id>`,
|
|
2766
|
+
...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
|
+
...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`] : [],
|
|
2605
2768
|
...resource.name === "internal-knowledge" ? [`gskills-admin ${resource.name} sync-media --since today --languages fr --all-targets --dry-run`] : [],
|
|
2606
2769
|
...resource.name === "pages" ? [`gskills-admin ${resource.name} backfill-field --field headerColor --all-targets --dry-run`] : []
|
|
2607
2770
|
],
|
package/package.json
CHANGED
|
@@ -69,6 +69,17 @@ gskills-admin cache invalidate --instance <instanceId> --scope pages --yes --out
|
|
|
69
69
|
|
|
70
70
|
CRUD help exposes `cache.scopes` for resources that are known to feed deploy caches. After create, update, or soft-delete, the database can be correct while the end-user view is still stale. Use the narrowest listed scope first. Use `all` only when the changed setting affects many deploy surfaces or when the narrow scope did not clear the visible stale state.
|
|
71
71
|
|
|
72
|
+
Internal knowledge and resources support direct local file uploads through signed GCS URLs. The CLI gets a signed URL from the authenticated app API, streams the local file directly to storage, then writes the normal row with the returned URL. This avoids routing large videos through a Next.js API body.
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
gskills-admin internal-knowledge create --instance dev-numericoach --upload-file ./capsule.mp4 --data '{"title":"Capsule test","language":"fr","isActive":true,"isAIAllowed":false}' --dry-run --output json
|
|
76
|
+
gskills-admin internal-knowledge update <knowledgeId> --instance dev-numericoach --upload-file ./capsule-v2.mp4 --data '{}' --dry-run --output json
|
|
77
|
+
gskills-admin resources create --instance dev-numericoach --upload-file ./webinar.mp4 --data '{"title":"Webinar test","type":"WEBINAR","language":"fr","isActive":true}' --dry-run --output json
|
|
78
|
+
gskills-admin resources update <resourceId> --instance dev-numericoach --upload-file ./webinar-v2.mp4 --data '{}' --dry-run --output json
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Use `--mime-type` when the extension is ambiguous and `--upload-name` when the stored file name should differ from the local basename. Always pass `--instance` for client-specific content; otherwise content-like creates default to `global`.
|
|
82
|
+
|
|
72
83
|
Delete commands are soft-only. They require both `--force` and an exact confirmation token, then write the safest inactive field available, such as `disabled: true`, `archived: true`, `isActive: false`, or `active: false`. If a resource cannot be safely disabled, the CLI refuses the delete command.
|
|
73
84
|
|
|
74
85
|
```bash
|