recess-cli 3.28.0 → 3.29.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 +4 -0
- package/dist/commands/flags.js +185 -0
- package/dist/help.js +17 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -30,6 +30,7 @@ import { runMasteryCommand } from "./commands/mastery.js";
|
|
|
30
30
|
import { runOnboardingCommand } from "./commands/onboarding.js";
|
|
31
31
|
import { runScheduleCommand, runMemoryFilesCommand, } from "./commands/safe-staff-operations.js";
|
|
32
32
|
import { runPlacementCommand } from "./commands/placement.js";
|
|
33
|
+
import { runFlagsCommand } from "./commands/flags.js";
|
|
33
34
|
import { runRockyFreeCommand } from "./commands/rocky-free.js";
|
|
34
35
|
import { runSchoolCommand } from "./commands/school.js";
|
|
35
36
|
import { runVillageEventsCommand } from "./commands/village-events.js";
|
|
@@ -6604,6 +6605,9 @@ export async function executeRecessCommand(argv, options = {}) {
|
|
|
6604
6605
|
if (noun === "rocky" && verb === "free") {
|
|
6605
6606
|
return runRockyFreeCommand({ parsed, api, writeCommand });
|
|
6606
6607
|
}
|
|
6608
|
+
if (noun === "flags") {
|
|
6609
|
+
return runFlagsCommand({ parsed, api, writeCommand });
|
|
6610
|
+
}
|
|
6607
6611
|
if (noun === "rocky") {
|
|
6608
6612
|
const studentId = flagString(parsed, "student", { required: true });
|
|
6609
6613
|
if (verb === "get") {
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { unwrap } from "../api.js";
|
|
2
|
+
import { flagString } from "../args.js";
|
|
3
|
+
import { CliError } from "../errors.js";
|
|
4
|
+
import { positional, readJsonFile } from "./shared.js";
|
|
5
|
+
const ROLES = [
|
|
6
|
+
"KID",
|
|
7
|
+
"GUARDIAN",
|
|
8
|
+
"GUIDE",
|
|
9
|
+
"MODERATOR",
|
|
10
|
+
"ADMIN",
|
|
11
|
+
"DISABLED",
|
|
12
|
+
"PROGRAM",
|
|
13
|
+
"GUEST",
|
|
14
|
+
];
|
|
15
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
16
|
+
const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
17
|
+
function list(context, name) {
|
|
18
|
+
const raw = flagString(context.parsed, name);
|
|
19
|
+
return raw
|
|
20
|
+
? raw
|
|
21
|
+
.split(",")
|
|
22
|
+
.map((value) => value.trim())
|
|
23
|
+
.filter(Boolean)
|
|
24
|
+
: [];
|
|
25
|
+
}
|
|
26
|
+
function onOff(context, name) {
|
|
27
|
+
const raw = flagString(context.parsed, name);
|
|
28
|
+
if (raw === undefined)
|
|
29
|
+
return undefined;
|
|
30
|
+
if (raw === "on")
|
|
31
|
+
return true;
|
|
32
|
+
if (raw === "off")
|
|
33
|
+
return false;
|
|
34
|
+
throw new CliError("invalid_arguments", `--${name} takes on or off.`);
|
|
35
|
+
}
|
|
36
|
+
function targets(context) {
|
|
37
|
+
const userIds = list(context, "user");
|
|
38
|
+
const emails = list(context, "email").map((email) => email.toLowerCase());
|
|
39
|
+
const roles = list(context, "role").map((role) => role.toUpperCase());
|
|
40
|
+
const badId = userIds.find((id) => !UUID.test(id));
|
|
41
|
+
if (badId) {
|
|
42
|
+
throw new CliError("invalid_arguments", `--user ${badId} is not a user id.`);
|
|
43
|
+
}
|
|
44
|
+
const badEmail = emails.find((email) => !EMAIL.test(email));
|
|
45
|
+
if (badEmail) {
|
|
46
|
+
throw new CliError("invalid_arguments", `--email ${badEmail} is not an email.`);
|
|
47
|
+
}
|
|
48
|
+
const badRole = roles.find((role) => !ROLES.includes(role));
|
|
49
|
+
if (badRole) {
|
|
50
|
+
throw new CliError("invalid_arguments", `--role ${badRole} is not one of ${ROLES.join(", ")}.`);
|
|
51
|
+
}
|
|
52
|
+
if (!userIds.length && !emails.length && !roles.length) {
|
|
53
|
+
throw new CliError("invalid_arguments", "Pass at least one of --user <id,...>, --email <email,...>, --role <ROLE,...>.");
|
|
54
|
+
}
|
|
55
|
+
return { userIds, emails, roles: roles };
|
|
56
|
+
}
|
|
57
|
+
function current(flag) {
|
|
58
|
+
return {
|
|
59
|
+
enabled: flag.enabled,
|
|
60
|
+
everyone: flag.everyone,
|
|
61
|
+
roles: flag.roles,
|
|
62
|
+
emails: flag.emails,
|
|
63
|
+
users: flag.users.map((user) => `${[user.firstName, user.lastName].filter(Boolean).join(" ") || user.email || user.id} (${user.role})`),
|
|
64
|
+
payload: flag.payload,
|
|
65
|
+
updatedAt: flag.updatedAt,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export async function runFlagsCommand(context) {
|
|
69
|
+
const { parsed, api, writeCommand } = context;
|
|
70
|
+
const verb = parsed.positionals[1];
|
|
71
|
+
if (verb === "list") {
|
|
72
|
+
return unwrap(await api.client.GET("/admin/feature-flags/"));
|
|
73
|
+
}
|
|
74
|
+
const verbs = ["get", "create", "set", "add", "remove", "delete"];
|
|
75
|
+
if (!verb || !verbs.includes(verb)) {
|
|
76
|
+
throw new CliError("invalid_arguments", "Use flags list|get|create|set|add|remove|delete.");
|
|
77
|
+
}
|
|
78
|
+
const key = positional(parsed, 2, "flag key");
|
|
79
|
+
if (verb === "create") {
|
|
80
|
+
const description = flagString(parsed, "description") ?? null;
|
|
81
|
+
const name = flagString(parsed, "name")?.trim() || undefined;
|
|
82
|
+
return writeCommand(parsed, {
|
|
83
|
+
action: "create a feature flag (off, targeting no one)",
|
|
84
|
+
target: { key },
|
|
85
|
+
request: { key, name, description },
|
|
86
|
+
details: {
|
|
87
|
+
consequences: [
|
|
88
|
+
"The flag starts disabled; code reading it sees it off until `flags set --enabled on` and a target.",
|
|
89
|
+
],
|
|
90
|
+
reverse: `\`flags delete ${key}\``,
|
|
91
|
+
},
|
|
92
|
+
}, async () => unwrap(await api.client.POST("/admin/feature-flags/", {
|
|
93
|
+
body: { key, name, description },
|
|
94
|
+
})));
|
|
95
|
+
}
|
|
96
|
+
const flag = unwrap(await api.client.GET("/admin/feature-flags/{key}", {
|
|
97
|
+
params: { path: { key } },
|
|
98
|
+
}));
|
|
99
|
+
if (verb === "get")
|
|
100
|
+
return flag;
|
|
101
|
+
const patch = (body) => async () => unwrap(await api.client.PATCH("/admin/feature-flags/{key}", {
|
|
102
|
+
params: { path: { key } },
|
|
103
|
+
body: { ...body, expectedUpdatedAt: flag.updatedAt },
|
|
104
|
+
}));
|
|
105
|
+
if (verb === "set") {
|
|
106
|
+
const body = {};
|
|
107
|
+
const enabled = onOff(context, "enabled");
|
|
108
|
+
const everyone = onOff(context, "everyone");
|
|
109
|
+
const name = flagString(parsed, "name")?.trim();
|
|
110
|
+
const description = flagString(parsed, "description");
|
|
111
|
+
const payloadFile = flagString(parsed, "payload-file");
|
|
112
|
+
if (name)
|
|
113
|
+
body.name = name;
|
|
114
|
+
if (enabled !== undefined)
|
|
115
|
+
body.enabled = enabled;
|
|
116
|
+
if (everyone !== undefined)
|
|
117
|
+
body.everyone = everyone;
|
|
118
|
+
if (description !== undefined)
|
|
119
|
+
body.description = description || null;
|
|
120
|
+
if (payloadFile !== undefined) {
|
|
121
|
+
body.payload =
|
|
122
|
+
payloadFile === "none"
|
|
123
|
+
? null
|
|
124
|
+
: await readJsonFile(payloadFile, "--payload-file");
|
|
125
|
+
}
|
|
126
|
+
if (!Object.keys(body).length) {
|
|
127
|
+
throw new CliError("invalid_arguments", "Pass at least one of --enabled, --everyone, --name, --description, --payload-file.");
|
|
128
|
+
}
|
|
129
|
+
const turningOnForEveryone = (body.everyone ?? flag.everyone) && (body.enabled ?? flag.enabled);
|
|
130
|
+
return writeCommand(parsed, {
|
|
131
|
+
action: "change a feature flag",
|
|
132
|
+
target: { key },
|
|
133
|
+
request: body,
|
|
134
|
+
details: {
|
|
135
|
+
current: current(flag),
|
|
136
|
+
consequences: [
|
|
137
|
+
turningOnForEveryone
|
|
138
|
+
? "On for EVERY user (and signed-out visitors) within ~15 seconds."
|
|
139
|
+
: "Takes effect for matching users within ~15 seconds.",
|
|
140
|
+
],
|
|
141
|
+
},
|
|
142
|
+
}, patch(body));
|
|
143
|
+
}
|
|
144
|
+
if (verb === "add" || verb === "remove") {
|
|
145
|
+
const { userIds, emails, roles } = targets(context);
|
|
146
|
+
const body = verb === "add"
|
|
147
|
+
? { addUserIds: userIds, addEmails: emails, addRoles: roles }
|
|
148
|
+
: { removeUserIds: userIds, removeEmails: emails, removeRoles: roles };
|
|
149
|
+
return writeCommand(parsed, {
|
|
150
|
+
action: verb === "add"
|
|
151
|
+
? "turn a feature flag on for these users, emails or roles"
|
|
152
|
+
: "stop targeting these users, emails or roles with a feature flag",
|
|
153
|
+
target: { key },
|
|
154
|
+
request: body,
|
|
155
|
+
details: {
|
|
156
|
+
current: current(flag),
|
|
157
|
+
consequences: [
|
|
158
|
+
flag.enabled
|
|
159
|
+
? "The flag is enabled, so this takes effect within ~15 seconds."
|
|
160
|
+
: "The flag is disabled: nothing changes for anyone until `flags set --enabled on`.",
|
|
161
|
+
...(flag.everyone
|
|
162
|
+
? [
|
|
163
|
+
"The flag is on for everyone, so targeting lists don't matter while it stays that way.",
|
|
164
|
+
]
|
|
165
|
+
: []),
|
|
166
|
+
],
|
|
167
|
+
reverse: `\`flags ${verb === "add" ? "remove" : "add"} ${key} …\` with the same targets`,
|
|
168
|
+
},
|
|
169
|
+
}, patch(body));
|
|
170
|
+
}
|
|
171
|
+
return writeCommand(parsed, {
|
|
172
|
+
action: "delete a feature flag",
|
|
173
|
+
target: { key },
|
|
174
|
+
request: {},
|
|
175
|
+
details: {
|
|
176
|
+
current: current(flag),
|
|
177
|
+
consequences: [
|
|
178
|
+
"Code reading this key sees it as unknown (off) everywhere; the targeting lists are gone.",
|
|
179
|
+
],
|
|
180
|
+
},
|
|
181
|
+
}, async () => unwrap(await api.client.DELETE("/admin/feature-flags/{key}", {
|
|
182
|
+
params: { path: { key } },
|
|
183
|
+
})));
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=flags.js.map
|
package/dist/help.js
CHANGED
|
@@ -614,6 +614,15 @@ Usage:
|
|
|
614
614
|
recess [--json] rocky free set-budget --student <user-id> (--budget <usd> | --default)
|
|
615
615
|
[--confirm]
|
|
616
616
|
recess [--json] rocky free revoke --student <user-id> [--confirm]
|
|
617
|
+
recess [--json] flags list
|
|
618
|
+
recess [--json] flags get <key>
|
|
619
|
+
recess [--json] flags create <key> [--name TEXT] [--description TEXT] [--confirm]
|
|
620
|
+
recess [--json] flags set <key> [--enabled on|off] [--everyone on|off] [--name TEXT]
|
|
621
|
+
[--description TEXT] [--payload-file <path.json|none>] [--confirm]
|
|
622
|
+
recess [--json] flags add <key> [--user <id,...>] [--email <email,...>] [--role <ROLE,...>] [--confirm]
|
|
623
|
+
recess [--json] flags remove <key> [--user <id,...>] [--email <email,...>] [--role <ROLE,...>]
|
|
624
|
+
[--confirm]
|
|
625
|
+
recess [--json] flags delete <key> [--confirm]
|
|
617
626
|
recess [--json] tutor-templates list [--q TEXT] [--subject TEXT] [--grade N]
|
|
618
627
|
recess [--json] tutor-templates get <slug>
|
|
619
628
|
recess [--json] tutor-templates assign <slug> [--student <kid-id>] [--confirm]
|
|
@@ -1478,6 +1487,13 @@ export const COMMAND_SUMMARIES = {
|
|
|
1478
1487
|
"rocky free grant": "Grant free Rocky to a kid or guardian.",
|
|
1479
1488
|
"rocky free set-budget": "Change a free Rocky grant's weekly budget.",
|
|
1480
1489
|
"rocky free revoke": "Revoke a user's free Rocky grant.",
|
|
1490
|
+
"flags list": "List every feature flag with who it targets.",
|
|
1491
|
+
"flags get": "Read one feature flag: status, targets, payload.",
|
|
1492
|
+
"flags create": "Create a feature flag (off, targeting no one).",
|
|
1493
|
+
"flags set": "Turn a flag on/off, on for everyone, or change its description or payload.",
|
|
1494
|
+
"flags add": "Turn a flag on for more users, emails or roles.",
|
|
1495
|
+
"flags remove": "Stop targeting users, emails or roles with a flag.",
|
|
1496
|
+
"flags delete": "Delete a feature flag.",
|
|
1481
1497
|
"tutor-templates list": "List tutor templates.",
|
|
1482
1498
|
"tutor-templates get": "Read one tutor template.",
|
|
1483
1499
|
"tutor-templates assign": "Assign a tutor template to a kid.",
|
|
@@ -1564,6 +1580,7 @@ export const NOUN_SUMMARIES = {
|
|
|
1564
1580
|
todos: "Kids' todos: create, edit, complete, analysis, applets.",
|
|
1565
1581
|
memories: "Kid memory files and the context Rocky sees.",
|
|
1566
1582
|
rocky: "A kid's Rocky personality settings; free Rocky grants and budgets.",
|
|
1583
|
+
flags: "Feature flags: on/off, everyone, and who they target by user, email or role.",
|
|
1567
1584
|
"tutor-templates": "Tutor templates and their assignment to kids.",
|
|
1568
1585
|
"library-books": "Book library: search the web, add and delete books, read status, reader stages, tags.",
|
|
1569
1586
|
"math-curricula": "Math curricula and the goals a math review assigns (ADMIN, GUIDE).",
|