recess-cli 3.49.0 → 3.50.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/cli.js CHANGED
@@ -25,6 +25,7 @@ import { runFamiliesCommand } from "./commands/families.js";
25
25
  import { runFamilyCommand, runKidCommand, runMeCommand, } from "./commands/family.js";
26
26
  import { runStudentsTextsCommand, runUsersPhoneCommand, runUsersTextCommand, runStudentsTextParentCommand, } from "./commands/phone-and-texts.js";
27
27
  import { hasCommunityHour, runUsersCommunityHourCommand, } from "./commands/community-hour.js";
28
+ import { runUsersBirthdayCommand } from "./commands/birthday.js";
28
29
  import { runTuitionPlansCommand } from "./commands/tuition-plans.js";
29
30
  import { runReportsCommand } from "./commands/reports.js";
30
31
  import { runMasteryCommand } from "./commands/mastery.js";
@@ -35,7 +36,7 @@ import { runFlagsCommand } from "./commands/flags.js";
35
36
  import { runRockyFreeCommand } from "./commands/rocky-free.js";
36
37
  import { runSchoolCommand } from "./commands/school.js";
37
38
  import { runVillageEventsCommand } from "./commands/village-events.js";
38
- import { assertChoice, flagIdList, positional, readJsonFile, readJsonValue, } from "./commands/shared.js";
39
+ import { assertChoice, flagDate, flagIdList, positional, readJsonFile, readJsonValue, } from "./commands/shared.js";
39
40
  import { CliError } from "./errors.js";
40
41
  import { listFeedback, submitFeedback } from "./feedback.js";
41
42
  import { HELP } from "./help.js";
@@ -2047,20 +2048,6 @@ function flagItemDateMs(parsed) {
2047
2048
  }
2048
2049
  return ms;
2049
2050
  }
2050
- function flagDateOnly(parsed, name) {
2051
- const raw = flagString(parsed, name);
2052
- if (raw === undefined)
2053
- return undefined;
2054
- const parsedDate = /^\d{4}-\d{2}-\d{2}$/.test(raw)
2055
- ? new Date(`${raw}T00:00:00.000Z`)
2056
- : null;
2057
- if (!parsedDate ||
2058
- Number.isNaN(parsedDate.getTime()) ||
2059
- parsedDate.toISOString().slice(0, 10) !== raw) {
2060
- throw new CliError("invalid_arguments", `--${name} must be a valid YYYY-MM-DD date.`);
2061
- }
2062
- return raw;
2063
- }
2064
2051
  const DAY_MS = 24 * 60 * 60 * 1000;
