recess-cli 3.21.0 → 3.22.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/args.js +1 -0
- package/dist/cli.js +4 -0
- package/dist/commands/rocky-free.js +118 -0
- package/dist/help.js +12 -1
- package/package.json +1 -1
package/dist/args.js
CHANGED
package/dist/cli.js
CHANGED
|
@@ -25,6 +25,7 @@ import { runReportsCommand } from "./commands/reports.js";
|
|
|
25
25
|
import { runMasteryCommand } from "./commands/mastery.js";
|
|
26
26
|
import { runOnboardingCommand } from "./commands/onboarding.js";
|
|
27
27
|
import { runScheduleCommand, runMemoryFilesCommand, } from "./commands/safe-staff-operations.js";
|
|
28
|
+
import { runRockyFreeCommand } from "./commands/rocky-free.js";
|
|
28
29
|
import { runSchoolCommand } from "./commands/school.js";
|
|
29
30
|
import { runVillageEventsCommand } from "./commands/village-events.js";
|
|
30
31
|
import { assertChoice, flagIdList, positional, readJsonFile, readJsonValue, } from "./commands/shared.js";
|
|
@@ -6496,6 +6497,9 @@ export async function executeRecessCommand(argv, options = {}) {
|
|
|
6496
6497
|
}
|
|
6497
6498
|
throw new CliError("invalid_arguments", "Use memories context|log.");
|
|
6498
6499
|
}
|
|
6500
|
+
if (noun === "rocky" && verb === "free") {
|
|
6501
|
+
return runRockyFreeCommand({ parsed, api, writeCommand });
|
|
6502
|
+
}
|
|
6499
6503
|
if (noun === "rocky") {
|
|
6500
6504
|
const studentId = flagString(parsed, "student", { required: true });
|
|
6501
6505
|
if (verb === "get") {
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { unwrap } from "../api.js";
|
|
2
|
+
import { flagNumber, flagString, hasFlag } from "../args.js";
|
|
3
|
+
import { CliError } from "../errors.js";
|
|
4
|
+
const MAX_DAILY_BUDGET_USD = 20;
|
|
5
|
+
function budgetFlag(context) {
|
|
6
|
+
const budget = flagNumber(context.parsed, "budget");
|
|
7
|
+
if (budget === undefined)
|
|
8
|
+
return undefined;
|
|
9
|
+
if (budget <= 0 || budget > MAX_DAILY_BUDGET_USD) {
|
|
10
|
+
throw new CliError("invalid_arguments", `--budget must be more than 0 and at most ${MAX_DAILY_BUDGET_USD} (USD per day).`);
|
|
11
|
+
}
|
|
12
|
+
return budget;
|
|
13
|
+
}
|
|
14
|
+
function currentStatus(status) {
|
|
15
|
+
return {
|
|
16
|
+
role: status.role,
|
|
17
|
+
plan: status.plan,
|
|
18
|
+
eligible: status.eligible,
|
|
19
|
+
schoolTierId: status.schoolTierId,
|
|
20
|
+
viaFlag: status.viaFlag,
|
|
21
|
+
grant: status.grant,
|
|
22
|
+
dailyBudgetUsd: status.dailyBudgetUsd,
|
|
23
|
+
defaultDailyBudgetUsd: status.defaultDailyBudgetUsd,
|
|
24
|
+
todayUsd: status.days.find((day) => day.day === status.today)?.costUsd ?? 0,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export async function runRockyFreeCommand(context) {
|
|
28
|
+
const { parsed, api, writeCommand } = context;
|
|
29
|
+
const verb = parsed.positionals[2];
|
|
30
|
+
if (verb === "list") {
|
|
31
|
+
return unwrap(await api.client.GET("/tutor/free-rocky/grants"));
|
|
32
|
+
}
|
|
33
|
+
if (verb !== "get" &&
|
|
34
|
+
verb !== "grant" &&
|
|
35
|
+
verb !== "set-budget" &&
|
|
36
|
+
verb !== "revoke") {
|
|
37
|
+
throw new CliError("invalid_arguments", "Use rocky free list|get|grant|set-budget|revoke.");
|
|
38
|
+
}
|
|
39
|
+
const studentId = flagString(parsed, "student", { required: true });
|
|
40
|
+
const status = unwrap(await api.client.GET("/tutor/students/{studentId}/free-rocky", {
|
|
41
|
+
params: { path: { studentId } },
|
|
42
|
+
}));
|
|
43
|
+
if (verb === "get")
|
|
44
|
+
return status;
|
|
45
|
+
const putBudget = (dailyBudgetUsd) => async () => unwrap(await api.client.PUT("/tutor/students/{studentId}/free-rocky", {
|
|
46
|
+
params: { path: { studentId } },
|
|
47
|
+
body: { dailyBudgetUsd },
|
|
48
|
+
}));
|
|
49
|
+
if (verb === "grant") {
|
|
50
|
+
if (hasFlag(parsed, "default")) {
|
|
51
|
+
throw new CliError("invalid_arguments", "grant takes --budget or nothing (the default budget); --default is for set-budget.");
|
|
52
|
+
}
|
|
53
|
+
const dailyBudgetUsd = budgetFlag(context) ?? null;
|
|
54
|
+
const alreadyGranted = status.grant?.active === true;
|
|
55
|
+
return writeCommand(parsed, {
|
|
56
|
+
action: alreadyGranted
|
|
57
|
+
? "change the daily budget of this user's existing free Rocky grant"
|
|
58
|
+
: "grant free Rocky to this user",
|
|
59
|
+
target: { studentUserId: studentId },
|
|
60
|
+
request: { dailyBudgetUsd },
|
|
61
|
+
details: {
|
|
62
|
+
current: currentStatus(status),
|
|
63
|
+
warnings: status.warnings,
|
|
64
|
+
budgetAfterUsd: dailyBudgetUsd ?? status.defaultDailyBudgetUsd,
|
|
65
|
+
budgetSource: dailyBudgetUsd === null ? "default" : "custom",
|
|
66
|
+
consequences: [
|
|
67
|
+
alreadyGranted
|
|
68
|
+
? "The grant is already active: only its daily budget changes; grantedAt and grantedBy stay."
|
|
69
|
+
: "Starts a new grant stamped with you as grantedBy; a revoked grant is re-granted.",
|
|
70
|
+
"ADMIN-only (exact-admin): a GUIDE session gets 403.",
|
|
71
|
+
],
|
|
72
|
+
reverse: `\`rocky free revoke --student ${studentId}\``,
|
|
73
|
+
},
|
|
74
|
+
}, putBudget(dailyBudgetUsd));
|
|
75
|
+
}
|
|
76
|
+
if (!status.grant?.active) {
|
|
77
|
+
throw new CliError("not_found", `User ${studentId} has no active free Rocky grant${status.viaFlag ? " (free Rocky comes from the feature flag, not a grant)" : ""}. Use rocky free grant.`);
|
|
78
|
+
}
|
|
79
|
+
if (verb === "set-budget") {
|
|
80
|
+
const budget = budgetFlag(context);
|
|
81
|
+
const useDefault = hasFlag(parsed, "default");
|
|
82
|
+
if ((budget === undefined) === !useDefault) {
|
|
83
|
+
throw new CliError("invalid_arguments", "Pass exactly one of --budget <usd> or --default.");
|
|
84
|
+
}
|
|
85
|
+
const dailyBudgetUsd = budget ?? null;
|
|
86
|
+
return writeCommand(parsed, {
|
|
87
|
+
action: "change the daily budget of this user's free Rocky grant",
|
|
88
|
+
target: { studentUserId: studentId },
|
|
89
|
+
request: { dailyBudgetUsd },
|
|
90
|
+
details: {
|
|
91
|
+
current: currentStatus(status),
|
|
92
|
+
warnings: status.warnings,
|
|
93
|
+
budgetBeforeUsd: status.dailyBudgetUsd,
|
|
94
|
+
budgetAfterUsd: dailyBudgetUsd ?? status.defaultDailyBudgetUsd,
|
|
95
|
+
budgetSource: dailyBudgetUsd === null ? "default" : "custom",
|
|
96
|
+
},
|
|
97
|
+
}, putBudget(dailyBudgetUsd));
|
|
98
|
+
}
|
|
99
|
+
return writeCommand(parsed, {
|
|
100
|
+
action: "revoke this user's free Rocky grant",
|
|
101
|
+
target: { studentUserId: studentId },
|
|
102
|
+
request: {},
|
|
103
|
+
details: {
|
|
104
|
+
current: currentStatus(status),
|
|
105
|
+
warnings: status.warnings,
|
|
106
|
+
consequences: [
|
|
107
|
+
status.viaFlag
|
|
108
|
+
? "The feature flag still gives this user free Rocky after the revoke."
|
|
109
|
+
: "Free Rocky stops for this user right away.",
|
|
110
|
+
"The grant row is kept (revokedAt/revokedBy); `rocky free grant` re-grants it.",
|
|
111
|
+
"ADMIN-only (exact-admin): a GUIDE session gets 403.",
|
|
112
|
+
],
|
|
113
|
+
},
|
|
114
|
+
}, async () => unwrap(await api.client.DELETE("/tutor/students/{studentId}/free-rocky", {
|
|
115
|
+
params: { path: { studentId } },
|
|
116
|
+
})));
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=rocky-free.js.map
|
package/dist/help.js
CHANGED
|
@@ -594,6 +594,12 @@ Usage:
|
|
|
594
594
|
recess [--json] rocky get --student <kid-id>
|
|
595
595
|
recess [--json] rocky set --student <kid-id> --patch-file <path/patch.json>
|
|
596
596
|
[--expected-updated-at ISO|none] [--confirm]
|
|
597
|
+
recess [--json] rocky free list
|
|
598
|
+
recess [--json] rocky free get --student <user-id>
|
|
599
|
+
recess [--json] rocky free grant --student <user-id> [--budget <usd>] [--confirm]
|
|
600
|
+
recess [--json] rocky free set-budget --student <user-id> (--budget <usd> | --default)
|
|
601
|
+
[--confirm]
|
|
602
|
+
recess [--json] rocky free revoke --student <user-id> [--confirm]
|
|
597
603
|
recess [--json] tutor-templates list [--q TEXT] [--subject TEXT] [--grade N]
|
|
598
604
|
recess [--json] tutor-templates get <slug>
|
|
599
605
|
recess [--json] tutor-templates assign <slug> [--student <kid-id>] [--confirm]
|
|
@@ -1396,6 +1402,11 @@ export const COMMAND_SUMMARIES = {
|
|
|
1396
1402
|
"memories log": "Read a kid's memory log for a date.",
|
|
1397
1403
|
"rocky get": "Read a kid's Rocky personality settings.",
|
|
1398
1404
|
"rocky set": "Patch a kid's Rocky personality settings.",
|
|
1405
|
+
"rocky free list": "List everyone with an active free Rocky grant.",
|
|
1406
|
+
"rocky free get": "Read a user's free Rocky plan, grant, budget, and usage.",
|
|
1407
|
+
"rocky free grant": "Grant free Rocky to a kid or guardian.",
|
|
1408
|
+
"rocky free set-budget": "Change a free Rocky grant's daily budget.",
|
|
1409
|
+
"rocky free revoke": "Revoke a user's free Rocky grant.",
|
|
1399
1410
|
"tutor-templates list": "List tutor templates.",
|
|
1400
1411
|
"tutor-templates get": "Read one tutor template.",
|
|
1401
1412
|
"tutor-templates assign": "Assign a tutor template to a kid.",
|
|
@@ -1461,7 +1472,7 @@ export const NOUN_SUMMARIES = {
|
|
|
1461
1472
|
goals: "Kids' goals: create/edit, queue, workspace files, PDFs, videos.",
|
|
1462
1473
|
todos: "Kids' todos: create, edit, complete, analysis, applets.",
|
|
1463
1474
|
memories: "Kid memory files and the context Rocky sees.",
|
|
1464
|
-
rocky: "A kid's Rocky personality settings.",
|
|
1475
|
+
rocky: "A kid's Rocky personality settings; free Rocky grants and budgets.",
|
|
1465
1476
|
"tutor-templates": "Tutor templates and their assignment to kids.",
|
|
1466
1477
|
"library-books": "Book library: search the web, add books, read status.",
|
|
1467
1478
|
mastery: "Mastery graphs and the content linked to them.",
|