@ait-co/console-cli 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.mjs +179 -26
- package/dist/cli.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -204,6 +204,22 @@ async function fetchReviewStatus(workspaceId, cookies, opts = {}) {
|
|
|
204
204
|
})
|
|
205
205
|
};
|
|
206
206
|
}
|
|
207
|
+
async function fetchMiniAppWithDraft(workspaceId, miniAppId, cookies, opts = {}) {
|
|
208
|
+
const raw = await requestConsoleApi({
|
|
209
|
+
url: `${BASE$2}/workspaces/${workspaceId}/mini-app/${miniAppId}/with-draft`,
|
|
210
|
+
cookies,
|
|
211
|
+
...opts.fetchImpl ? { fetchImpl: opts.fetchImpl } : {}
|
|
212
|
+
});
|
|
213
|
+
if (raw === null || typeof raw !== "object") throw new Error(`Unexpected with-draft shape for mini-app=${miniAppId}`);
|
|
214
|
+
const rec = raw;
|
|
215
|
+
return {
|
|
216
|
+
current: isRecordOrNull(rec.current) ? rec.current : null,
|
|
217
|
+
draft: isRecordOrNull(rec.draft) ? rec.draft : null
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function isRecordOrNull(v) {
|
|
221
|
+
return v === null || typeof v === "object" && !Array.isArray(v);
|
|
222
|
+
}
|
|
207
223
|
async function createMiniApp(workspaceId, payload, cookies, opts = {}) {
|
|
208
224
|
return normalizeCreateResult(await requestConsoleApi({
|
|
209
225
|
url: `${BASE$2}/workspaces/${workspaceId}/mini-app/review`,
|
|
@@ -1028,21 +1044,112 @@ function reviewStateFor(entry) {
|
|
|
1028
1044
|
const raw = entry.reviewState ?? entry.status;
|
|
1029
1045
|
return typeof raw === "string" ? raw : void 0;
|
|
1030
1046
|
}
|
|
1047
|
+
const lsCommand$3 = defineCommand({
|
|
1048
|
+
meta: {
|
|
1049
|
+
name: "ls",
|
|
1050
|
+
description: "List mini-apps in the selected workspace."
|
|
1051
|
+
},
|
|
1052
|
+
args: {
|
|
1053
|
+
workspace: {
|
|
1054
|
+
type: "string",
|
|
1055
|
+
description: "Workspace ID. Defaults to the selected workspace (`aitcc workspace use`)."
|
|
1056
|
+
},
|
|
1057
|
+
json: {
|
|
1058
|
+
type: "boolean",
|
|
1059
|
+
description: "Emit machine-readable JSON to stdout.",
|
|
1060
|
+
default: false
|
|
1061
|
+
}
|
|
1062
|
+
},
|
|
1063
|
+
async run({ args }) {
|
|
1064
|
+
const ctx = await resolveWorkspaceContext(args);
|
|
1065
|
+
if (!ctx) return;
|
|
1066
|
+
const { session, workspaceId } = ctx;
|
|
1067
|
+
try {
|
|
1068
|
+
const [apps, review] = await Promise.all([fetchMiniApps(workspaceId, session.cookies), fetchReviewStatus(workspaceId, session.cookies)]);
|
|
1069
|
+
if (args.json) {
|
|
1070
|
+
const joined = apps.map((app) => {
|
|
1071
|
+
const reviewState = reviewStateFor(findReviewEntry(review.miniApps, app.id));
|
|
1072
|
+
return {
|
|
1073
|
+
id: app.id,
|
|
1074
|
+
name: app.name ?? null,
|
|
1075
|
+
...reviewState !== void 0 ? { reviewState } : {},
|
|
1076
|
+
extra: app.extra
|
|
1077
|
+
};
|
|
1078
|
+
});
|
|
1079
|
+
emitJson({
|
|
1080
|
+
ok: true,
|
|
1081
|
+
workspaceId,
|
|
1082
|
+
hasPolicyViolation: review.hasPolicyViolation,
|
|
1083
|
+
apps: joined
|
|
1084
|
+
});
|
|
1085
|
+
return exitAfterFlush(ExitCode.Ok);
|
|
1086
|
+
}
|
|
1087
|
+
if (apps.length === 0) {
|
|
1088
|
+
process.stdout.write(`No apps in workspace ${workspaceId}.\n`);
|
|
1089
|
+
if (review.hasPolicyViolation) process.stderr.write("Note: workspace-wide policy violation flag is set.\n");
|
|
1090
|
+
return exitAfterFlush(ExitCode.Ok);
|
|
1091
|
+
}
|
|
1092
|
+
for (const app of apps) {
|
|
1093
|
+
const reviewState = reviewStateFor(findReviewEntry(review.miniApps, app.id)) ?? "-";
|
|
1094
|
+
const name = app.name ?? "(unnamed)";
|
|
1095
|
+
process.stdout.write(`${app.id}\t${name}\t${reviewState}\n`);
|
|
1096
|
+
}
|
|
1097
|
+
if (review.hasPolicyViolation) process.stderr.write("Note: workspace-wide policy violation flag is set.\n");
|
|
1098
|
+
return exitAfterFlush(ExitCode.Ok);
|
|
1099
|
+
} catch (err) {
|
|
1100
|
+
return emitFailureFromError(args.json, err);
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
});
|
|
1104
|
+
function pickMiniAppView(envelope, view) {
|
|
1105
|
+
const extract = (side) => {
|
|
1106
|
+
if (side === null) return null;
|
|
1107
|
+
const ma = side.miniApp;
|
|
1108
|
+
if (ma !== null && typeof ma === "object" && !Array.isArray(ma)) return ma;
|
|
1109
|
+
return null;
|
|
1110
|
+
};
|
|
1111
|
+
const draft = extract(envelope.draft);
|
|
1112
|
+
const current = extract(envelope.current);
|
|
1113
|
+
if (view === "draft") return draft;
|
|
1114
|
+
if (view === "current") return current;
|
|
1115
|
+
if (current !== null && draft !== null) return {
|
|
1116
|
+
...current,
|
|
1117
|
+
...draft
|
|
1118
|
+
};
|
|
1119
|
+
return draft ?? current;
|
|
1120
|
+
}
|
|
1121
|
+
function parseAppId(raw) {
|
|
1122
|
+
if (raw === void 0 || raw === "") return null;
|
|
1123
|
+
const n = Number(raw);
|
|
1124
|
+
if (!Number.isFinite(n) || !Number.isInteger(n) || n <= 0) return null;
|
|
1125
|
+
return n;
|
|
1126
|
+
}
|
|
1031
1127
|
const appCommand = defineCommand({
|
|
1032
1128
|
meta: {
|
|
1033
1129
|
name: "app",
|
|
1034
1130
|
description: "Inspect mini-apps in a workspace."
|
|
1035
1131
|
},
|
|
1036
1132
|
subCommands: {
|
|
1037
|
-
ls:
|
|
1133
|
+
ls: lsCommand$3,
|
|
1134
|
+
show: defineCommand({
|
|
1038
1135
|
meta: {
|
|
1039
|
-
name: "
|
|
1040
|
-
description: "
|
|
1136
|
+
name: "show",
|
|
1137
|
+
description: "Show full details of a mini-app, including fields only visible in the draft view."
|
|
1041
1138
|
},
|
|
1042
1139
|
args: {
|
|
1140
|
+
id: {
|
|
1141
|
+
type: "positional",
|
|
1142
|
+
description: "Mini-app ID (the numeric `appId` from `app ls` or `app register`).",
|
|
1143
|
+
required: true
|
|
1144
|
+
},
|
|
1043
1145
|
workspace: {
|
|
1044
1146
|
type: "string",
|
|
1045
|
-
description: "Workspace ID. Defaults to the selected workspace
|
|
1147
|
+
description: "Workspace ID. Defaults to the selected workspace."
|
|
1148
|
+
},
|
|
1149
|
+
view: {
|
|
1150
|
+
type: "string",
|
|
1151
|
+
description: "Which view to render: `draft` (default), `current`, or `merged`.",
|
|
1152
|
+
default: "draft"
|
|
1046
1153
|
},
|
|
1047
1154
|
json: {
|
|
1048
1155
|
type: "boolean",
|
|
@@ -1051,40 +1158,86 @@ const appCommand = defineCommand({
|
|
|
1051
1158
|
}
|
|
1052
1159
|
},
|
|
1053
1160
|
async run({ args }) {
|
|
1161
|
+
const appId = parseAppId(args.id);
|
|
1162
|
+
if (appId === null) {
|
|
1163
|
+
if (args.json) emitJson({
|
|
1164
|
+
ok: false,
|
|
1165
|
+
reason: "invalid-id",
|
|
1166
|
+
message: `app id must be a positive integer (got ${JSON.stringify(args.id)})`
|
|
1167
|
+
});
|
|
1168
|
+
else process.stderr.write(`app show: invalid id ${JSON.stringify(args.id)}\n`);
|
|
1169
|
+
return exitAfterFlush(ExitCode.Usage);
|
|
1170
|
+
}
|
|
1171
|
+
const view = args.view;
|
|
1172
|
+
if (view !== "draft" && view !== "current" && view !== "merged") {
|
|
1173
|
+
if (args.json) emitJson({
|
|
1174
|
+
ok: false,
|
|
1175
|
+
reason: "invalid-config",
|
|
1176
|
+
field: "view",
|
|
1177
|
+
message: `--view must be one of draft|current|merged (got ${JSON.stringify(view)})`
|
|
1178
|
+
});
|
|
1179
|
+
else process.stderr.write(`app show: invalid --view ${JSON.stringify(view)}\n`);
|
|
1180
|
+
return exitAfterFlush(ExitCode.Usage);
|
|
1181
|
+
}
|
|
1054
1182
|
const ctx = await resolveWorkspaceContext(args);
|
|
1055
1183
|
if (!ctx) return;
|
|
1056
1184
|
const { session, workspaceId } = ctx;
|
|
1057
1185
|
try {
|
|
1058
|
-
const
|
|
1186
|
+
const envelope = await fetchMiniAppWithDraft(workspaceId, appId, session.cookies);
|
|
1187
|
+
const miniApp = pickMiniAppView(envelope, view);
|
|
1059
1188
|
if (args.json) {
|
|
1060
|
-
const joined = apps.map((app) => {
|
|
1061
|
-
const reviewState = reviewStateFor(findReviewEntry(review.miniApps, app.id));
|
|
1062
|
-
return {
|
|
1063
|
-
id: app.id,
|
|
1064
|
-
name: app.name ?? null,
|
|
1065
|
-
...reviewState !== void 0 ? { reviewState } : {},
|
|
1066
|
-
extra: app.extra
|
|
1067
|
-
};
|
|
1068
|
-
});
|
|
1069
1189
|
emitJson({
|
|
1070
1190
|
ok: true,
|
|
1071
1191
|
workspaceId,
|
|
1072
|
-
|
|
1073
|
-
|
|
1192
|
+
appId,
|
|
1193
|
+
view,
|
|
1194
|
+
miniApp
|
|
1074
1195
|
});
|
|
1075
1196
|
return exitAfterFlush(ExitCode.Ok);
|
|
1076
1197
|
}
|
|
1077
|
-
if (
|
|
1078
|
-
process.stdout.write(`
|
|
1079
|
-
|
|
1198
|
+
if (miniApp === null) {
|
|
1199
|
+
if (view === "current" && envelope.draft !== null) process.stdout.write(`App ${appId} has no \`current\` view yet (not reviewed). Try --view draft.\n`);
|
|
1200
|
+
else process.stdout.write(`App ${appId} has no data for view=${view}.\n`);
|
|
1080
1201
|
return exitAfterFlush(ExitCode.Ok);
|
|
1081
1202
|
}
|
|
1082
|
-
|
|
1083
|
-
const
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1203
|
+
const pick = (k) => {
|
|
1204
|
+
const v = miniApp[k];
|
|
1205
|
+
return v === null || v === void 0 ? "-" : String(v);
|
|
1206
|
+
};
|
|
1207
|
+
const images = Array.isArray(miniApp.images) ? miniApp.images : [];
|
|
1208
|
+
const impression = miniApp.impression !== null && typeof miniApp.impression === "object" ? miniApp.impression : {};
|
|
1209
|
+
const keywords = Array.isArray(impression.keywordList) ? impression.keywordList : [];
|
|
1210
|
+
const categoryPaths = Array.isArray(impression.categoryPaths) ? impression.categoryPaths : [];
|
|
1211
|
+
process.stdout.write(`# App ${appId} (view=${view})\n\n`);
|
|
1212
|
+
process.stdout.write(`Name (ko) ${pick("title")}\n`);
|
|
1213
|
+
process.stdout.write(`Name (en) ${pick("titleEn")}\n`);
|
|
1214
|
+
process.stdout.write(`App slug ${pick("appName")}\n`);
|
|
1215
|
+
process.stdout.write(`Status ${pick("status")}\n`);
|
|
1216
|
+
process.stdout.write(`Home page ${pick("homePageUri")}\n`);
|
|
1217
|
+
process.stdout.write(`CS email ${pick("csEmail")}\n`);
|
|
1218
|
+
process.stdout.write(`Logo ${pick("iconUri")}\n`);
|
|
1219
|
+
process.stdout.write(`Subtitle ${pick("description")}\n`);
|
|
1220
|
+
const detail = typeof miniApp.detailDescription === "string" ? `${[...miniApp.detailDescription].length} chars` : "-";
|
|
1221
|
+
process.stdout.write(`Detail desc ${detail}\n`);
|
|
1222
|
+
process.stdout.write(`Images ${images.length}\n`);
|
|
1223
|
+
process.stdout.write(`Keywords ${keywords.length} (${keywords.join(", ")})\n`);
|
|
1224
|
+
const firstPath = categoryPaths[0];
|
|
1225
|
+
if (firstPath && typeof firstPath === "object") {
|
|
1226
|
+
const fp = firstPath;
|
|
1227
|
+
const parts = [];
|
|
1228
|
+
for (const key of [
|
|
1229
|
+
"group",
|
|
1230
|
+
"category",
|
|
1231
|
+
"subCategory"
|
|
1232
|
+
]) {
|
|
1233
|
+
const node = fp[key];
|
|
1234
|
+
if (node !== null && typeof node === "object") {
|
|
1235
|
+
const nm = node.name;
|
|
1236
|
+
if (typeof nm === "string") parts.push(nm);
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
process.stdout.write(`Category ${parts.join(" > ") || "-"}\n`);
|
|
1240
|
+
} else process.stdout.write(`Category -\n`);
|
|
1088
1241
|
return exitAfterFlush(ExitCode.Ok);
|
|
1089
1242
|
} catch (err) {
|
|
1090
1243
|
return emitFailureFromError(args.json, err);
|
|
@@ -2082,7 +2235,7 @@ function resolveVersion() {
|
|
|
2082
2235
|
if (typeof injected === "string" && injected.length > 0) return injected;
|
|
2083
2236
|
} catch {}
|
|
2084
2237
|
try {
|
|
2085
|
-
return "0.1.
|
|
2238
|
+
return "0.1.9";
|
|
2086
2239
|
} catch {}
|
|
2087
2240
|
return "0.0.0-dev";
|
|
2088
2241
|
}
|