2065
2052
  async function waitForContentLibraryLive(api, gems, timeoutSeconds) {
2066
2053
  const pending = new Set(gems);
@@ -3270,6 +3257,9 @@ export async function executeRecessCommand(argv, options = {}) {
3270
3257
  if (noun === "users" && verb === "phone") {
3271
3258
  return runUsersPhoneCommand({ parsed, api, writeCommand });
3272
3259
  }
3260
+ if (noun === "users" && verb === "birthday") {
3261
+ return runUsersBirthdayCommand({ parsed, api, writeCommand });
3262
+ }
3273
3263
  if (noun === "users" && verb === "text") {
3274
3264
  return runUsersTextCommand({ parsed, api, writeCommand });
3275
3265
  }
@@ -6828,7 +6818,7 @@ export async function executeRecessCommand(argv, options = {}) {
6828
6818
  const todoId = positional(parsed, 2, "todo ID");
6829
6819
  const student = await studentFlag(api, parsed, { required: true });
6830
6820
  const studentId = student.id;
6831
- const targetDueDateISO = flagDateOnly(parsed, "due-date");
6821
+ const targetDueDateISO = flagDate(parsed, "due-date");
6832
6822
  const mode = flagString(parsed, "mode");
6833
6823
  if (mode !== undefined &&
6834
6824
  mode !== "game" &&
@@ -0,0 +1,81 @@
1
+ import { unwrap } from "../api.js";
2
+ import { CliError } from "../errors.js";
3
+ import { flagDate, positional } from "./shared.js";
4
+ /** apps/web-server/src/libs/birth-window.ts MIN_AGE/MAX_AGE: the school's kid ages. */
5
+ const KID_AGE_WINDOW = { min: 3, max: 21 };
6
+ /** Whole years from `birthdate` (YYYY-MM-DD) to `today`, as `users get` counts them. */
7
+ function ageOn(birthdate, today) {
8
+ const born = new Date(`${birthdate}T00:00:00.000Z`);
9
+ const hadBirthday = today.getUTCMonth() > born.getUTCMonth() ||
10
+ (today.getUTCMonth() === born.getUTCMonth() &&
11
+ today.getUTCDate() >= born.getUTCDate());
12
+ return today.getUTCFullYear() - born.getUTCFullYear() - (hadBirthday ? 0 : 1);
13
+ }
14
+ /**
15
+ * `users birthday set` — staff correction of a kid's birthday, typically a
16
+ * year typed in the wrong century (1911 for 2011, so Recess shows age 115).
17
+ * The parent's `kid set-profile` only reaches the caller's own kids; this
18
+ * writes the same kid-config field, which the server lets an admin set on any
19
+ * kid, so the change keeps its provenance and lands in the family change log.
20
+ */
21
+ export async function runUsersBirthdayCommand({ parsed, api, writeCommand, }) {
22
+ const action = positional(parsed, 2, "users birthday action");
23
+ if (action !== "set") {
24
+ throw new CliError("invalid_arguments", "Use users birthday set.");
25
+ }
26
+ const userId = positional(parsed, 3, "kid ID");
27
+ const birthdate = flagDate(parsed, "date", { required: true });
28
+ const age = ageOn(birthdate, new Date());
29
+ if (age < 0) {
30
+ throw new CliError("invalid_arguments", `--date ${birthdate} is in the future.`);
31
+ }
32
+ const { user } = unwrap(await api.client.GET("/admin/users/{userId}", {
33
+ params: { path: { userId } },
34
+ }));
35
+ const current = {
36
+ userId: user.id,
37
+ name: [user.firstName, user.lastName].filter(Boolean).join(" "),
38
+ role: user.role,
39
+ birthdate: user.birthdate?.slice(0, 10) ?? null,
40
+ age: user.age ?? null,
41
+ };
42
+ if (user.role !== "KID") {
43
+ throw new CliError("invalid_arguments", `${current.name || user.id} is a ${user.role}, not a KID. Only a kid's birthday is set here: pass the kid's user ID.`, 1, { current });
44
+ }
45
+ if (current.birthdate === birthdate) {
46
+ return { ...current, status: "unchanged" };
47
+ }
48
+ const warnings = age < KID_AGE_WINDOW.min || age > KID_AGE_WINDOW.max
49
+ ? [
50
+ `Age ${age} is outside the school's ${KID_AGE_WINDOW.min} to ${KID_AGE_WINDOW.max} window: check the year with the family before approving.`,
51
+ ]
52
+ : [];
53
+ return writeCommand(parsed, {
54
+ action: `change this kid's birthday from ${current.birthdate ?? "unset"} (age ${current.age ?? "unknown"}) to ${birthdate} (age ${age}); the family's change log shows it under your first name, and a guardian can undo it`,
55
+ target: { userId: user.id },
56
+ request: { path: "profile.birthdate", value: birthdate },
57
+ details: {
58
+ current,
59
+ after: { birthdate, age },
60
+ ...(warnings.length > 0 ? { warnings } : {}),
61
+ },
62
+ }, async () => {
63
+ const { result } = unwrap(await api.client.PATCH("/kid-config/kid/{kidId}/", {
64
+ params: { path: { kidId: user.id }, query: { surface: "admin" } },
65
+ body: { path: "profile.birthdate", value: birthdate },
66
+ }));
67
+ if (result.status === "unconfirmed") {
68
+ throw new CliError("write_unconfirmed", `The server accepted the change but still reads ${String(result.after)}. Re-read with users get ${user.id}.`);
69
+ }
70
+ // What the server read back, not what was sent: a concurrent edit wins.
71
+ const saved = typeof result.after === "string" ? result.after : null;
72
+ return {
73
+ ...current,
74
+ birthdate: saved,
75
+ age: saved === null ? null : ageOn(saved, new Date()),
76
+ status: result.status,
77
+ changeId: result.changeId,
78
+ };
79
+ });
80
+ }
81
+ //# sourceMappingURL=birthday.js.map
@@ -3,7 +3,7 @@ import { unwrap } from "../api.js";
3
3
  import { flagString, hasFlag } from "../args.js";
4
4
  import { apiError, CliError } from "../errors.js";
5
5
  import { resolveStudentReference } from "../goal-authoring.js";
6
- import { assertChoice, flagBooleanValue, flagIdList, flagInteger, } from "./shared.js";
6
+ import { assertChoice, flagBooleanValue, flagDate, flagIdList, flagInteger, } from "./shared.js";
7
7
  // packages/web-schema COMMUNITY_HOUR_COURSE_ID: the daily coworking pods are
8
8
  // this course's event series (apps/web `$lib/onboarding/cowork.ts`).
9
9
  const COWORK_COURSE_ID = "b96a9f7d-7851-4506-965e-2d9babd50b11";
@@ -12,7 +12,6 @@ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
12
12
  const DEFAULT_SUMMARY_SEND_HOUR = 18;
13
13
  // lesson-notes.ts LESSON_NOTE_MAX_CHARS: the server's goal-note cap.
14
14
  const GOAL_NOTE_MAX_CHARS = 2000;
15
- const DATE = /^\d{4}-\d{2}-\d{2}$/;
16
15
  const FEED_LOCK_MODES = [
17
16
  "ALL_DAILY_TODOS",
18
17
  "SELECTED_GOALS",
@@ -83,15 +82,6 @@ function redactedSecret(secret) {
83
82
  .slice(0, 12),
84
83
  };
85
84
  }
86
- function flagDate(parsed, name) {
87
- const value = flagString(parsed, name);
88
- if (value !== undefined &&
89
- (!DATE.test(value) ||
90
- new Date(`${value}T00:00:00.000Z`).toISOString().slice(0, 10) !== value)) {
91
- throw new CliError("invalid_arguments", `--${name} must be a valid YYYY-MM-DD date.`);
92
- }
93
- return value;
94
- }
95
85
  function flagUuid(parsed, name, options = {}) {
96
86
  const value = flagString(parsed, name, options);
97
87
  if (value !== undefined && !UUID.test(value)) {
@@ -69,6 +69,21 @@ export function flagIsoInstant(parsed, name, options = {}) {
69
69
  }
70
70
  return raw;
71
71
  }
72
+ /** A `YYYY-MM-DD` date that exists: 2015-02-31 and 2015-13-01 are refused. */
73
+ export function flagDate(parsed, name, options = {}) {
74
+ const raw = flagString(parsed, name, options);
75
+ if (raw === undefined)
76
+ return undefined;
77
+ const date = /^\d{4}-\d{2}-\d{2}$/.test(raw)
78
+ ? new Date(`${raw}T00:00:00.000Z`)
79
+ : null;
80
+ if (!date ||
81
+ Number.isNaN(date.getTime()) ||
82
+ date.toISOString().slice(0, 10) !== raw) {
83
+ throw new CliError("invalid_arguments", `--${name} must be a valid YYYY-MM-DD date.`);
84
+ }
85
+ return raw;
86
+ }
72
87
  export async function readJsonValue(filePath, label) {
73
88
  const absolutePath = path.resolve(filePath);
74
89
  let raw;
package/dist/help.js CHANGED
@@ -52,6 +52,7 @@ Usage:
52
52
  recess [--json] users phone get <user-id>
53
53
  recess [--json] users phone set <user-id> --phone <number> [--confirm]
54
54
  recess [--json] users phone clear <user-id> [--confirm]
55
+ recess [--json] users birthday set <kid-id> --date YYYY-MM-DD [--confirm]
55
56
  recess [--json] users text <user-id> --text TEXT [--confirm]
56
57
  recess [--json] users lock <user-id> [--confirm]
57
58
  recess [--json] users unlock <user-id> [--confirm]
@@ -912,6 +913,11 @@ account — the confirmed write's own response is the record of what changed.
912
913
  without +country is read as US), rejects invalid or already-taken numbers, and
913
914
  marks the new number unverified until the user's next phone sign-in.
914
915
 
916
+ "users birthday set" corrects any kid's birthday, e.g. a wrong-century year that
917
+ makes "users get" show age 115 ("kid set-profile" reaches only your own kids).
918
+ The preview shows the age before and after, and warns outside ages 3 to 21. The
919
+ family's change log shows the change under your first name; a guardian can undo it.
920
+
915
921
  Parent SMS summary notes: "students texts get" shows the kid-level switch and
916
922
  end-of-day send hour (0-23 in the kid's timezone; unset = 18) plus every
917
923
  recipient's phone, texts on/off, frequency, and focus. "set" changes the
@@ -1274,6 +1280,7 @@ export const COMMAND_SUMMARIES = {
1274
1280
  "users phone get": "Read a user's phone number and verification.",
1275
1281
  "users phone set": "Set a user's phone number (stored E.164, unverified).",
1276
1282
  "users phone clear": "Remove a user's phone number.",
1283
+ "users birthday set": "Correct any kid's birthday (shows the age it gives).",
1277
1284
  "users text": "Text a parent from Rocky's number, signed with your first name.",
1278
1285
  "users community-hour get": "Show whether a kid can join Community Hour.",
1279
1286
  "users community-hour unlock": "Let a kid join Community Hour and enter the Village.",
@@ -1773,7 +1780,7 @@ export const NOUN_SUMMARIES = {
1773
1780
  jobs: "Local ledger of write operations by operation key.",
1774
1781
  feedback: "Send or list feedback about this CLI.",
1775
1782
  auth: "Sign in (browser or headless), session status, sign out.",
1776
- users: "Accounts: search/get, lock/unlock, community-hour, disable/restore, phone, tier, school status.",
1783
+ users: "Accounts: search/get, lock/unlock, community-hour, disable/restore, phone, birthday, tier, school status.",
1777
1784
  guides: "Create and invite guide accounts.",
1778
1785
  guardians: "Invite guardians into a family.",
1779
1786
  students: "Kids: roster, today, schedule, todos, analysis, XP, SMS summaries, notes.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "recess-cli",
3
- "version": "3.49.0",
3
+ "version": "3.50.0",
4
4
  "description": "Safe Recess administration and family AI tools from the command line.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {