recess-cli 3.4.1 → 3.6.0
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/api.js +17 -0
- package/dist/cli.js +89 -4
- package/dist/command-schema.js +7 -0
- package/dist/commands/channels.js +271 -0
- package/dist/commands/db.js +78 -0
- package/dist/commands/families.js +39 -0
- package/dist/commands/phone-and-texts.js +167 -0
- package/dist/commands/rooms.js +70 -0
- package/dist/help.js +61 -0
- package/package.json +1 -1
package/dist/api.js
CHANGED
|
@@ -167,6 +167,23 @@ export class RecessAdminApi {
|
|
|
167
167
|
throw apiError(response.status, body);
|
|
168
168
|
return body;
|
|
169
169
|
}
|
|
170
|
+
async uploadChannelImage(channelId, image, fileName, mimeType) {
|
|
171
|
+
this.requireAuth();
|
|
172
|
+
const formData = new FormData();
|
|
173
|
+
const arrayBuffer = image.buffer.slice(image.byteOffset, image.byteOffset + image.byteLength);
|
|
174
|
+
formData.append("file", new Blob([arrayBuffer], { type: mimeType }), fileName);
|
|
175
|
+
const headers = cliRequestHeaders({ cookie: this.config.sessionCookie }, this.reason, this.clientTag);
|
|
176
|
+
applyIdempotencyHeaders(headers);
|
|
177
|
+
const response = await fetch(new URL(`/admin/channels/${encodeURIComponent(channelId)}/image`, this.config.apiOrigin), {
|
|
178
|
+
method: "POST",
|
|
179
|
+
headers,
|
|
180
|
+
body: formData,
|
|
181
|
+
});
|
|
182
|
+
const body = await readResponseBody(response);
|
|
183
|
+
if (!response.ok)
|
|
184
|
+
throw apiError(response.status, body);
|
|
185
|
+
return body;
|
|
186
|
+
}
|
|
170
187
|
async uploadMapTestScores(studentId, pdf, fileName) {
|
|
171
188
|
this.requireAuth();
|
|
172
189
|
const formData = new FormData();
|
package/dist/cli.js
CHANGED
|
@@ -10,7 +10,12 @@ import { agentContext, buildCommandSchema, findCommandSchema, remoteCommands, sc
|
|
|
10
10
|
import { runApplicationsCommand } from "./commands/applications.js";
|
|
11
11
|
import { runAppsCommand } from "./commands/apps.js";
|
|
12
12
|
import { readAssignmentSelection, runGoalCurriculumCommand, } from "./commands/goal-curriculum.js";
|
|
13
|
+
import { runChannelsCommand } from "./commands/channels.js";
|
|
13
14
|
import { runChatLogsCommand } from "./commands/chat-logs.js";
|
|
15
|
+
import { runDbCommand } from "./commands/db.js";
|
|
16
|
+
import { runRoomsCommand } from "./commands/rooms.js";
|
|
17
|
+
import { runFamiliesCommand } from "./commands/families.js";
|
|
18
|
+
import { runStudentsTextsCommand, runUsersPhoneCommand, } from "./commands/phone-and-texts.js";
|
|
14
19
|
import { runMasteryCommand } from "./commands/mastery.js";
|
|
15
20
|
import { runOnboardingCommand } from "./commands/onboarding.js";
|
|
16
21
|
import { runScheduleCommand, runMemoryFilesCommand, } from "./commands/safe-staff-operations.js";
|
|
@@ -308,6 +313,7 @@ async function localWriteCommand(parsed, preview, execute) {
|
|
|
308
313
|
const GOAL_WORKSPACE_WRITE_MAX_FILES = 1_000;
|
|
309
314
|
const GOAL_WORKSPACE_WRITE_MAX_TOTAL_BYTES = 20 * 1024 * 1024;
|
|
310
315
|
const GOAL_PDF_UPLOAD_MAX_BYTES = 1024 * 1024 * 1024;
|
|
316
|
+
const GOAL_VIDEO_UPLOAD_MAX_BYTES = 500 * 1024 * 1024;
|
|
311
317
|
const GOAL_QUEUE_MAX_ENTRIES = 500;
|
|
312
318
|
const URL_QUEUE_DESCRIPTION_POINTER = "Skill queue managed by the system.";
|
|
313
319
|
const RECESS_GIT_METADATA = "recess-workspace.json";
|
|
@@ -2670,6 +2676,9 @@ export async function executeRecessCommand(argv, options = {}) {
|
|
|
2670
2676
|
body,
|
|
2671
2677
|
})));
|
|
2672
2678
|
}
|
|
2679
|
+
if (noun === "users" && verb === "phone") {
|
|
2680
|
+
return runUsersPhoneCommand({ parsed, api, writeCommand });
|
|
2681
|
+
}
|
|
2673
2682
|
if (noun === "users" && verb === "get") {
|
|
2674
2683
|
const userId = positional(parsed, 2, "user ID");
|
|
2675
2684
|
return unwrap(await api.client.GET("/admin/users/{userId}", {
|
|
@@ -4340,7 +4349,7 @@ export async function executeRecessCommand(argv, options = {}) {
|
|
|
4340
4349
|
}));
|
|
4341
4350
|
const prompt = flagString(parsed, "prompt");
|
|
4342
4351
|
return writeCommand(parsed, {
|
|
4343
|
-
action: "queue paid
|
|
4352
|
+
action: "queue paid challenge-art regeneration",
|
|
4344
4353
|
target: {
|
|
4345
4354
|
templateId: id,
|
|
4346
4355
|
slug: current.slug,
|
|
@@ -4348,7 +4357,7 @@ export async function executeRecessCommand(argv, options = {}) {
|
|
|
4348
4357
|
},
|
|
4349
4358
|
request: { prompt: prompt ?? null },
|
|
4350
4359
|
details: {
|
|
4351
|
-
costNote: "This queues one paid 1024×1024
|
|
4360
|
+
costNote: "This queues one paid 1024×1024 challenge-art painting (the shared lane behind /challenges-v2, from the category's style reference; ~$0.02) and replaces the template image when it finishes. New templates already generate art automatically.",
|
|
4352
4361
|
},
|
|
4353
4362
|
}, async () => unwrap(await api.client.POST("/ai/goal-templates/{id}/generate-image", {
|
|
4354
4363
|
params: { path: { id } },
|
|
@@ -4582,7 +4591,10 @@ export async function executeRecessCommand(argv, options = {}) {
|
|
|
4582
4591
|
}
|
|
4583
4592
|
throw new CliError("invalid_arguments", "Use goals adaptations list|diff.");
|
|
4584
4593
|
}
|
|
4585
|
-
if (noun === "goals" &&
|
|
4594
|
+
if (noun === "goals" &&
|
|
4595
|
+
verb !== "files" &&
|
|
4596
|
+
verb !== "pdf" &&
|
|
4597
|
+
verb !== "video") {
|
|
4586
4598
|
if (verb === "complete" || verb === "undo-completion") {
|
|
4587
4599
|
const goalId = positional(parsed, 2, "goal ID");
|
|
4588
4600
|
const undo = verb === "undo-completion";
|
|
@@ -5074,11 +5086,26 @@ export async function executeRecessCommand(argv, options = {}) {
|
|
|
5074
5086
|
}
|
|
5075
5087
|
throw new CliError("invalid_arguments", "Use goals queue get|set.");
|
|
5076
5088
|
}
|
|
5077
|
-
throw new CliError("invalid_arguments", "Use goals list|create|edit|delete|restore|archive|unarchive|complete|undo-completion|move-module|queue|files|pdf.");
|
|
5089
|
+
throw new CliError("invalid_arguments", "Use goals list|create|edit|delete|restore|archive|unarchive|complete|undo-completion|move-module|queue|files|pdf|video.");
|
|
5090
|
+
}
|
|
5091
|
+
if (noun === "channels") {
|
|
5092
|
+
return runChannelsCommand({ parsed, api, writeCommand });
|
|
5093
|
+
}
|
|
5094
|
+
if (noun === "families") {
|
|
5095
|
+
return runFamiliesCommand({ parsed, api, writeCommand });
|
|
5078
5096
|
}
|
|
5079
5097
|
if (noun === "chat-logs") {
|
|
5080
5098
|
return runChatLogsCommand({ parsed, api, writeCommand });
|
|
5081
5099
|
}
|
|
5100
|
+
if (noun === "db") {
|
|
5101
|
+
return runDbCommand({ parsed, api, writeCommand });
|
|
5102
|
+
}
|
|
5103
|
+
if (noun === "rooms") {
|
|
5104
|
+
return runRoomsCommand({ parsed, api, writeCommand });
|
|
5105
|
+
}
|
|
5106
|
+
if (noun === "students" && verb === "texts") {
|
|
5107
|
+
return runStudentsTextsCommand({ parsed, api, writeCommand });
|
|
5108
|
+
}
|
|
5082
5109
|
if (noun === "students") {
|
|
5083
5110
|
if (verb === "list") {
|
|
5084
5111
|
const requestedScope = flagString(parsed, "scope");
|
|
@@ -5651,6 +5678,64 @@ export async function executeRecessCommand(argv, options = {}) {
|
|
|
5651
5678
|
}
|
|
5652
5679
|
throw new CliError("invalid_arguments", "Use tutor-templates list|get|create|update|delete|assign|unassign.");
|
|
5653
5680
|
}
|
|
5681
|
+
if (noun === "goals" && verb === "video") {
|
|
5682
|
+
const action = positional(parsed, 2, "goals video action");
|
|
5683
|
+
if (action !== "upload") {
|
|
5684
|
+
throw new CliError("invalid_arguments", "Use goals video upload.");
|
|
5685
|
+
}
|
|
5686
|
+
const sourceFile = flagString(parsed, "source-file", { required: true });
|
|
5687
|
+
const absolutePath = path.resolve(sourceFile);
|
|
5688
|
+
const fileStat = await fs.lstat(absolutePath).catch(() => null);
|
|
5689
|
+
if (!fileStat?.isFile() || fileStat.isSymbolicLink()) {
|
|
5690
|
+
throw new CliError("invalid_arguments", `--source-file is not a file: ${absolutePath}`);
|
|
5691
|
+
}
|
|
5692
|
+
if (!absolutePath.toLowerCase().endsWith(".mp4")) {
|
|
5693
|
+
throw new CliError("invalid_arguments", "goals video upload accepts .mp4 files only (H.264 plays everywhere).");
|
|
5694
|
+
}
|
|
5695
|
+
if (fileStat.size <= 0 || fileStat.size > GOAL_VIDEO_UPLOAD_MAX_BYTES) {
|
|
5696
|
+
throw new CliError("invalid_arguments", `Video size must be between 1 byte and ${GOAL_VIDEO_UPLOAD_MAX_BYTES} bytes.`);
|
|
5697
|
+
}
|
|
5698
|
+
const fileName = path.basename(absolutePath);
|
|
5699
|
+
const sourceSha256 = await sha256File(absolutePath);
|
|
5700
|
+
const preview = {
|
|
5701
|
+
action: "publish a video at a public, unlisted URL",
|
|
5702
|
+
target: { fileName },
|
|
5703
|
+
request: {
|
|
5704
|
+
sourceFile: absolutePath,
|
|
5705
|
+
sourceSha256,
|
|
5706
|
+
sizeBytes: fileStat.size,
|
|
5707
|
+
},
|
|
5708
|
+
details: {
|
|
5709
|
+
note: "Anyone with the returned URL can watch it. Paste the URL into a goal module or template (with a short transcript so Rocky knows what it covers); Rocky opens it in the browser.",
|
|
5710
|
+
},
|
|
5711
|
+
};
|
|
5712
|
+
return previewBoundWrite(parsed, preview, async () => {
|
|
5713
|
+
const signed = unwrap(await api.client.POST("/os-v2-mesa/goal-videos/sign", {
|
|
5714
|
+
body: { fileName, sizeBytes: fileStat.size },
|
|
5715
|
+
}));
|
|
5716
|
+
const bytes = await fs.readFile(absolutePath);
|
|
5717
|
+
if (createHash("sha256").update(bytes).digest("hex") !== sourceSha256) {
|
|
5718
|
+
throw new CliError("source_changed", "The video changed after approval; preview the current file again.");
|
|
5719
|
+
}
|
|
5720
|
+
const response = await fetch(signed.uploadUrl, {
|
|
5721
|
+
method: "PUT",
|
|
5722
|
+
headers: signed.uploadHeaders,
|
|
5723
|
+
body: uploadBody(bytes),
|
|
5724
|
+
});
|
|
5725
|
+
if (!response.ok) {
|
|
5726
|
+
throw new CliError("upload_failed", `Video upload failed with HTTP ${response.status}.`);
|
|
5727
|
+
}
|
|
5728
|
+
const done = unwrap(await api.client.POST("/os-v2-mesa/goal-videos/complete", {
|
|
5729
|
+
body: { assetId: signed.assetId },
|
|
5730
|
+
}));
|
|
5731
|
+
return {
|
|
5732
|
+
action: "upload_goal_video",
|
|
5733
|
+
url: done.url,
|
|
5734
|
+
fileName,
|
|
5735
|
+
sizeBytes: fileStat.size,
|
|
5736
|
+
};
|
|
5737
|
+
});
|
|
5738
|
+
}
|
|
5654
5739
|
if (noun === "goals" && verb === "pdf") {
|
|
5655
5740
|
const action = positional(parsed, 2, "goals pdf action");
|
|
5656
5741
|
if (action !== "upload") {
|
package/dist/command-schema.js
CHANGED
|
@@ -13,6 +13,8 @@ const BOOLEAN_FLAGS = new Set([
|
|
|
13
13
|
"archived",
|
|
14
14
|
"cancel-subscriptions",
|
|
15
15
|
"clear",
|
|
16
|
+
"clear-focus",
|
|
17
|
+
"clear-send-hour",
|
|
16
18
|
"confirm",
|
|
17
19
|
"confirm-destructive-changes",
|
|
18
20
|
"disable-applet-follow-ups",
|
|
@@ -26,10 +28,12 @@ const BOOLEAN_FLAGS = new Set([
|
|
|
26
28
|
"keep-tokens",
|
|
27
29
|
"include-deleted",
|
|
28
30
|
"include-archived",
|
|
31
|
+
"include-left",
|
|
29
32
|
"json",
|
|
30
33
|
"mirrored",
|
|
31
34
|
"no-collision",
|
|
32
35
|
"no-invite",
|
|
36
|
+
"no-join",
|
|
33
37
|
"open",
|
|
34
38
|
"refresh",
|
|
35
39
|
"resend",
|
|
@@ -179,6 +183,7 @@ const FAMILY_AI_COMMANDS = new Set([
|
|
|
179
183
|
"goals list",
|
|
180
184
|
"goals move-module",
|
|
181
185
|
"goals pdf upload",
|
|
186
|
+
"goals video upload",
|
|
182
187
|
"goals queue get",
|
|
183
188
|
"goals queue set",
|
|
184
189
|
"goals unarchive",
|
|
@@ -202,6 +207,8 @@ const FAMILY_AI_COMMANDS = new Set([
|
|
|
202
207
|
"tutor-templates unassign",
|
|
203
208
|
]);
|
|
204
209
|
const STAFF_COMMANDS = new Set([
|
|
210
|
+
"rooms transcripts get",
|
|
211
|
+
"rooms transcripts search",
|
|
205
212
|
"cohorts schedule get",
|
|
206
213
|
"cohorts schedule set",
|
|
207
214
|
"cohorts schedule changes",
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { unwrap } from "../api.js";
|
|
5
|
+
import { flagNumber, flagString, hasFlag } from "../args.js";
|
|
6
|
+
import { CliError } from "../errors.js";
|
|
7
|
+
import { assertChoice, positional } from "./shared.js";
|
|
8
|
+
// Runtime mirrors of the generated unions; `satisfies` fails the build if the
|
|
9
|
+
// backend enums move.
|
|
10
|
+
const CHANNEL_TYPES = [
|
|
11
|
+
"COMMUNITY",
|
|
12
|
+
"SYSTEM_GENERATED",
|
|
13
|
+
"COHORT_PARENT",
|
|
14
|
+
"DIRECT_MESSAGE",
|
|
15
|
+
"GROUP_MESSAGE",
|
|
16
|
+
"COURSE_REQUEST",
|
|
17
|
+
"RECESS_EVENT",
|
|
18
|
+
"LFG_GROUP",
|
|
19
|
+
"CHALLENGE_FINISHERS",
|
|
20
|
+
"RECESS",
|
|
21
|
+
"STREAMING",
|
|
22
|
+
];
|
|
23
|
+
const LIST_TYPES = [
|
|
24
|
+
...CHANNEL_TYPES,
|
|
25
|
+
"WORLD",
|
|
26
|
+
];
|
|
27
|
+
const AUDIENCES = ["KID", "PARENT"];
|
|
28
|
+
const STATUSES = [
|
|
29
|
+
"ACTIVE",
|
|
30
|
+
"HIDDEN",
|
|
31
|
+
"ARCHIVED",
|
|
32
|
+
];
|
|
33
|
+
const MEMBER_ROLES = [
|
|
34
|
+
"MEMBER",
|
|
35
|
+
"MODERATOR",
|
|
36
|
+
"ADMIN",
|
|
37
|
+
];
|
|
38
|
+
/** The type set post.channel-image.ts accepts, keyed by extension. */
|
|
39
|
+
const IMAGE_MIME_BY_EXT = {
|
|
40
|
+
".jpg": "image/jpeg",
|
|
41
|
+
".jpeg": "image/jpeg",
|
|
42
|
+
".png": "image/png",
|
|
43
|
+
".gif": "image/gif",
|
|
44
|
+
".webp": "image/webp",
|
|
45
|
+
};
|
|
46
|
+
const MAX_IMAGE_BYTES = 10 * 1024 * 1024;
|
|
47
|
+
async function readChannelImage(filePath) {
|
|
48
|
+
const absolutePath = path.resolve(filePath);
|
|
49
|
+
const mimeType = IMAGE_MIME_BY_EXT[path.extname(absolutePath).toLowerCase()];
|
|
50
|
+
if (!mimeType) {
|
|
51
|
+
throw new CliError("invalid_arguments", "The image must be a .png, .jpg, .jpeg, .gif, or .webp file.");
|
|
52
|
+
}
|
|
53
|
+
let bytes;
|
|
54
|
+
try {
|
|
55
|
+
bytes = await fs.readFile(absolutePath);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (error.code === "ENOENT") {
|
|
59
|
+
throw new CliError("invalid_arguments", `Image file does not exist: ${absolutePath}`);
|
|
60
|
+
}
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
if (bytes.byteLength > MAX_IMAGE_BYTES) {
|
|
64
|
+
throw new CliError("invalid_arguments", "The image must be 10MB or smaller.");
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
bytes,
|
|
68
|
+
fileName: path.basename(absolutePath),
|
|
69
|
+
mimeType,
|
|
70
|
+
sha256: createHash("sha256").update(bytes).digest("hex"),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export async function runChannelsCommand({ parsed, api, writeCommand, }) {
|
|
74
|
+
const verb = parsed.positionals[1];
|
|
75
|
+
if (verb === "list") {
|
|
76
|
+
const type = flagString(parsed, "type");
|
|
77
|
+
const audience = flagString(parsed, "audience");
|
|
78
|
+
const status = flagString(parsed, "status");
|
|
79
|
+
const limit = flagNumber(parsed, "limit");
|
|
80
|
+
if (limit !== undefined &&
|
|
81
|
+
(!Number.isInteger(limit) || limit < 1 || limit > 200)) {
|
|
82
|
+
throw new CliError("invalid_arguments", "--limit must be an integer from 1 to 200.");
|
|
83
|
+
}
|
|
84
|
+
const q = parsed.positionals.slice(2).join(" ").trim();
|
|
85
|
+
return unwrap(await api.client.GET("/admin/channels/", {
|
|
86
|
+
params: {
|
|
87
|
+
query: {
|
|
88
|
+
...(type ? { type: assertChoice(type, LIST_TYPES, "--type") } : {}),
|
|
89
|
+
...(audience
|
|
90
|
+
? { audience: assertChoice(audience, AUDIENCES, "--audience") }
|
|
91
|
+
: {}),
|
|
92
|
+
...(status
|
|
93
|
+
? { status: assertChoice(status, STATUSES, "--status") }
|
|
94
|
+
: {}),
|
|
95
|
+
...(q ? { q } : {}),
|
|
96
|
+
...(limit !== undefined ? { limit } : {}),
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
if (verb === "create") {
|
|
102
|
+
const name = flagString(parsed, "name", { required: true }).trim();
|
|
103
|
+
if (!name || name.length > 100) {
|
|
104
|
+
throw new CliError("invalid_arguments", "--name must be 1 to 100 characters.");
|
|
105
|
+
}
|
|
106
|
+
const type = assertChoice(flagString(parsed, "type") ?? "COMMUNITY", CHANNEL_TYPES, "--type");
|
|
107
|
+
const audienceFlag = flagString(parsed, "audience");
|
|
108
|
+
const audience = audienceFlag === undefined
|
|
109
|
+
? undefined
|
|
110
|
+
: audienceFlag === "NONE"
|
|
111
|
+
? null
|
|
112
|
+
: assertChoice(audienceFlag, AUDIENCES, "--audience");
|
|
113
|
+
const description = flagString(parsed, "description");
|
|
114
|
+
const joinAsAdmin = !hasFlag(parsed, "no-join");
|
|
115
|
+
const imagePath = flagString(parsed, "image");
|
|
116
|
+
const image = imagePath ? await readChannelImage(imagePath) : undefined;
|
|
117
|
+
const body = {
|
|
118
|
+
name,
|
|
119
|
+
type,
|
|
120
|
+
joinAsAdmin,
|
|
121
|
+
...(audience !== undefined ? { audience } : {}),
|
|
122
|
+
...(description !== undefined ? { description } : {}),
|
|
123
|
+
};
|
|
124
|
+
return writeCommand(parsed, {
|
|
125
|
+
action: type === "COMMUNITY"
|
|
126
|
+
? `create a ${audience ?? "KID"}-audience community channel that ${audience === "PARENT" ? "guardians" : "kids"} can find and join from Browse`
|
|
127
|
+
: `create a standalone ${type} channel (not linked to any cohort, event, challenge, or course)`,
|
|
128
|
+
target: { name, type },
|
|
129
|
+
// The image's hash is in the approved request, so confirming with a
|
|
130
|
+
// different file fails the operation-key check.
|
|
131
|
+
request: image
|
|
132
|
+
? {
|
|
133
|
+
...body,
|
|
134
|
+
image: {
|
|
135
|
+
fileName: image.fileName,
|
|
136
|
+
mimeType: image.mimeType,
|
|
137
|
+
bytes: image.bytes.byteLength,
|
|
138
|
+
sha256: image.sha256,
|
|
139
|
+
},
|
|
140
|
+
}
|
|
141
|
+
: body,
|
|
142
|
+
...(joinAsAdmin
|
|
143
|
+
? {}
|
|
144
|
+
: {
|
|
145
|
+
details: {
|
|
146
|
+
note: "You will not be a member; use channels join to enter it.",
|
|
147
|
+
},
|
|
148
|
+
}),
|
|
149
|
+
}, async () => {
|
|
150
|
+
const channel = unwrap(await api.client.POST("/admin/channels/", { body }));
|
|
151
|
+
if (!image)
|
|
152
|
+
return channel;
|
|
153
|
+
try {
|
|
154
|
+
const uploaded = (await api.uploadChannelImage(channel.id, image.bytes, image.fileName, image.mimeType));
|
|
155
|
+
return { ...channel, imageUrl: uploaded.imageUrl };
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
throw new CliError("partial_failure", `Channel ${channel.id} was created, but its image upload failed: ${error instanceof Error ? error.message : String(error)}. Retry with channels set-image ${channel.id} <path>.`, 1, { channel });
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
if (verb === "set-image") {
|
|
163
|
+
const channelId = positional(parsed, 2, "channel ID");
|
|
164
|
+
const imagePath = parsed.positionals[3];
|
|
165
|
+
const clear = hasFlag(parsed, "clear");
|
|
166
|
+
if (clear === Boolean(imagePath)) {
|
|
167
|
+
throw new CliError("invalid_arguments", "Pass an image path or --clear (not both).");
|
|
168
|
+
}
|
|
169
|
+
if (clear) {
|
|
170
|
+
return writeCommand(parsed, {
|
|
171
|
+
action: "remove the channel's image",
|
|
172
|
+
target: { channelId },
|
|
173
|
+
request: { clear: true },
|
|
174
|
+
}, async () => unwrap(await api.client.DELETE("/admin/channels/{channelId}/image", {
|
|
175
|
+
params: { path: { channelId } },
|
|
176
|
+
})));
|
|
177
|
+
}
|
|
178
|
+
const image = await readChannelImage(imagePath);
|
|
179
|
+
return writeCommand(parsed, {
|
|
180
|
+
action: "upload this image and set it as the channel's image",
|
|
181
|
+
target: { channelId },
|
|
182
|
+
request: {
|
|
183
|
+
fileName: image.fileName,
|
|
184
|
+
mimeType: image.mimeType,
|
|
185
|
+
bytes: image.bytes.byteLength,
|
|
186
|
+
sha256: image.sha256,
|
|
187
|
+
},
|
|
188
|
+
}, async () => api.uploadChannelImage(channelId, image.bytes, image.fileName, image.mimeType));
|
|
189
|
+
}
|
|
190
|
+
if (verb === "join") {
|
|
191
|
+
const channelId = positional(parsed, 2, "channel ID");
|
|
192
|
+
const body = { channelId };
|
|
193
|
+
return writeCommand(parsed, {
|
|
194
|
+
action: "join the channel yourself (rejoins if you left)",
|
|
195
|
+
target: { channelId },
|
|
196
|
+
request: body,
|
|
197
|
+
}, async () => unwrap(await api.client.POST("/admin/channels/join/", { body })));
|
|
198
|
+
}
|
|
199
|
+
if (verb === "members") {
|
|
200
|
+
const action = parsed.positionals[2];
|
|
201
|
+
const channelId = positional(parsed, 3, "channel ID");
|
|
202
|
+
if (action === "list") {
|
|
203
|
+
return unwrap(await api.client.GET("/admin/channels/{channelId}/members", {
|
|
204
|
+
params: {
|
|
205
|
+
path: { channelId },
|
|
206
|
+
query: {
|
|
207
|
+
includeLeft: hasFlag(parsed, "include-left") ? "true" : "false",
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
}));
|
|
211
|
+
}
|
|
212
|
+
if (action === "add" || action === "set-role" || action === "remove") {
|
|
213
|
+
const userIds = parsed.positionals.slice(4);
|
|
214
|
+
if (userIds.length === 0) {
|
|
215
|
+
throw new CliError("invalid_arguments", "Pass at least one user ID.");
|
|
216
|
+
}
|
|
217
|
+
if (new Set(userIds).size !== userIds.length) {
|
|
218
|
+
throw new CliError("invalid_arguments", "User IDs must be unique.");
|
|
219
|
+
}
|
|
220
|
+
// Read-only preflight: the approval preview names the exact channel
|
|
221
|
+
// (and audience) people are entering or leaving. Only stable fields go
|
|
222
|
+
// in the preview, since the operation key is bound to its hash.
|
|
223
|
+
const current = unwrap(await api.client.GET("/admin/channels/{channelId}/members", {
|
|
224
|
+
params: { path: { channelId }, query: { includeLeft: "false" } },
|
|
225
|
+
}));
|
|
226
|
+
const channel = {
|
|
227
|
+
name: current.channel.name,
|
|
228
|
+
type: current.channel.type,
|
|
229
|
+
audience: current.channel.audience,
|
|
230
|
+
status: current.channel.status,
|
|
231
|
+
};
|
|
232
|
+
if (action === "remove") {
|
|
233
|
+
const active = new Set(current.members.map((m) => m.userId));
|
|
234
|
+
const notMembers = userIds.filter((id) => !active.has(id));
|
|
235
|
+
if (notMembers.length > 0) {
|
|
236
|
+
throw new CliError("invalid_arguments", `Not active members of this channel: ${notMembers.join(", ")}`);
|
|
237
|
+
}
|
|
238
|
+
return writeCommand(parsed, {
|
|
239
|
+
action: `remove ${userIds.length} member(s) from the channel (soft: they can be re-added; a LEFT notice posts in the channel)`,
|
|
240
|
+
target: { channelId, userIds },
|
|
241
|
+
request: { userIds },
|
|
242
|
+
details: { channel },
|
|
243
|
+
}, async () => unwrap(await api.client.POST("/admin/channels/{channelId}/members/remove", { params: { path: { channelId } }, body: { userIds } })));
|
|
244
|
+
}
|
|
245
|
+
const role = assertChoice(flagString(parsed, "role", { required: action === "set-role" }) ??
|
|
246
|
+
"MEMBER", MEMBER_ROLES, "--role");
|
|
247
|
+
if (action === "set-role") {
|
|
248
|
+
const active = new Set(current.members.map((m) => m.userId));
|
|
249
|
+
const notMembers = userIds.filter((id) => !active.has(id));
|
|
250
|
+
if (notMembers.length > 0) {
|
|
251
|
+
throw new CliError("invalid_arguments", `Not active members (use members add): ${notMembers.join(", ")}`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const body = { userIds, role };
|
|
255
|
+
return writeCommand(parsed, {
|
|
256
|
+
action: action === "set-role"
|
|
257
|
+
? `set the channel role of ${userIds.length} member(s) to ${role}`
|
|
258
|
+
: `add ${userIds.length} user(s) to the channel as ${role} (a JOINED notice posts for each new arrival)`,
|
|
259
|
+
target: { channelId, userIds },
|
|
260
|
+
request: body,
|
|
261
|
+
details: { channel },
|
|
262
|
+
}, async () => unwrap(await api.client.POST("/admin/channels/{channelId}/members", {
|
|
263
|
+
params: { path: { channelId } },
|
|
264
|
+
body,
|
|
265
|
+
})));
|
|
266
|
+
}
|
|
267
|
+
throw new CliError("invalid_arguments", "Use channels members list|add|set-role|remove <channel-id> ...");
|
|
268
|
+
}
|
|
269
|
+
throw new CliError("invalid_arguments", "Use channels list|create|set-image|join or channels members list|add|set-role|remove.");
|
|
270
|
+
}
|
|
271
|
+
//# sourceMappingURL=channels.js.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { unwrap } from "../api.js";
|
|
4
|
+
import { flagNumber, flagString } from "../args.js";
|
|
5
|
+
import { CliError } from "../errors.js";
|
|
6
|
+
import { positional } from "./shared.js";
|
|
7
|
+
const MAX_ROW_LIMIT = 5000;
|
|
8
|
+
async function readSql(parsed) {
|
|
9
|
+
const inline = parsed.positionals[2];
|
|
10
|
+
const file = flagString(parsed, "file");
|
|
11
|
+
if ((inline === undefined) === (file === undefined)) {
|
|
12
|
+
throw new CliError("invalid_arguments", "Pass the SQL either as one quoted argument or with --file <path>, not both.");
|
|
13
|
+
}
|
|
14
|
+
if (inline !== undefined)
|
|
15
|
+
return { sql: inline };
|
|
16
|
+
const absolutePath = path.resolve(file);
|
|
17
|
+
const sql = await fs.readFile(absolutePath, "utf8").catch(() => {
|
|
18
|
+
throw new CliError("invalid_arguments", `Cannot read ${absolutePath}.`);
|
|
19
|
+
});
|
|
20
|
+
return { sql, file: absolutePath };
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* `recess db query` — one read-only SQL query against the product database,
|
|
24
|
+
* for ADMINs holding `cli:db-query`; `recess db access` — list/grant/revoke
|
|
25
|
+
* that access, for `cli:db-query:grant` holders. The server owns every check
|
|
26
|
+
* (live role + access role, restricted Postgres login); a query is a read, so
|
|
27
|
+
* it needs no confirmation.
|
|
28
|
+
*/
|
|
29
|
+
export async function runDbCommand({ parsed, api, writeCommand, }) {
|
|
30
|
+
const verb = parsed.positionals[1];
|
|
31
|
+
if (verb === "query") {
|
|
32
|
+
const { sql, file } = await readSql(parsed);
|
|
33
|
+
const rowLimit = flagNumber(parsed, "limit") ?? 100;
|
|
34
|
+
if (!Number.isInteger(rowLimit) ||
|
|
35
|
+
rowLimit < 1 ||
|
|
36
|
+
rowLimit > MAX_ROW_LIMIT) {
|
|
37
|
+
throw new CliError("invalid_arguments", `--limit must be an integer from 1 to ${MAX_ROW_LIMIT}.`);
|
|
38
|
+
}
|
|
39
|
+
const result = unwrap(await api.client.POST("/admin/db-query/query/", {
|
|
40
|
+
body: { sql, rowLimit },
|
|
41
|
+
}));
|
|
42
|
+
return file ? { file, ...result } : result;
|
|
43
|
+
}
|
|
44
|
+
if (verb === "access") {
|
|
45
|
+
const action = positional(parsed, 2, "access action (list|grant|revoke)");
|
|
46
|
+
if (action === "list") {
|
|
47
|
+
return unwrap(await api.client.GET("/admin/db-query/grants/"));
|
|
48
|
+
}
|
|
49
|
+
if (action !== "grant" && action !== "revoke") {
|
|
50
|
+
throw new CliError("invalid_arguments", "Use db access list|grant|revoke.");
|
|
51
|
+
}
|
|
52
|
+
const userId = flagString(parsed, "user", { required: true });
|
|
53
|
+
// Read-only preflight: the approval must name the exact person gaining or
|
|
54
|
+
// losing global database read access.
|
|
55
|
+
const { user } = unwrap(await api.client.GET("/admin/users/{userId}", {
|
|
56
|
+
params: { path: { userId } },
|
|
57
|
+
}));
|
|
58
|
+
if (action === "grant" && user.role !== "ADMIN") {
|
|
59
|
+
throw new CliError("invalid_arguments", `User ${userId} has role ${user.role}; database query access is ADMIN-only.`);
|
|
60
|
+
}
|
|
61
|
+
const body = { userId, action };
|
|
62
|
+
return writeCommand(parsed, {
|
|
63
|
+
action: action === "grant"
|
|
64
|
+
? "grant global read-only database query access (recess db query) to this admin"
|
|
65
|
+
: "revoke this user's database query access",
|
|
66
|
+
target: { userId },
|
|
67
|
+
request: body,
|
|
68
|
+
details: {
|
|
69
|
+
email: user.email,
|
|
70
|
+
firstName: user.firstName,
|
|
71
|
+
lastName: user.lastName,
|
|
72
|
+
role: user.role,
|
|
73
|
+
},
|
|
74
|
+
}, async () => unwrap(await api.client.POST("/admin/db-query/grants/", { body })));
|
|
75
|
+
}
|
|
76
|
+
throw new CliError("invalid_arguments", "Use db query|access.");
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=db.js.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { unwrap } from "../api.js";
|
|
3
|
+
import { flagString } from "../args.js";
|
|
4
|
+
import { CliError } from "../errors.js";
|
|
5
|
+
import { readJsonValue } from "./shared.js";
|
|
6
|
+
export async function runFamiliesCommand({ parsed, api, writeCommand, }) {
|
|
7
|
+
const verb = parsed.positionals[1];
|
|
8
|
+
if (verb === "set-addresses") {
|
|
9
|
+
const filePath = flagString(parsed, "file", { required: true });
|
|
10
|
+
const { absolutePath, raw, parsed: json, } = await readJsonValue(filePath, "Address file");
|
|
11
|
+
if (!Array.isArray(json) || json.length === 0) {
|
|
12
|
+
throw new CliError("invalid_arguments", `Address file must be a non-empty JSON array of {familyId, postalCode?, stateRegion?, city?, streetAddress?, country?, source} (${absolutePath}).`);
|
|
13
|
+
}
|
|
14
|
+
const entries = json;
|
|
15
|
+
const sha256 = createHash("sha256").update(raw).digest("hex");
|
|
16
|
+
// Read-only preflight: the server's dry run validates every entry and
|
|
17
|
+
// returns each family's current and proposed address for the approval.
|
|
18
|
+
const dryRun = unwrap(await api.client.POST("/admin/users/family-addresses/", {
|
|
19
|
+
body: { dryRun: true, entries },
|
|
20
|
+
}));
|
|
21
|
+
const changes = dryRun.results.filter((r) => r.changed);
|
|
22
|
+
return writeCommand(parsed, {
|
|
23
|
+
action: `set household addresses on ${changes.length} of ${entries.length} families (the rest already match)`,
|
|
24
|
+
target: { families: entries.length },
|
|
25
|
+
request: { file: absolutePath, sha256, entries: entries.length },
|
|
26
|
+
details: {
|
|
27
|
+
changes: changes.map((r) => ({
|
|
28
|
+
familyId: r.familyId,
|
|
29
|
+
before: r.before,
|
|
30
|
+
after: r.after,
|
|
31
|
+
})),
|
|
32
|
+
},
|
|
33
|
+
}, async () => unwrap(await api.client.POST("/admin/users/family-addresses/", {
|
|
34
|
+
body: { dryRun: false, entries },
|
|
35
|
+
})));
|
|
36
|
+
}
|
|
37
|
+
throw new CliError("invalid_arguments", "Use families set-addresses.");
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=families.js.map
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { unwrap } from "../api.js";
|
|
2
|
+
import { flagString, hasFlag } from "../args.js";
|
|
3
|
+
import { CliError } from "../errors.js";
|
|
4
|
+
import { assertChoice, flagBooleanValue, flagInteger, positional, } from "./shared.js";
|
|
5
|
+
const TEXT_FREQUENCIES = ["all", "daily", "important"];
|
|
6
|
+
function fullName(user) {
|
|
7
|
+
return [user.firstName, user.lastName].filter(Boolean).join(" ");
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* `users phone get|set|clear` — a user's SMS/login phone number. The server
|
|
11
|
+
* normalizes whatever is typed to E.164 (bare numbers read as US) and rejects
|
|
12
|
+
* invalid or already-taken numbers, so the preview shows the raw input.
|
|
13
|
+
*/
|
|
14
|
+
export async function runUsersPhoneCommand({ parsed, api, writeCommand, }) {
|
|
15
|
+
const action = positional(parsed, 2, "users phone action");
|
|
16
|
+
if (!["get", "set", "clear"].includes(action)) {
|
|
17
|
+
throw new CliError("invalid_arguments", "Use users phone get|set|clear.");
|
|
18
|
+
}
|
|
19
|
+
const userId = positional(parsed, 3, "user ID");
|
|
20
|
+
const phoneNumber = action === "set" ? flagString(parsed, "phone", { required: true }) : null;
|
|
21
|
+
const { user } = unwrap(await api.client.GET("/admin/users/{userId}", {
|
|
22
|
+
params: { path: { userId } },
|
|
23
|
+
}));
|
|
24
|
+
const current = {
|
|
25
|
+
userId: user.id,
|
|
26
|
+
name: fullName(user),
|
|
27
|
+
role: user.role,
|
|
28
|
+
phoneNumber: user.phoneNumber ?? null,
|
|
29
|
+
};
|
|
30
|
+
if (action === "get")
|
|
31
|
+
return current;
|
|
32
|
+
return writeCommand(parsed, {
|
|
33
|
+
action: phoneNumber === null
|
|
34
|
+
? "remove the user's phone number (they stop receiving SMS and can't sign in by phone)"
|
|
35
|
+
: "set the user's phone number (stored as E.164 and marked unverified until their next phone sign-in)",
|
|
36
|
+
target: { userId: user.id },
|
|
37
|
+
request: { phoneNumber },
|
|
38
|
+
details: { current },
|
|
39
|
+
}, async () => {
|
|
40
|
+
const result = unwrap(await api.client.PATCH("/admin/users/{userId}", {
|
|
41
|
+
params: { path: { userId: user.id } },
|
|
42
|
+
body: { phoneNumber },
|
|
43
|
+
}));
|
|
44
|
+
return { ...current, phoneNumber: result.phoneNumber ?? null };
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* `students texts get|set|set-guardian` — the parent SMS activity-summary
|
|
49
|
+
* controls. Student-level: summary on/off and the end-of-day send hour (in the
|
|
50
|
+
* student's timezone). Per guardian: texts on/off, frequency, and the custom
|
|
51
|
+
* focus instructions that steer that guardian's summaries.
|
|
52
|
+
*/
|
|
53
|
+
export async function runStudentsTextsCommand({ parsed, api, writeCommand, }) {
|
|
54
|
+
const action = positional(parsed, 2, "students texts action");
|
|
55
|
+
if (!["get", "set", "set-guardian"].includes(action)) {
|
|
56
|
+
throw new CliError("invalid_arguments", "Use students texts get|set|set-guardian.");
|
|
57
|
+
}
|
|
58
|
+
const studentId = positional(parsed, 3, "student ID");
|
|
59
|
+
// Validate every flag before the first request.
|
|
60
|
+
const studentBody = action === "set" ? studentTextsBody(parsed) : undefined;
|
|
61
|
+
const guardianId = action === "set-guardian" ? positional(parsed, 4, "guardian ID") : "";
|
|
62
|
+
const guardianBody = action === "set-guardian" ? guardianTextsBody(parsed) : undefined;
|
|
63
|
+
const readSettings = async () => {
|
|
64
|
+
const [profile, focuses] = await Promise.all([
|
|
65
|
+
api.client.GET("/tutor/students/{studentId}/profile", {
|
|
66
|
+
params: { path: { studentId } },
|
|
67
|
+
}),
|
|
68
|
+
api.client.GET("/admin/browser/students/{userId}/guardian-focuses/", {
|
|
69
|
+
params: { path: { userId: studentId } },
|
|
70
|
+
}),
|
|
71
|
+
]);
|
|
72
|
+
const student = unwrap(profile);
|
|
73
|
+
return {
|
|
74
|
+
studentId,
|
|
75
|
+
timezone: student.timezone,
|
|
76
|
+
summaryEnabled: student.dailySummaryEnabled,
|
|
77
|
+
sendHour: student.dailySummarySendHour,
|
|
78
|
+
recipients: unwrap(focuses).guardians.map((guardian) => ({
|
|
79
|
+
guardianId: guardian.guardianId,
|
|
80
|
+
name: fullName(guardian),
|
|
81
|
+
email: guardian.email,
|
|
82
|
+
phoneNumber: guardian.phoneNumber,
|
|
83
|
+
isFamilyMember: guardian.isFamilyMember,
|
|
84
|
+
hasSubscription: guardian.hasSubscription,
|
|
85
|
+
textsEnabled: guardian.textsEnabled,
|
|
86
|
+
textFrequency: guardian.textFrequency,
|
|
87
|
+
focus: guardian.dailySummaryFocus,
|
|
88
|
+
})),
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
const current = await readSettings();
|
|
92
|
+
if (action === "get")
|
|
93
|
+
return current;
|
|
94
|
+
if (studentBody) {
|
|
95
|
+
return writeCommand(parsed, {
|
|
96
|
+
action: "update the student's parent SMS summary settings (applies to every recipient)",
|
|
97
|
+
target: { studentId },
|
|
98
|
+
request: studentBody,
|
|
99
|
+
details: {
|
|
100
|
+
current: {
|
|
101
|
+
summaryEnabled: current.summaryEnabled,
|
|
102
|
+
sendHour: current.sendHour,
|
|
103
|
+
timezone: current.timezone,
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
}, async () => {
|
|
107
|
+
unwrap(await api.client.PATCH("/tutor/students/{studentId}/profile", {
|
|
108
|
+
params: { path: { studentId } },
|
|
109
|
+
body: studentBody,
|
|
110
|
+
}));
|
|
111
|
+
return readSettings();
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const recipient = current.recipients.find((r) => r.guardianId === guardianId) ?? null;
|
|
115
|
+
return writeCommand(parsed, {
|
|
116
|
+
action: recipient
|
|
117
|
+
? "update this recipient's SMS settings for the student"
|
|
118
|
+
: "subscribe a new recipient to the student's SMS summaries (only ADMINs may be subscribed across families)",
|
|
119
|
+
target: { studentId, guardianId },
|
|
120
|
+
request: guardianBody,
|
|
121
|
+
details: { current: recipient },
|
|
122
|
+
}, async () => unwrap(await api.client.PATCH("/admin/browser/students/{userId}/guardian-focuses/{guardianId}/", {
|
|
123
|
+
params: { path: { userId: studentId, guardianId } },
|
|
124
|
+
body: guardianBody,
|
|
125
|
+
})));
|
|
126
|
+
}
|
|
127
|
+
function studentTextsBody(parsed) {
|
|
128
|
+
const summaryEnabled = flagBooleanValue(parsed, "summary-enabled");
|
|
129
|
+
const clearSendHour = hasFlag(parsed, "clear-send-hour");
|
|
130
|
+
const sendHour = flagInteger(parsed, "send-hour", { min: 0, max: 23 });
|
|
131
|
+
if (clearSendHour && sendHour !== undefined) {
|
|
132
|
+
throw new CliError("invalid_arguments", "Pass --send-hour or --clear-send-hour, not both.");
|
|
133
|
+
}
|
|
134
|
+
const body = {
|
|
135
|
+
...(summaryEnabled !== undefined && {
|
|
136
|
+
dailySummaryEnabled: summaryEnabled,
|
|
137
|
+
}),
|
|
138
|
+
...(sendHour !== undefined && { dailySummarySendHour: sendHour }),
|
|
139
|
+
...(clearSendHour && { dailySummarySendHour: null }),
|
|
140
|
+
};
|
|
141
|
+
if (Object.keys(body).length === 0) {
|
|
142
|
+
throw new CliError("invalid_arguments", "Pass at least one of --summary-enabled, --send-hour, --clear-send-hour.");
|
|
143
|
+
}
|
|
144
|
+
return body;
|
|
145
|
+
}
|
|
146
|
+
function guardianTextsBody(parsed) {
|
|
147
|
+
const textsEnabled = flagBooleanValue(parsed, "texts-enabled");
|
|
148
|
+
const frequency = flagString(parsed, "frequency");
|
|
149
|
+
const focus = flagString(parsed, "focus");
|
|
150
|
+
const clearFocus = hasFlag(parsed, "clear-focus");
|
|
151
|
+
if (focus !== undefined && clearFocus) {
|
|
152
|
+
throw new CliError("invalid_arguments", "Pass --focus or --clear-focus, not both.");
|
|
153
|
+
}
|
|
154
|
+
const body = {
|
|
155
|
+
...(textsEnabled !== undefined && { textsEnabled }),
|
|
156
|
+
...(frequency !== undefined && {
|
|
157
|
+
textFrequency: assertChoice(frequency, TEXT_FREQUENCIES, "--frequency").toUpperCase(),
|
|
158
|
+
}),
|
|
159
|
+
...(focus !== undefined && { dailySummaryFocus: focus }),
|
|
160
|
+
...(clearFocus && { dailySummaryFocus: null }),
|
|
161
|
+
};
|
|
162
|
+
if (Object.keys(body).length === 0) {
|
|
163
|
+
throw new CliError("invalid_arguments", "Pass at least one of --texts-enabled, --frequency, --focus, --clear-focus.");
|
|
164
|
+
}
|
|
165
|
+
return body;
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=phone-and-texts.js.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { unwrap } from "../api.js";
|
|
2
|
+
import { flagNumber, flagString } from "../args.js";
|
|
3
|
+
import { CliError } from "../errors.js";
|
|
4
|
+
import { positional } from "./shared.js";
|
|
5
|
+
const DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
6
|
+
function dateFlag(parsed, name) {
|
|
7
|
+
const value = flagString(parsed, name);
|
|
8
|
+
if (value !== undefined && !DATE.test(value)) {
|
|
9
|
+
throw new CliError("invalid_arguments", `--${name} must be YYYY-MM-DD.`);
|
|
10
|
+
}
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
function intFlag(parsed, name, min, max) {
|
|
14
|
+
const value = flagNumber(parsed, name);
|
|
15
|
+
if (value !== undefined &&
|
|
16
|
+
(!Number.isInteger(value) || value < min || value > max)) {
|
|
17
|
+
throw new CliError("invalid_arguments", `--${name} must be an integer from ${min} to ${max}.`);
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
export async function runRoomsCommand({ parsed, api, }) {
|
|
22
|
+
const group = parsed.positionals[1];
|
|
23
|
+
const verb = parsed.positionals[2];
|
|
24
|
+
if (group !== "transcripts" || (verb !== "search" && verb !== "get")) {
|
|
25
|
+
throw new CliError("invalid_arguments", "Use `rooms transcripts search` or `rooms transcripts get <meeting-id>`.");
|
|
26
|
+
}
|
|
27
|
+
if (verb === "search") {
|
|
28
|
+
return unwrap(await api.client.GET("/voice/room-transcripts/", {
|
|
29
|
+
params: {
|
|
30
|
+
query: {
|
|
31
|
+
roomName: flagString(parsed, "room"),
|
|
32
|
+
startDate: dateFlag(parsed, "from"),
|
|
33
|
+
endDate: dateFlag(parsed, "to"),
|
|
34
|
+
query: flagString(parsed, "query"),
|
|
35
|
+
limit: intFlag(parsed, "limit", 1, 20),
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
const meetingId = positional(parsed, 3, "meeting ID");
|
|
41
|
+
const breakoutIndex = intFlag(parsed, "breakout", 0, 1000);
|
|
42
|
+
const query = flagString(parsed, "query");
|
|
43
|
+
const read = (offset) => api.client.GET("/voice/room-transcripts/{meetingId}", {
|
|
44
|
+
params: {
|
|
45
|
+
path: { meetingId },
|
|
46
|
+
query: { breakoutIndex, query, offset, maxChars: 30000 },
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
const first = unwrap(await read());
|
|
50
|
+
if (query || first.text === undefined)
|
|
51
|
+
return first;
|
|
52
|
+
let text = first.text;
|
|
53
|
+
let next = first.nextOffset ?? null;
|
|
54
|
+
while (next !== null) {
|
|
55
|
+
const page = unwrap(await read(next));
|
|
56
|
+
if (page.offset !== next || page.text === undefined) {
|
|
57
|
+
throw new CliError("pagination_error", "Transcript pagination did not advance; no complete download was produced.");
|
|
58
|
+
}
|
|
59
|
+
text += page.text;
|
|
60
|
+
next = page.nextOffset ?? null;
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
...first,
|
|
64
|
+
offset: 0,
|
|
65
|
+
nextOffset: null,
|
|
66
|
+
text,
|
|
67
|
+
complete: true,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=rooms.js.map
|
package/dist/help.js
CHANGED
|
@@ -47,6 +47,9 @@ Usage:
|
|
|
47
47
|
recess [--json] users enrollment set <user-id>
|
|
48
48
|
--entity online-learning-program|recess-academy-school|partner-school|unset
|
|
49
49
|
[--partner-school <school-id-or-slug>] [--confirm]
|
|
50
|
+
recess [--json] users phone get <user-id>
|
|
51
|
+
recess [--json] users phone set <user-id> --phone <number> [--confirm]
|
|
52
|
+
recess [--json] users phone clear <user-id> [--confirm]
|
|
50
53
|
recess [--json] users lock <user-id> [--confirm]
|
|
51
54
|
recess [--json] users unlock <user-id> [--confirm]
|
|
52
55
|
recess [--json] users disable <user-id> [--whole-family] [--allow-billing] [--confirm]
|
|
@@ -62,11 +65,20 @@ Usage:
|
|
|
62
65
|
recess [--json] guides invite --user <user-id> [--confirm]
|
|
63
66
|
recess [--json] guardians invite --family <family-id> --email <email>
|
|
64
67
|
--first-name TEXT [--last-name TEXT] [--no-invite] [--confirm]
|
|
68
|
+
recess [--json] students texts get <kid-id>
|
|
69
|
+
recess [--json] students texts set <kid-id> [--summary-enabled true|false]
|
|
70
|
+
[--send-hour <0-23> | --clear-send-hour] [--confirm]
|
|
71
|
+
recess [--json] students texts set-guardian <kid-id> <guardian-id>
|
|
72
|
+
[--texts-enabled true|false] [--frequency all|daily|important]
|
|
73
|
+
[--focus <text> | --clear-focus] [--confirm]
|
|
65
74
|
recess [--json] students upload-map-scores --student <kid-id>
|
|
66
75
|
--file </path/to/map-report.pdf> [--confirm]
|
|
67
76
|
recess [--json] chat-logs list --student <user-id> [--limit 100] [--cursor <cursor>]
|
|
68
77
|
recess [--json] chat-logs get <conversation-id>
|
|
69
78
|
recess [--json] chat-logs by-todo <todo-id>
|
|
79
|
+
recess [--json] rooms transcripts search [--room TEXT] [--from YYYY-MM-DD]
|
|
80
|
+
[--to YYYY-MM-DD] [--query TEXT] [--limit 10]
|
|
81
|
+
recess [--json] rooms transcripts get <meeting-id> [--breakout <n>] [--query TEXT]
|
|
70
82
|
recess [--json] students list [--scope mine|family]
|
|
71
83
|
recess [--json] students today --student <kid-id> [--date YYYY-MM-DD]
|
|
72
84
|
recess [--json] students schedule --student <kid-id> [--days 14]
|
|
@@ -160,6 +172,17 @@ Usage:
|
|
|
160
172
|
recess [--json] payout items edit <item-id> [--amount-cents N]
|
|
161
173
|
[--description TEXT] [--date YYYY-MM-DD] [--confirm]
|
|
162
174
|
recess [--json] payout items delete <item-id> [--confirm]
|
|
175
|
+
recess [--json] families set-addresses --file <json> [--confirm]
|
|
176
|
+
recess [--json] channels list [<query>...] [--type <channel-type>] [--audience KID|PARENT]
|
|
177
|
+
[--status ACTIVE|HIDDEN|ARCHIVED] [--limit 1..200]
|
|
178
|
+
recess [--json] channels create --name TEXT [--type <channel-type>]
|
|
179
|
+
[--audience KID|PARENT|NONE] [--description TEXT] [--image <path>] [--no-join] [--confirm]
|
|
180
|
+
recess [--json] channels set-image <channel-id> [path] [--clear] [--confirm]
|
|
181
|
+
recess [--json] channels join <channel-id> [--confirm]
|
|
182
|
+
recess [--json] channels members list <channel-id> [--include-left]
|
|
183
|
+
recess [--json] channels members add <channel-id> <user-id...> [--role MEMBER|MODERATOR|ADMIN] [--confirm]
|
|
184
|
+
recess [--json] channels members set-role <channel-id> <user-id...> --role MEMBER|MODERATOR|ADMIN [--confirm]
|
|
185
|
+
recess [--json] channels members remove <channel-id> <user-id...> [--confirm]
|
|
163
186
|
recess [--json] cohorts get <cohort-id> [--events-tab ACTIVE|ENDED|CANCELED|ARCHIVED]
|
|
164
187
|
recess [--json] cohorts schedule get <cohort-id>
|
|
165
188
|
recess [--json] cohorts schedule set <cohort-id> --days <MO,WE> --time <09:30> [--timezone <zone>] --effective-date <YYYY-MM-DD> --notify none|parents [--confirm] [--approval-token <token>]
|
|
@@ -338,6 +361,10 @@ Usage:
|
|
|
338
361
|
[--sort-order asc|desc]
|
|
339
362
|
recess [--json] store-items set-status <village-store-item-id>
|
|
340
363
|
--status ACTIVE|INACTIVE|COMING_SOON [--confirm]
|
|
364
|
+
recess [--json] db query [sql] [--file <path.sql>] [--limit 100]
|
|
365
|
+
recess [--json] db access list
|
|
366
|
+
recess [--json] db access grant --user <user-id> [--confirm]
|
|
367
|
+
recess [--json] db access revoke --user <user-id> [--confirm]
|
|
341
368
|
recess [--json] content-library search <query> [--limit 8]
|
|
342
369
|
recess [--json] content-library status <gem-id-or-url>
|
|
343
370
|
recess [--json] content-library set-stage [<gem-id-or-url>...] [--file <path>]
|
|
@@ -490,6 +517,8 @@ Usage:
|
|
|
490
517
|
(--goal <goal-id> | --draft <draft-slug>) --source-file <local.pdf>
|
|
491
518
|
[--path uploads/name.pdf] [--message TEXT]
|
|
492
519
|
[--confirm --approval-token TOKEN]
|
|
520
|
+
recess [--json] goals video upload --source-file <local.mp4>
|
|
521
|
+
[--confirm --approval-token TOKEN]
|
|
493
522
|
|
|
494
523
|
Authoring notes: "skills" serves the in-product tutor skills (the private
|
|
495
524
|
packages/skills workspace package) read-only over your admin session — they are never
|
|
@@ -568,6 +597,19 @@ what the account was; ADMIN and MODERATOR are not restorable from the CLI.
|
|
|
568
597
|
Note that after a disable "users get" and "users search" no longer resolve the
|
|
569
598
|
account — the confirmed write's own response is the record of what changed.
|
|
570
599
|
|
|
600
|
+
"users phone set" accepts any common format; the server stores E.164 (a number
|
|
601
|
+
without +country is read as US), rejects invalid or already-taken numbers, and
|
|
602
|
+
marks the new number unverified until the user's next phone sign-in.
|
|
603
|
+
|
|
604
|
+
Parent SMS summary notes: "students texts get" shows the kid-level switch and
|
|
605
|
+
end-of-day send hour (0-23 in the kid's timezone; unset = 18) plus every
|
|
606
|
+
recipient's phone, texts on/off, frequency, and focus. "set" changes the
|
|
607
|
+
kid-level switch/hour for all recipients. "set-guardian" changes one adult's
|
|
608
|
+
settings: --frequency all = per-todo texts + daily summary, daily = the daily
|
|
609
|
+
summary only, important = only non-routine summaries; --focus is that adult's
|
|
610
|
+
custom instructions for what the summary should emphasize. A recipient with no
|
|
611
|
+
phone number receives nothing, so check "users phone get" too.
|
|
612
|
+
|
|
571
613
|
Onboarding notes: "status" and "intake-session" are reads — "intake-session"
|
|
572
614
|
looks up the current IN_PROGRESS session without creating one (prints a "none
|
|
573
615
|
yet" result when absent). "intake-session-create" is the explicit write that
|
|
@@ -587,6 +629,25 @@ Class-ops notes: "events cancel" notifies families (chat + parent email blast +
|
|
|
587
629
|
credit notes + Slack); "events set-status --status CANCELED" is a silent status
|
|
588
630
|
change. Reschedule times are cohort-local wall-clock (zoneless).
|
|
589
631
|
|
|
632
|
+
Channel notes: channel types are COMMUNITY (default), SYSTEM_GENERATED,
|
|
633
|
+
COHORT_PARENT, DIRECT_MESSAGE, GROUP_MESSAGE, COURSE_REQUEST, RECESS_EVENT,
|
|
634
|
+
LFG_GROUP, CHALLENGE_FINISHERS, RECESS, STREAMING; WORLD channels belong to
|
|
635
|
+
apps/world and can only be listed. Guardians browse PARENT-audience COMMUNITY
|
|
636
|
+
channels and kids browse KID ones; "create" defaults a COMMUNITY channel to KID
|
|
637
|
+
and COHORT_PARENT to PARENT (--audience NONE clears it). Non-community types
|
|
638
|
+
created here stand alone: nothing links them to a cohort, event, challenge, or
|
|
639
|
+
course. "members add" also rejoins past members and applies --role to everyone
|
|
640
|
+
named; kids are refused from PARENT-audience and COHORT_PARENT channels.
|
|
641
|
+
"members remove" is soft (sets leftAt) and posts a LEFT notice. Images
|
|
642
|
+
(--image, set-image) are .png/.jpg/.gif/.webp, 10MB max.
|
|
643
|
+
|
|
644
|
+
Family address notes: "families set-addresses --file" takes a JSON array of
|
|
645
|
+
{familyId, streetAddress?, city?, stateRegion?, postalCode?, country?, source},
|
|
646
|
+
source one of PARENT|STAFF|APPLICATION|LIGHTFIELD|STRIPE. Country is ISO-2 and
|
|
647
|
+
omitted for US; US ZIPs must be 12345 or 12345-6789. Each entry replaces the
|
|
648
|
+
family's whole address. The preview is the server's dry run: before and after
|
|
649
|
+
for every family that changes.
|
|
650
|
+
|
|
590
651
|
Payout notes: amounts are integer cents. "payout items add" without --date
|
|
591
652
|
defaults the item date to the penultimate day of the invoice's cycle (its
|
|
592
653
|
endDate minus one day) and shows the computed date in the preview.
|