recess-cli 3.19.2 → 3.20.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.
@@ -0,0 +1,1111 @@
1
+ import { createHash } from "node:crypto";
2
+ import { unwrap } from "../api.js";
3
+ import { flagString, hasFlag } from "../args.js";
4
+ import { apiError, CliError } from "../errors.js";
5
+ import { assertChoice, flagBooleanValue, flagIdList, flagInteger, } from "./shared.js";
6
+ // packages/web-schema COMMUNITY_HOUR_COURSE_ID: the daily coworking pods are
7
+ // this course's event series (apps/web `$lib/onboarding/cowork.ts`).
8
+ const COWORK_COURSE_ID = "b96a9f7d-7851-4506-965e-2d9babd50b11";
9
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
10
+ // Server default when a kid's dailySummarySendHour is null (6pm, kid's local time).
11
+ const DEFAULT_SUMMARY_SEND_HOUR = 18;
12
+ // lesson-notes.ts LESSON_NOTE_MAX_CHARS: the server's goal-note cap.
13
+ const GOAL_NOTE_MAX_CHARS = 2000;
14
+ const DATE = /^\d{4}-\d{2}-\d{2}$/;
15
+ const FEED_LOCK_MODES = [
16
+ "ALL_DAILY_TODOS",
17
+ "SELECTED_GOALS",
18
+ "DAILY_XP",
19
+ ];
20
+ function kidName(kid) {
21
+ return [kid.firstName, kid.lastName].filter(Boolean).join(" ") || "(unnamed)";
22
+ }
23
+ function normalizeName(value) {
24
+ return value.trim().replace(/\s+/g, " ").toLowerCase();
25
+ }
26
+ async function listFamilyKids(api) {
27
+ return unwrap(await api.client.GET("/family/kids", {
28
+ params: { query: { includeSelf: "false" } },
29
+ })).kids;
30
+ }
31
+ /**
32
+ * `--student` against the guardian's own kids: exact id, then full name
33
+ * (case/whitespace-insensitive), then a unique first name.
34
+ */
35
+ async function resolveFamilyKid(api, parsed) {
36
+ const reference = flagString(parsed, "student", { required: true }).trim();
37
+ const kids = await listFamilyKids(api);
38
+ const candidates = kids.map((kid) => ({ id: kid.id, name: kidName(kid) }));
39
+ const byId = kids.find((kid) => kid.id === reference);
40
+ if (byId)
41
+ return byId;
42
+ const wanted = normalizeName(reference);
43
+ const byFullName = kids.filter((kid) => normalizeName(kidName(kid)) === wanted);
44
+ const byFirstName = kids.filter((kid) => normalizeName(kid.firstName ?? "") === wanted);
45
+ const matches = byFullName.length > 0 ? byFullName : byFirstName;
46
+ if (matches.length === 1)
47
+ return matches[0];
48
+ if (matches.length > 1) {
49
+ throw new CliError("ambiguous_student", `--student "${reference}" matches ${matches.length} of your kids; pass a kid id.`, 1, { candidates: matches.map((kid) => ({ id: kid.id, name: kidName(kid) })) });
50
+ }
51
+ throw new CliError("student_not_found", `--student "${reference}" is not one of your kids. Use an id, full name, or unique first name.`, 1, { candidates });
52
+ }
53
+ function kidTarget(kid) {
54
+ return { kidId: kid.id, kid: kidName(kid) };
55
+ }
56
+ /** Never echo a secret: a redaction marker plus a short fingerprint. */
57
+ function redactedSecret(secret) {
58
+ return {
59
+ secret: "<redacted>",
60
+ secretSha256Prefix: createHash("sha256")
61
+ .update(secret)
62
+ .digest("hex")
63
+ .slice(0, 12),
64
+ };
65
+ }
66
+ function flagDate(parsed, name) {
67
+ const value = flagString(parsed, name);
68
+ if (value !== undefined &&
69
+ (!DATE.test(value) ||
70
+ new Date(`${value}T00:00:00.000Z`).toISOString().slice(0, 10) !== value)) {
71
+ throw new CliError("invalid_arguments", `--${name} must be a valid YYYY-MM-DD date.`);
72
+ }
73
+ return value;
74
+ }
75
+ function flagUuid(parsed, name, options = {}) {
76
+ const value = flagString(parsed, name, options);
77
+ if (value !== undefined && !UUID.test(value)) {
78
+ throw new CliError("invalid_arguments", `--${name} must be an id (UUID).`);
79
+ }
80
+ return value;
81
+ }
82
+ async function schoolClassesFor(api, kid) {
83
+ const { kids } = unwrap(await api.client.GET("/family/school-classes"));
84
+ const entry = kids.find((candidate) => candidate.id === kid.id);
85
+ if (!entry) {
86
+ throw new CliError("not_found", `${kidName(kid)} has no school classes to manage.`);
87
+ }
88
+ return entry;
89
+ }
90
+ /** A kid's class registration by cohort id (or the registration id itself). */
91
+ function findRegistration(entry, reference) {
92
+ const registration = entry.registrations.find((candidate) => candidate.cohort.id === reference ||
93
+ candidate.registrationId === reference);
94
+ if (!registration) {
95
+ throw new CliError("not_found", `${kidName(entry)} is not registered in cohort ${reference}. Run \`family school-classes\` for their classes.`, 1, {
96
+ classes: entry.registrations.map((candidate) => ({
97
+ cohortId: candidate.cohort.id,
98
+ cohort: candidate.cohort.name,
99
+ course: candidate.course.name,
100
+ })),
101
+ });
102
+ }
103
+ return registration;
104
+ }
105
+ /** A cohort's course/name from the kid's swap options, when listed there. */
106
+ async function describeCohortOption(api, kidId, cohortId) {
107
+ const { courses } = unwrap(await api.client.GET("/family/school-classes/swap-options", {
108
+ params: { query: { kidId } },
109
+ }));
110
+ for (const course of courses) {
111
+ const cohort = course.cohorts.find((candidate) => candidate.id === cohortId);
112
+ if (cohort) {
113
+ return {
114
+ cohortId,
115
+ cohort: cohort.name,
116
+ course: course.name,
117
+ startsAt: cohort.startsAt,
118
+ timezone: cohort.timezone,
119
+ spotsLeft: cohort.spotsLeft,
120
+ };
121
+ }
122
+ }
123
+ return null;
124
+ }
125
+ async function coworkPods(api) {
126
+ const { course } = unwrap(await api.client.GET("/courses/{courseId}/", {
127
+ params: { path: { courseId: COWORK_COURSE_ID } },
128
+ }));
129
+ return course.eventSeries.map((series) => ({
130
+ cohortId: series.id,
131
+ name: series.name,
132
+ nextStartsAt: series.events[0]?.startsAt ?? series.startsAt,
133
+ timezone: series.timezone,
134
+ guide: series.guides[0]?.firstName ?? null,
135
+ registered: series._count.registrations,
136
+ spotsLeft: series.capacity != null
137
+ ? Math.max(0, series.capacity - series._count.registrations)
138
+ : null,
139
+ }));
140
+ }
141
+ function requireAnyFlag(parsed, names) {
142
+ if (!names.some((name) => hasFlag(parsed, name))) {
143
+ throw new CliError("invalid_arguments", `Pass at least one of ${names.map((name) => `--${name}`).join(", ")}.`);
144
+ }
145
+ }
146
+ export async function runFamilyCommand({ parsed, api, writeCommand, }) {
147
+ const verb = parsed.positionals[1];
148
+ if (verb === "kids") {
149
+ // School families see no money here: drop credits and membership pricing.
150
+ const kids = await listFamilyKids(api);
151
+ return {
152
+ kids: kids.map((kid) => ({
153
+ id: kid.id,
154
+ firstName: kid.firstName,
155
+ lastName: kid.lastName,
156
+ onboarded: kid.onboarded,
157
+ needsParentOnboarding: kid.needsParentOnboarding,
158
+ needsCurriculumSetup: kid.needsCurriculumSetup,
159
+ schoolSlots: kid.schoolSlots,
160
+ })),
161
+ };
162
+ }
163
+ if (verb === "today") {
164
+ return unwrap(await api.client.GET("/family/today/"));
165
+ }
166
+ if (verb === "schedule") {
167
+ const days = flagInteger(parsed, "days", { min: 1, max: 31 }) ?? 14;
168
+ const start = new Date();
169
+ const end = new Date(start.getTime() + days * 24 * 60 * 60 * 1000);
170
+ return unwrap(await api.client.GET("/schedule/", {
171
+ params: {
172
+ query: {
173
+ scope: ["FAMILY"],
174
+ start: start.toISOString(),
175
+ end: end.toISOString(),
176
+ },
177
+ },
178
+ }));
179
+ }
180
+ if (verb === "tutor") {
181
+ const kid = hasFlag(parsed, "student")
182
+ ? await resolveFamilyKid(api, parsed)
183
+ : undefined;
184
+ return unwrap(await api.client.GET("/family/tutor/", {
185
+ params: { query: kid ? { kidId: kid.id } : {} },
186
+ }));
187
+ }
188
+ if (verb === "account") {
189
+ const [me, timezone] = await Promise.all([
190
+ api.client.GET("/user/@me/"),
191
+ api.client.GET("/user/@me/timezone/"),
192
+ ]);
193
+ const { user } = unwrap(me);
194
+ if (!user)
195
+ throw new CliError("not_found", "No signed-in user.");
196
+ return {
197
+ id: user.id,
198
+ firstName: user.firstName,
199
+ lastName: user.lastName,
200
+ email: user.email,
201
+ phoneNumber: user.phoneNumber,
202
+ phoneVerified: user.phoneVerified,
203
+ smsReminders: user.smsOptIn,
204
+ emailReminders: user.preferences?.emailRemindersEnabled ?? null,
205
+ timezone: unwrap(timezone).timezone,
206
+ };
207
+ }
208
+ if (verb === "set-name") {
209
+ const firstName = flagString(parsed, "first-name")?.trim();
210
+ const lastName = flagString(parsed, "last-name")?.trim();
211
+ requireAnyFlag(parsed, ["first-name", "last-name"]);
212
+ if (firstName === "" || lastName === "") {
213
+ throw new CliError("invalid_arguments", "Names cannot be empty.");
214
+ }
215
+ const body = {
216
+ ...(firstName !== undefined ? { firstName } : {}),
217
+ ...(lastName !== undefined ? { lastName } : {}),
218
+ };
219
+ return writeCommand(parsed, {
220
+ action: "rename your own guardian account",
221
+ target: { user: "@me" },
222
+ request: body,
223
+ details: {
224
+ consequence: "Your name changes everywhere Recess shows it (guides, chats, emails).",
225
+ },
226
+ }, async () => unwrap(await api.client.PATCH("/user/@me/", { body })));
227
+ }
228
+ if (verb === "set-notifications") {
229
+ const emailReminders = flagBooleanValue(parsed, "email-reminders");
230
+ const smsReminders = flagBooleanValue(parsed, "sms-reminders");
231
+ requireAnyFlag(parsed, ["email-reminders", "sms-reminders"]);
232
+ const request = {
233
+ ...(emailReminders !== undefined ? { emailReminders } : {}),
234
+ ...(smsReminders !== undefined ? { smsReminders } : {}),
235
+ };
236
+ return writeCommand(parsed, {
237
+ action: "change your own email/SMS reminder settings",
238
+ target: { user: "@me" },
239
+ request,
240
+ details: {
241
+ consequence: "Controls whether Recess sends you class/event reminders by email and by text.",
242
+ },
243
+ }, async () => {
244
+ const [email, sms] = await Promise.all([
245
+ emailReminders === undefined
246
+ ? undefined
247
+ : api.client
248
+ .PATCH("/user/preferences/", {
249
+ body: { emailRemindersEnabled: emailReminders },
250
+ })
251
+ .then(unwrap),
252
+ smsReminders === undefined
253
+ ? undefined
254
+ : // Replies with an empty 200; only the status says it landed.
255
+ api.client
256
+ .PATCH("/user/@me/sms-opt-in/", {
257
+ body: { optIn: smsReminders },
258
+ })
259
+ .then((result) => {
260
+ if (!result.response.ok) {
261
+ throw apiError(result.response.status, result.error);
262
+ }
263
+ return smsReminders;
264
+ }),
265
+ ]);
266
+ return {
267
+ ...(email ? { emailReminders: email.emailRemindersEnabled } : {}),
268
+ ...(sms !== undefined ? { smsReminders: sms } : {}),
269
+ };
270
+ });
271
+ }
272
+ if (verb === "set-phone") {
273
+ const phoneNumber = flagString(parsed, "phone", { required: true }).trim();
274
+ if (!/^\+[1-9]\d{7,14}$/.test(phoneNumber)) {
275
+ throw new CliError("invalid_arguments", "--phone must be E.164, e.g. +14155550123.");
276
+ }
277
+ return writeCommand(parsed, {
278
+ action: "change your own phone number",
279
+ target: { user: "@me" },
280
+ request: { phoneNumber },
281
+ details: {
282
+ consequence: "The new number starts unverified; Recess texts go to it once verified.",
283
+ },
284
+ }, async () => unwrap(await api.client.PUT("/user/@me/phone-number/", {
285
+ body: { phoneNumber },
286
+ })));
287
+ }
288
+ if (verb === "set-timezone") {
289
+ const timezone = flagString(parsed, "timezone", {
290
+ required: true,
291
+ }).trim();
292
+ try {
293
+ new Intl.DateTimeFormat("en-US", { timeZone: timezone });
294
+ }
295
+ catch {
296
+ throw new CliError("invalid_arguments", "--timezone must be an IANA timezone, e.g. America/Phoenix.");
297
+ }
298
+ return writeCommand(parsed, {
299
+ action: "set the whole family's timezone",
300
+ target: { family: "@me" },
301
+ request: { timezone },
302
+ details: {
303
+ consequence: "Every family member (you and your kids) switches to this timezone: class times, daily todos and reminders follow it.",
304
+ },
305
+ }, async () => {
306
+ const result = await api.client.PATCH("/family/timezone/", {
307
+ body: { timezone },
308
+ });
309
+ if (!result.response.ok) {
310
+ throw apiError(result.response.status, result.error);
311
+ }
312
+ return { timezone };
313
+ });
314
+ }
315
+ if (verb === "guardians") {
316
+ return unwrap(await api.client.GET("/family/guardians/"));
317
+ }
318
+ if (verb === "school-classes") {
319
+ return unwrap(await api.client.GET("/family/school-classes"));
320
+ }
321
+ if (verb === "school-class-options") {
322
+ const kid = await resolveFamilyKid(api, parsed);
323
+ return unwrap(await api.client.GET("/family/school-classes/swap-options", {
324
+ params: { query: { kidId: kid.id } },
325
+ }));
326
+ }
327
+ if (verb === "drop-class" || verb === "restore-class") {
328
+ const kid = await resolveFamilyKid(api, parsed);
329
+ const cohort = flagUuid(parsed, "cohort", { required: true });
330
+ const registration = findRegistration(await schoolClassesFor(api, kid), cohort);
331
+ const action = verb === "drop-class" ? "drop" : "restore";
332
+ const body = {
333
+ registrationId: registration.registrationId,
334
+ action,
335
+ };
336
+ return writeCommand(parsed, {
337
+ action: action === "drop"
338
+ ? `drop ${kidName(kid)} from ${registration.course.name}`
339
+ : `undo the pending drop of ${kidName(kid)} from ${registration.course.name}`,
340
+ target: {
341
+ ...kidTarget(kid),
342
+ cohortId: registration.cohort.id,
343
+ cohort: registration.cohort.name,
344
+ },
345
+ request: body,
346
+ details: {
347
+ consequence: action === "drop"
348
+ ? registration.wouldEndImmediately
349
+ ? "The class ends immediately."
350
+ : `The class stays until the period ends (${registration.enrollmentPeriodEnd ?? "end of the current period"}), then ends.`
351
+ : "The class continues; the scheduled drop is cancelled.",
352
+ ...(action === "drop" && registration.alsoEnds.length > 0
353
+ ? { alsoEnds: registration.alsoEnds }
354
+ : {}),
355
+ pendingDrop: registration.pendingDrop,
356
+ },
357
+ }, async () => unwrap(await api.client.POST("/family/school-classes/drop", { body })));
358
+ }
359
+ if (verb === "swap-class") {
360
+ const kid = await resolveFamilyKid(api, parsed);
361
+ const from = flagUuid(parsed, "from", { required: true });
362
+ const to = flagString(parsed, "to", { required: true });
363
+ const toCohortId = to === "none" ? null : to;
364
+ if (toCohortId !== null && !UUID.test(toCohortId)) {
365
+ throw new CliError("invalid_arguments", "--to must be a cohort id or none.");
366
+ }
367
+ const registration = findRegistration(await schoolClassesFor(api, kid), from);
368
+ const destination = toCohortId
369
+ ? await describeCohortOption(api, kid.id, toCohortId)
370
+ : null;
371
+ if (toCohortId && !destination) {
372
+ throw new CliError("invalid_arguments", `Cohort ${toCohortId} is not a class option for ${kidName(kid)}. Run \`family school-class-options --student ${kid.id}\`.`);
373
+ }
374
+ const body = { registrationId: registration.registrationId, toCohortId };
375
+ return writeCommand(parsed, {
376
+ action: toCohortId
377
+ ? `queue a switch for ${kidName(kid)} from ${registration.course.name} to ${destination.course}`
378
+ : `cancel ${kidName(kid)}'s queued switch out of ${registration.course.name}`,
379
+ target: {
380
+ ...kidTarget(kid),
381
+ fromCohortId: registration.cohort.id,
382
+ fromCohort: registration.cohort.name,
383
+ },
384
+ request: body,
385
+ details: {
386
+ consequence: toCohortId
387
+ ? "The switch takes effect at the next period boundary; the current class runs until then."
388
+ : "The kid stays in the current class.",
389
+ ...(destination ? { to: destination } : {}),
390
+ currentQueuedSwap: registration.queuedSwap,
391
+ },
392
+ }, async () => unwrap(await api.client.POST("/family/school-classes/swap", { body })));
393
+ }
394
+ if (verb === "register-class") {
395
+ const kid = await resolveFamilyKid(api, parsed);
396
+ const cohortId = flagUuid(parsed, "cohort", { required: true });
397
+ const option = await describeCohortOption(api, kid.id, cohortId);
398
+ const body = { kidId: kid.id, cohortId };
399
+ return writeCommand(parsed, {
400
+ action: `register ${kidName(kid)} for ${option ? `${option.course} (${option.cohort})` : `cohort ${cohortId}`}`,
401
+ target: { ...kidTarget(kid), cohortId },
402
+ request: body,
403
+ details: {
404
+ consequence: "The kid joins the class; it uses one of their school class slots.",
405
+ ...(option ? { cohort: option } : {}),
406
+ },
407
+ }, async () => unwrap(await api.client.POST("/family/school-classes/register", { body })));
408
+ }
409
+ throw new CliError("invalid_arguments", "Use family kids|today|schedule|tutor|account|set-name|set-notifications|set-phone|set-timezone|guardians|school-classes|school-class-options|drop-class|restore-class|swap-class|register-class.");
410
+ }
411
+ export async function runKidCommand({ parsed, api, writeCommand, }) {
412
+ const verb = parsed.positionals[1];
413
+ const kid = await resolveFamilyKid(api, parsed);
414
+ const kidId = kid.id;
415
+ const name = kidName(kid);
416
+ if (verb === "today") {
417
+ const date = flagDate(parsed, "date");
418
+ return unwrap(await api.client.GET("/parent/kid/{kidId}/today/", {
419
+ params: { path: { kidId }, query: date ? { date } : {} },
420
+ }));
421
+ }
422
+ if (verb === "goals") {
423
+ return unwrap(await api.client.GET("/parent/kid/{kidId}/goals/", {
424
+ params: { path: { kidId } },
425
+ }));
426
+ }
427
+ if (verb === "xp") {
428
+ const range = flagString(parsed, "range");
429
+ return unwrap(await api.client.GET("/parent/kid/{kidId}/xp-history/", {
430
+ params: {
431
+ path: { kidId },
432
+ query: range
433
+ ? {
434
+ range: assertChoice(range, ["week", "month", "quarter", "year"], "--range"),
435
+ }
436
+ : {},
437
+ },
438
+ }));
439
+ }
440
+ if (verb === "map-scores") {
441
+ return unwrap(await api.client.GET("/parent/kid/{kidId}/map-scores/", {
442
+ params: { path: { kidId } },
443
+ }));
444
+ }
445
+ if (verb === "classes") {
446
+ return unwrap(await api.client.GET("/tutor/students/{studentId}/classes", {
447
+ params: { path: { studentId: kidId } },
448
+ }));
449
+ }
450
+ if (verb === "profile") {
451
+ return unwrap(await api.client.GET("/family/kid/{kidId}/profile/", {
452
+ params: { path: { kidId } },
453
+ }));
454
+ }
455
+ if (verb === "set-profile") {
456
+ requireAnyFlag(parsed, [
457
+ "first-name",
458
+ "last-name",
459
+ "birthday",
460
+ "interests",
461
+ ]);
462
+ const firstName = flagString(parsed, "first-name")?.trim();
463
+ const lastName = flagString(parsed, "last-name")?.trim();
464
+ const birthdate = flagDate(parsed, "birthday");
465
+ const interests = hasFlag(parsed, "interests")
466
+ ? flagIdList(parsed, "interests")
467
+ : undefined;
468
+ if (firstName === "" || lastName === "") {
469
+ throw new CliError("invalid_arguments", "Names cannot be empty.");
470
+ }
471
+ const body = {
472
+ ...(firstName !== undefined ? { firstName } : {}),
473
+ ...(lastName !== undefined ? { lastName } : {}),
474
+ ...(birthdate !== undefined ? { birthdate } : {}),
475
+ ...(interests !== undefined ? { interests } : {}),
476
+ };
477
+ return writeCommand(parsed, {
478
+ action: `update ${name}'s profile`,
479
+ target: kidTarget(kid),
480
+ request: body,
481
+ details: {
482
+ consequence: interests !== undefined
483
+ ? "--interests REPLACES the kid's whole interest list; Rocky uses it to tailor lessons."
484
+ : "Updates what guides and Rocky see for this kid.",
485
+ },
486
+ }, async () => unwrap(await api.client.PATCH("/family/kid/{kidId}/profile/", {
487
+ params: { path: { kidId } },
488
+ body,
489
+ })));
490
+ }
491
+ if (verb === "texts") {
492
+ const [preferences, profile] = await Promise.all([
493
+ api.client.GET("/family/kid/{kidId}/text-preferences/", {
494
+ params: { path: { kidId } },
495
+ }),
496
+ api.client.GET("/tutor/students/{studentId}/profile", {
497
+ params: { path: { studentId: kidId } },
498
+ }),
499
+ ]);
500
+ const { dailySummaryEnabled, dailySummarySendHour } = unwrap(profile);
501
+ return {
502
+ ...unwrap(preferences),
503
+ dailySummaryEnabled,
504
+ dailySummarySendHour,
505
+ // The hour only matters while the (opt-in) daily summary is on.
506
+ dailySummarySendHourEffective: dailySummaryEnabled
507
+ ? (dailySummarySendHour ?? DEFAULT_SUMMARY_SEND_HOUR)
508
+ : null,
509
+ };
510
+ }
511
+ if (verb === "set-texts") {
512
+ requireAnyFlag(parsed, [
513
+ "enabled",
514
+ "frequency",
515
+ "focus",
516
+ "clear-focus",
517
+ "summary",
518
+ "hour",
519
+ ]);
520
+ const textsEnabled = flagBooleanValue(parsed, "enabled");
521
+ const frequency = flagString(parsed, "frequency");
522
+ const focus = flagString(parsed, "focus")?.trim();
523
+ if (focus !== undefined && hasFlag(parsed, "clear-focus")) {
524
+ throw new CliError("invalid_arguments", "Pass --focus or --clear-focus, not both.");
525
+ }
526
+ const dailySummaryEnabled = flagBooleanValue(parsed, "summary");
527
+ const hour = flagString(parsed, "hour");
528
+ let dailySummarySendHour;
529
+ if (hour === "default") {
530
+ dailySummarySendHour = null;
531
+ }
532
+ else if (hour !== undefined) {
533
+ dailySummarySendHour = flagInteger(parsed, "hour", { min: 0, max: 23 });
534
+ }
535
+ if (dailySummarySendHour !== undefined && dailySummaryEnabled === false) {
536
+ throw new CliError("invalid_arguments", `--hour needs the daily summary on; the server drops the hour while it is off for ${name}.`);
537
+ }
538
+ // Daily summaries are opt-in per kid and the server 409s an hour-only
539
+ // change while the summary is off: refuse that before the preview.
540
+ const before = dailySummarySendHour !== undefined || dailySummaryEnabled !== undefined
541
+ ? unwrap(await api.client.GET("/tutor/students/{studentId}/profile", {
542
+ params: { path: { studentId: kidId } },
543
+ }))
544
+ : undefined;
545
+ if (dailySummarySendHour !== undefined &&
546
+ dailySummaryEnabled !== true &&
547
+ !before?.dailySummaryEnabled) {
548
+ throw new CliError("invalid_arguments", `The daily summary is off for ${name}; add --summary true to turn it on with this hour.`);
549
+ }
550
+ const body = {
551
+ ...(textsEnabled !== undefined ? { textsEnabled } : {}),
552
+ ...(frequency !== undefined
553
+ ? {
554
+ textFrequency: assertChoice(frequency, ["ALL", "DAILY", "IMPORTANT"], "--frequency"),
555
+ }
556
+ : {}),
557
+ ...(focus !== undefined ? { dailySummaryFocus: focus || null } : {}),
558
+ ...(hasFlag(parsed, "clear-focus") ? { dailySummaryFocus: null } : {}),
559
+ };
560
+ const profileBody = {
561
+ ...(dailySummaryEnabled !== undefined ? { dailySummaryEnabled } : {}),
562
+ ...(dailySummarySendHour !== undefined ? { dailySummarySendHour } : {}),
563
+ };
564
+ const textChange = Object.keys(body).length > 0;
565
+ const profileChange = Object.keys(profileBody).length > 0;
566
+ return writeCommand(parsed, {
567
+ action: `change the texts you get about ${name}`,
568
+ target: kidTarget(kid),
569
+ request: {
570
+ ...(textChange ? { textPreferences: body } : {}),
571
+ ...(profileChange ? { profile: profileBody } : {}),
572
+ },
573
+ details: {
574
+ ...(before
575
+ ? {
576
+ before: {
577
+ dailySummaryEnabled: before.dailySummaryEnabled,
578
+ dailySummarySendHour: before.dailySummarySendHour,
579
+ },
580
+ }
581
+ : {}),
582
+ consequence: [
583
+ ...(textChange
584
+ ? [
585
+ "Controls the texts Recess sends YOU about this kid (on/off, how often, what the daily summary focuses on).",
586
+ ]
587
+ : []),
588
+ ...(dailySummaryEnabled !== undefined
589
+ ? [
590
+ dailySummaryEnabled
591
+ ? "Turns on the kid's daily summary (opt-in per kid, shared by every guardian)."
592
+ : "Turns off the kid's daily summary for every guardian; its send hour is dropped.",
593
+ ]
594
+ : []),
595
+ ...(dailySummarySendHour !== undefined
596
+ ? [
597
+ `The daily summary send hour is per kid, shared by every guardian, in the kid's timezone (${dailySummarySendHour === null ? `default ${DEFAULT_SUMMARY_SEND_HOUR}:00` : `${dailySummarySendHour}:00`}).`,
598
+ ]
599
+ : []),
600
+ ].join(" "),
601
+ },
602
+ }, async () => {
603
+ await Promise.all([
604
+ textChange
605
+ ? api.client
606
+ .PATCH("/family/kid/{kidId}/text-preferences/", {
607
+ params: { path: { kidId } },
608
+ body,
609
+ })
610
+ .then(unwrap)
611
+ : undefined,
612
+ profileChange
613
+ ? api.client
614
+ .PATCH("/tutor/students/{studentId}/profile", {
615
+ params: { path: { studentId: kidId } },
616
+ body: profileBody,
617
+ })
618
+ .then(unwrap)
619
+ : undefined,
620
+ ]);
621
+ // Report what the server stored, not what was asked for.
622
+ const [textPreferences, profile] = await Promise.all([
623
+ api.client.GET("/family/kid/{kidId}/text-preferences/", {
624
+ params: { path: { kidId } },
625
+ }),
626
+ api.client.GET("/tutor/students/{studentId}/profile", {
627
+ params: { path: { studentId: kidId } },
628
+ }),
629
+ ]);
630
+ const stored = unwrap(profile);
631
+ return {
632
+ textPreferences: unwrap(textPreferences),
633
+ dailySummaryEnabled: stored.dailySummaryEnabled,
634
+ dailySummarySendHour: stored.dailySummarySendHour,
635
+ };
636
+ });
637
+ }
638
+ if (verb === "set-rooms") {
639
+ const allow = flagBooleanValue(parsed, "allow");
640
+ if (allow === undefined) {
641
+ throw new CliError("invalid_arguments", "Missing required --allow.");
642
+ }
643
+ const body = { kidId, allow };
644
+ return writeCommand(parsed, {
645
+ action: `${allow ? "allow" : "block"} ${name} in live rooms`,
646
+ target: kidTarget(kid),
647
+ request: body,
648
+ details: {
649
+ consequence: allow
650
+ ? "The kid can join live video rooms with other kids."
651
+ : "The kid can no longer join live video rooms.",
652
+ },
653
+ }, async () => unwrap(await api.client.POST("/safety/rooms/", { body })));
654
+ }
655
+ if (verb === "feed-lock") {
656
+ const profile = unwrap(await api.client.GET("/tutor/students/{studentId}/profile", {
657
+ params: { path: { studentId: kidId } },
658
+ }));
659
+ return { feedLock: profile.feedLock, goals: profile.feedLockGoals };
660
+ }
661
+ if (verb === "set-feed-lock") {
662
+ requireAnyFlag(parsed, ["enabled", "mode", "xp-target", "goals"]);
663
+ const profile = unwrap(await api.client.GET("/tutor/students/{studentId}/profile", {
664
+ params: { path: { studentId: kidId } },
665
+ }));
666
+ const enabled = flagBooleanValue(parsed, "enabled");
667
+ const mode = flagString(parsed, "mode");
668
+ const xpTarget = flagInteger(parsed, "xp-target", {
669
+ min: 1,
670
+ max: 2147483647,
671
+ });
672
+ const goalIds = hasFlag(parsed, "goals")
673
+ ? flagIdList(parsed, "goals")
674
+ : undefined;
675
+ const feedLock = {
676
+ ...profile.feedLock,
677
+ ...(enabled !== undefined ? { enabled } : {}),
678
+ ...(mode !== undefined
679
+ ? { mode: assertChoice(mode, FEED_LOCK_MODES, "--mode") }
680
+ : {}),
681
+ ...(xpTarget !== undefined ? { xpTarget } : {}),
682
+ ...(goalIds !== undefined ? { goalIds } : {}),
683
+ };
684
+ // FeedLockSettings.svelte saves only a complete config for its mode.
685
+ if (feedLock.enabled && feedLock.mode === "SELECTED_GOALS") {
686
+ const known = new Set(profile.feedLockGoals.map((goal) => goal.id));
687
+ const unknown = feedLock.goalIds.filter((id) => !known.has(id));
688
+ if (feedLock.goalIds.length === 0 || unknown.length > 0) {
689
+ throw new CliError("invalid_arguments", "SELECTED_GOALS needs --goals with ids from this kid's goals.", 1, { unknown, goals: profile.feedLockGoals });
690
+ }
691
+ }
692
+ if (feedLock.enabled &&
693
+ feedLock.mode === "DAILY_XP" &&
694
+ !(feedLock.xpTarget && feedLock.xpTarget > 0)) {
695
+ throw new CliError("invalid_arguments", "DAILY_XP needs --xp-target N (a positive integer).");
696
+ }
697
+ return writeCommand(parsed, {
698
+ action: `${feedLock.enabled ? "set" : "turn off"} ${name}'s feed lock`,
699
+ target: kidTarget(kid),
700
+ request: { feedLock },
701
+ details: {
702
+ before: profile.feedLock,
703
+ consequence: feedLock.enabled
704
+ ? "The kid's feed stays locked each day until the lock's goal is met (todos, selected goals, or the XP target)."
705
+ : "The kid's feed is no longer locked behind daily work.",
706
+ },
707
+ }, async () => {
708
+ unwrap(await api.client.PATCH("/tutor/students/{studentId}/profile", {
709
+ params: { path: { studentId: kidId } },
710
+ body: { feedLock },
711
+ }));
712
+ return { feedLock };
713
+ });
714
+ }
715
+ if (verb === "logins") {
716
+ return unwrap(await api.client.GET("/parent/kid/{kidId}/credentials/", {
717
+ params: { path: { kidId } },
718
+ }));
719
+ }
720
+ if (verb === "reveal-login") {
721
+ const credentialId = flagUuid(parsed, "login", { required: true });
722
+ return unwrap(await api.client.GET("/parent/kid/{kidId}/credentials/{credentialId}/secret/", { params: { path: { kidId, credentialId } } }));
723
+ }
724
+ if (verb === "add-login") {
725
+ const platform = flagString(parsed, "platform", { required: true });
726
+ const origin = flagString(parsed, "url", { required: true });
727
+ const username = flagString(parsed, "username");
728
+ const secret = flagString(parsed, "password");
729
+ const notes = flagString(parsed, "notes");
730
+ const body = {
731
+ platform,
732
+ origin,
733
+ ...(username !== undefined ? { username } : {}),
734
+ ...(secret !== undefined ? { secret } : {}),
735
+ ...(notes !== undefined ? { notes } : {}),
736
+ };
737
+ return writeCommand(parsed, {
738
+ action: `save a ${platform} login for ${name}`,
739
+ target: kidTarget(kid),
740
+ request: {
741
+ ...body,
742
+ ...(secret !== undefined ? redactedSecret(secret) : {}),
743
+ },
744
+ details: {
745
+ consequence: "Rocky and the kid's browser can sign in to this site with it.",
746
+ },
747
+ }, async () => unwrap(await api.client.POST("/parent/kid/{kidId}/credentials/", {
748
+ params: { path: { kidId } },
749
+ body,
750
+ })));
751
+ }
752
+ if (verb === "edit-login") {
753
+ const credentialId = flagUuid(parsed, "login", { required: true });
754
+ requireAnyFlag(parsed, [
755
+ "platform",
756
+ "url",
757
+ "username",
758
+ "password",
759
+ "notes",
760
+ ]);
761
+ const platform = flagString(parsed, "platform");
762
+ const origin = flagString(parsed, "url");
763
+ const username = flagString(parsed, "username");
764
+ const secret = flagString(parsed, "password");
765
+ const notes = flagString(parsed, "notes");
766
+ const body = {
767
+ ...(platform !== undefined ? { platform } : {}),
768
+ ...(origin !== undefined ? { origin } : {}),
769
+ ...(username !== undefined ? { username } : {}),
770
+ ...(secret !== undefined ? { secret } : {}),
771
+ ...(notes !== undefined ? { notes: notes || null } : {}),
772
+ };
773
+ return writeCommand(parsed, {
774
+ action: `edit ${name}'s saved login ${credentialId}`,
775
+ target: { ...kidTarget(kid), credentialId },
776
+ request: {
777
+ ...body,
778
+ ...(secret !== undefined ? redactedSecret(secret) : {}),
779
+ },
780
+ details: {
781
+ consequence: "Rocky and the kid's browser use the updated login.",
782
+ },
783
+ }, async () => unwrap(await api.client.PATCH("/parent/kid/{kidId}/credentials/{credentialId}/", { params: { path: { kidId, credentialId } }, body })));
784
+ }
785
+ if (verb === "remove-login") {
786
+ const credentialId = flagUuid(parsed, "login", { required: true });
787
+ const { credentials } = unwrap(await api.client.GET("/parent/kid/{kidId}/credentials/", {
788
+ params: { path: { kidId } },
789
+ }));
790
+ const credential = credentials.find((entry) => entry.id === credentialId);
791
+ if (!credential) {
792
+ throw new CliError("not_found", `${name} has no saved login ${credentialId}. Run \`kid logins\`.`);
793
+ }
794
+ return writeCommand(parsed, {
795
+ action: `delete ${name}'s saved ${credential.platform} login`,
796
+ target: { ...kidTarget(kid), credentialId },
797
+ request: {},
798
+ details: {
799
+ login: {
800
+ platform: credential.platform,
801
+ origin: credential.origin,
802
+ username: credential.username,
803
+ },
804
+ consequence: "The login is deleted; Rocky and the kid's browser can no longer sign in with it.",
805
+ },
806
+ }, async () => unwrap(await api.client.DELETE("/parent/kid/{kidId}/credentials/{credentialId}/", { params: { path: { kidId, credentialId } } })));
807
+ }
808
+ if (verb === "excuse") {
809
+ const eventId = flagUuid(parsed, "event", { required: true });
810
+ const reason = flagString(parsed, "note")?.trim();
811
+ if (reason !== undefined && reason.length > 500) {
812
+ throw new CliError("invalid_arguments", "--note must be 500 characters or fewer.");
813
+ }
814
+ const body = reason ? { reason } : {};
815
+ return writeCommand(parsed, {
816
+ action: `excuse ${name} from event ${eventId}`,
817
+ target: { ...kidTarget(kid), eventId },
818
+ request: body,
819
+ details: {
820
+ consequence: "Attendance is marked EXCUSED and the class's guides are notified (with the note).",
821
+ },
822
+ }, async () => unwrap(await api.client.POST("/parent/kid/{kidId}/events/{eventId}/excuse/", { params: { path: { kidId, eventId } }, body })));
823
+ }
824
+ if (verb === "cowork") {
825
+ const [current, pods] = await Promise.all([
826
+ api.client.GET("/parent/kid/{kidId}/cowork/", {
827
+ params: { path: { kidId } },
828
+ }),
829
+ coworkPods(api),
830
+ ]);
831
+ const { seriesId } = unwrap(current);
832
+ return {
833
+ currentCohortId: seriesId,
834
+ current: pods.find((pod) => pod.cohortId === seriesId) ?? null,
835
+ pods,
836
+ };
837
+ }
838
+ if (verb === "switch-cowork") {
839
+ const to = flagUuid(parsed, "to", { required: true });
840
+ const [current, pods] = await Promise.all([
841
+ api.client.GET("/parent/kid/{kidId}/cowork/", {
842
+ params: { path: { kidId } },
843
+ }),
844
+ coworkPods(api),
845
+ ]);
846
+ const currentId = unwrap(current).seriesId;
847
+ // CoworkHourCard.svelte: picking the pod the kid is already in is a no-op.
848
+ if (to === currentId) {
849
+ return { skipped: true, reason: `${name} is already in that pod.` };
850
+ }
851
+ const next = pods.find((pod) => pod.cohortId === to);
852
+ if (!next) {
853
+ throw new CliError("invalid_arguments", `${to} is not a coworking pod. Run \`kid cowork --student ${kidId}\` for the pods.`);
854
+ }
855
+ return writeCommand(parsed, {
856
+ action: `move ${name} to the ${next.name} coworking pod`,
857
+ target: kidTarget(kid),
858
+ request: {
859
+ register: { cohortId: to, kidId },
860
+ ...(currentId
861
+ ? {
862
+ unregister: {
863
+ cohortId: currentId,
864
+ userId: kidId,
865
+ cancelEnrollment: false,
866
+ },
867
+ }
868
+ : {}),
869
+ },
870
+ details: {
871
+ from: pods.find((pod) => pod.cohortId === currentId) ?? currentId,
872
+ to: next,
873
+ consequence: "The kid joins the new daily pod, then leaves the old one (enrollment is kept).",
874
+ },
875
+ }, async () => {
876
+ const registered = unwrap(await api.client.POST("/cohorts/register/", {
877
+ body: { cohortId: to, kidId },
878
+ }));
879
+ const unregistered = currentId
880
+ ? unwrap(await api.client.POST("/cohorts/unregister/", {
881
+ body: {
882
+ cohortId: currentId,
883
+ userId: kidId,
884
+ cancelEnrollment: false,
885
+ },
886
+ }))
887
+ : null;
888
+ return { registered, unregistered };
889
+ });
890
+ }
891
+ if (verb === "friends") {
892
+ return unwrap(await api.client.GET("/friends/", {
893
+ params: { query: { userId: kidId } },
894
+ }));
895
+ }
896
+ if (verb === "friend-parent") {
897
+ const parentId = flagUuid(parsed, "parent", { required: true });
898
+ const { friendships } = unwrap(await api.client.GET("/friends/", {
899
+ params: { query: { userId: kidId } },
900
+ }));
901
+ // KidFriendsCard.svelte: only the guardians of the kid's own friends.
902
+ const match = friendships
903
+ .flatMap((friendship) => (friendship.parents ?? []).map((parent) => ({ friendship, parent })))
904
+ .find(({ parent }) => parent.id === parentId);
905
+ if (!match) {
906
+ throw new CliError("invalid_arguments", `${parentId} is not a parent of one of ${name}'s friends. Run \`kid friends --student ${kidId}\`.`);
907
+ }
908
+ const body = { toUserId: parentId };
909
+ return writeCommand(parsed, {
910
+ action: `send a friend request to ${kidName(match.parent)}`,
911
+ target: {
912
+ ...kidTarget(kid),
913
+ parentId,
914
+ parent: kidName(match.parent),
915
+ parentOf: kidName(match.friendship.user),
916
+ },
917
+ request: body,
918
+ details: {
919
+ consequence: "The other parent gets a friend request from you; once accepted you can message each other.",
920
+ },
921
+ }, async () => unwrap(await api.client.POST("/friends/friend-request/", { body })));
922
+ }
923
+ if (verb === "pair-device") {
924
+ const body = { kidUserId: kidId };
925
+ return writeCommand(parsed, {
926
+ action: `issue a single-use code that signs ${name} into a new device`,
927
+ target: kidTarget(kid),
928
+ request: body,
929
+ details: {
930
+ // device-pairing.ts PAIRING_TTL_MS.
931
+ expiresInMinutes: 5,
932
+ consequence: "The result (pairingUrl, shortCode) is a live sign-in for this kid. Give it only to the guardian for the device in front of them.",
933
+ },
934
+ }, async () => unwrap(await api.client.POST("/auth/device-pairing/generate/", { body })));
935
+ }
936
+ if (verb === "goal-schedule" ||
937
+ verb === "pause-goal" ||
938
+ verb === "resume-goal") {
939
+ const goalId = flagUuid(parsed, "goal", { required: true });
940
+ const schedule = verb === "goal-schedule"
941
+ ? flagString(parsed, "schedule", { required: true }).trim()
942
+ : undefined;
943
+ const status = verb === "pause-goal"
944
+ ? "PAUSED"
945
+ : verb === "resume-goal"
946
+ ? "ACTIVE"
947
+ : undefined;
948
+ const { goals } = unwrap(await api.client.GET("/parent/kid/{kidId}/goals/", {
949
+ params: { path: { kidId } },
950
+ }));
951
+ const goal = goals.find((candidate) => candidate.id === goalId);
952
+ if (!goal) {
953
+ throw new CliError("not_found", `${name} has no goal ${goalId}. Run \`kid goals\` for their goals.`);
954
+ }
955
+ if (status && goal.status === status) {
956
+ return {
957
+ skipped: true,
958
+ reason: `"${goal.title}" is already ${status === "PAUSED" ? "paused" : "active"}.`,
959
+ };
960
+ }
961
+ if (status && goal.status === "COMPLETED") {
962
+ throw new CliError("invalid_arguments", `"${goal.title}" is archived (completed); it can't be paused or resumed.`);
963
+ }
964
+ const body = {
965
+ ...(schedule !== undefined ? { schedule } : {}),
966
+ ...(status !== undefined ? { status } : {}),
967
+ };
968
+ return writeCommand(parsed, {
969
+ action: schedule !== undefined
970
+ ? `change the schedule of ${name}'s goal "${goal.title}"`
971
+ : `${status === "PAUSED" ? "pause" : "resume"} ${name}'s goal "${goal.title}"`,
972
+ target: { ...kidTarget(kid), goalId },
973
+ request: body,
974
+ details: {
975
+ before: { schedule: goal.schedule, status: goal.status },
976
+ after: {
977
+ schedule: schedule ?? goal.schedule,
978
+ status: status ?? goal.status,
979
+ },
980
+ consequence: schedule !== undefined
981
+ ? "Daily plans follow the new cadence from the next plan on."
982
+ : status === "PAUSED"
983
+ ? "No new work is planned for this goal until it is resumed; its progress is kept."
984
+ : "The goal is planned again (it takes one of the kid's open-goal slots).",
985
+ },
986
+ }, async () => unwrap(await api.client.PATCH("/parent/kid/{kidId}/goals/{goalId}/", {
987
+ params: { path: { kidId, goalId } },
988
+ body,
989
+ })));
990
+ }
991
+ if (verb === "goal-note") {
992
+ const goalId = flagUuid(parsed, "goal", { required: true });
993
+ return unwrap(await api.client.GET("/parent/kid/{kidId}/goals/{goalId}/note/", {
994
+ params: { path: { kidId, goalId } },
995
+ }));
996
+ }
997
+ if (verb === "set-goal-note") {
998
+ const goalId = flagUuid(parsed, "goal", { required: true });
999
+ const note = flagString(parsed, "note")?.trim();
1000
+ const clear = hasFlag(parsed, "clear");
1001
+ if ((note === undefined) === !clear) {
1002
+ throw new CliError("invalid_arguments", "Pass --note TEXT, or --clear to remove the note.");
1003
+ }
1004
+ const text = clear ? "" : note;
1005
+ if (!clear && !text) {
1006
+ throw new CliError("invalid_arguments", "--note cannot be empty; use --clear to remove the note.");
1007
+ }
1008
+ if (text.length > GOAL_NOTE_MAX_CHARS) {
1009
+ throw new CliError("invalid_arguments", `--note must be ${GOAL_NOTE_MAX_CHARS} characters or fewer.`);
1010
+ }
1011
+ const current = unwrap(await api.client.GET("/parent/kid/{kidId}/goals/{goalId}/note/", {
1012
+ params: { path: { kidId, goalId } },
1013
+ }));
1014
+ return writeCommand(parsed, {
1015
+ action: clear
1016
+ ? `clear the guidance note on ${name}'s goal "${current.title}"`
1017
+ : `set the guidance note on ${name}'s goal "${current.title}"`,
1018
+ target: { ...kidTarget(kid), goalId },
1019
+ request: { text },
1020
+ details: {
1021
+ before: current.note,
1022
+ after: clear ? null : text,
1023
+ consequence: "Rocky and the daily planner read this note when planning and teaching this goal (it replaces the current note).",
1024
+ },
1025
+ }, async () => unwrap(await api.client.PUT("/parent/kid/{kidId}/goals/{goalId}/note/", {
1026
+ params: { path: { kidId, goalId } },
1027
+ body: { text },
1028
+ })));
1029
+ }
1030
+ if (verb === "add-todo") {
1031
+ const title = flagString(parsed, "title", { required: true }).trim();
1032
+ if (!title)
1033
+ throw new CliError("invalid_arguments", "--title cannot be empty.");
1034
+ const dueDate = flagDate(parsed, "due-date");
1035
+ const url = flagString(parsed, "url");
1036
+ if (url !== undefined && !/^https?:\/\/\S+$/.test(url)) {
1037
+ throw new CliError("invalid_arguments", "--url must be an http(s) URL.");
1038
+ }
1039
+ const targetDurationInMins = flagInteger(parsed, "minutes", {
1040
+ min: 1,
1041
+ max: 600,
1042
+ });
1043
+ const body = {
1044
+ title,
1045
+ ...(dueDate !== undefined ? { dueDate } : {}),
1046
+ ...(url !== undefined ? { url } : {}),
1047
+ ...(targetDurationInMins !== undefined ? { targetDurationInMins } : {}),
1048
+ };
1049
+ return writeCommand(parsed, {
1050
+ action: `add the todo "${title}" for ${name}`,
1051
+ target: kidTarget(kid),
1052
+ request: body,
1053
+ details: {
1054
+ consequence: "A one-off todo appears in the kid's list (on its due day) and the kid gets a notification.",
1055
+ },
1056
+ }, async () => unwrap(await api.client.POST("/parent/kid/{kidId}/todos/", {
1057
+ params: { path: { kidId } },
1058
+ body,
1059
+ })));
1060
+ }
1061
+ if (verb === "todo") {
1062
+ const todoId = flagUuid(parsed, "todo", { required: true });
1063
+ return unwrap(await api.client.GET("/parent/kid/{kidId}/todos/{todoId}/", {
1064
+ params: { path: { kidId, todoId } },
1065
+ }));
1066
+ }
1067
+ if (verb === "move-todo" || verb === "end-session") {
1068
+ const todoId = flagUuid(parsed, "todo", { required: true });
1069
+ const dueDate = verb === "move-todo" ? flagDate(parsed, "due-date") : undefined;
1070
+ if (verb === "move-todo" && dueDate === undefined) {
1071
+ throw new CliError("invalid_arguments", "Missing required --due-date.");
1072
+ }
1073
+ const todo = unwrap(await api.client.GET("/parent/kid/{kidId}/todos/{todoId}/", {
1074
+ params: { path: { kidId, todoId } },
1075
+ }));
1076
+ if (verb === "move-todo") {
1077
+ if (todo.status !== "NOT_STARTED" ||
1078
+ todo.completedAt ||
1079
+ todo.activeSession) {
1080
+ throw new CliError("invalid_arguments", `"${todo.title}" is ${todo.activeSession ? "in a session" : todo.status}; only a todo the kid hasn't started can be moved.`);
1081
+ }
1082
+ return writeCommand(parsed, {
1083
+ action: `move ${name}'s todo "${todo.title}" to ${dueDate}`,
1084
+ target: { ...kidTarget(kid), todoId },
1085
+ request: { dueDate },
1086
+ details: {
1087
+ before: { dueDate: todo.dueDate },
1088
+ after: { dueDate },
1089
+ consequence: "The todo shows up on the new day instead.",
1090
+ },
1091
+ }, async () => unwrap(await api.client.PATCH("/parent/kid/{kidId}/todos/{todoId}/", {
1092
+ params: { path: { kidId, todoId } },
1093
+ body: { dueDate: dueDate },
1094
+ })));
1095
+ }
1096
+ if (!todo.activeSession) {
1097
+ throw new CliError("invalid_arguments", `"${todo.title}" has no active session to end.`);
1098
+ }
1099
+ return writeCommand(parsed, {
1100
+ action: `end the stuck session on ${name}'s todo "${todo.title}"`,
1101
+ target: { ...kidTarget(kid), todoId },
1102
+ request: {},
1103
+ details: {
1104
+ session: todo.activeSession,
1105
+ consequence: "The session ends at its last activity. The todo is NOT completed and no XP is awarded; it stays started, so it can then be removed. Refused if the kid was active in the last 10 minutes.",
1106
+ },
1107
+ }, async () => unwrap(await api.client.POST("/parent/kid/{kidId}/todos/{todoId}/end-session/", { params: { path: { kidId, todoId } } })));
1108
+ }
1109
+ throw new CliError("invalid_arguments", "Use kid today|goals|xp|map-scores|classes|profile|set-profile|texts|set-texts|set-rooms|feed-lock|set-feed-lock|logins|reveal-login|add-login|edit-login|remove-login|excuse|cowork|switch-cowork|friends|friend-parent|pair-device|goal-schedule|pause-goal|resume-goal|goal-note|set-goal-note|add-todo|todo|move-todo|end-session.");
1110
+ }
1111
+ //# sourceMappingURL=family.js.map