recess-cli 3.9.0 → 3.10.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 +4 -0
- package/dist/cli.js +28 -1
- package/dist/command-schema.js +1 -0
- package/dist/commands/feed.js +82 -0
- package/dist/help.js +4 -2
- package/package.json +1 -1
package/dist/api.js
CHANGED
|
@@ -7,6 +7,10 @@ const idempotencyContext = new AsyncLocalStorage();
|
|
|
7
7
|
export function withIdempotencyContext(context, execute) {
|
|
8
8
|
return idempotencyContext.run(context, execute);
|
|
9
9
|
}
|
|
10
|
+
/** The approved operation key while a confirmed write executes. */
|
|
11
|
+
export function currentOperationKey() {
|
|
12
|
+
return idempotencyContext.getStore()?.operationKey;
|
|
13
|
+
}
|
|
10
14
|
function applyIdempotencyHeaders(headers) {
|
|
11
15
|
const context = idempotencyContext.getStore();
|
|
12
16
|
if (!context)
|
package/dist/cli.js
CHANGED
|
@@ -14,6 +14,7 @@ import { runChannelsCommand } from "./commands/channels.js";
|
|
|
14
14
|
import { runChatLogsCommand } from "./commands/chat-logs.js";
|
|
15
15
|
import { runDbCommand } from "./commands/db.js";
|
|
16
16
|
import { runRoomsCommand } from "./commands/rooms.js";
|
|
17
|
+
import { runFeedCommand } from "./commands/feed.js";
|
|
17
18
|
import { runFamiliesCommand } from "./commands/families.js";
|
|
18
19
|
import { runStudentsTextsCommand, runUsersPhoneCommand, } from "./commands/phone-and-texts.js";
|
|
19
20
|
import { runTuitionPlansCommand } from "./commands/tuition-plans.js";
|
|
@@ -3546,6 +3547,23 @@ export async function executeRecessCommand(argv, options = {}) {
|
|
|
3546
3547
|
params: { path: { eventId } },
|
|
3547
3548
|
}));
|
|
3548
3549
|
}
|
|
3550
|
+
if (noun === "events" && verb === "list") {
|
|
3551
|
+
const date = flagString(parsed, "date");
|
|
3552
|
+
if (!date) {
|
|
3553
|
+
throw new CliError("invalid_arguments", "events list requires --date YYYY-MM-DD.");
|
|
3554
|
+
}
|
|
3555
|
+
const timezone = flagString(parsed, "timezone");
|
|
3556
|
+
const search = flagString(parsed, "search");
|
|
3557
|
+
return unwrap(await api.client.GET("/admin/events/by-date", {
|
|
3558
|
+
params: {
|
|
3559
|
+
query: {
|
|
3560
|
+
date,
|
|
3561
|
+
...(timezone && { timezone }),
|
|
3562
|
+
...(search && { search }),
|
|
3563
|
+
},
|
|
3564
|
+
},
|
|
3565
|
+
}));
|
|
3566
|
+
}
|
|
3549
3567
|
if (noun === "events" && verb === "take-attendance") {
|
|
3550
3568
|
const eventId = positional(parsed, 2, "event ID");
|
|
3551
3569
|
const attended = flagIdList(parsed, "attended");
|
|
@@ -4295,6 +4313,7 @@ export async function executeRecessCommand(argv, options = {}) {
|
|
|
4295
4313
|
throw new CliError("invalid_arguments", "--coin-amount must be a positive integer.");
|
|
4296
4314
|
}
|
|
4297
4315
|
const visibility = flagString(parsed, "visibility");
|
|
4316
|
+
const targetPlatform = flagString(parsed, "target-platform");
|
|
4298
4317
|
const isStarterRaw = flagString(parsed, "is-starter");
|
|
4299
4318
|
const setupAudienceRaw = flagString(parsed, "setup-audience");
|
|
4300
4319
|
const isStarter = isStarterRaw === undefined
|
|
@@ -4341,6 +4360,11 @@ export async function executeRecessCommand(argv, options = {}) {
|
|
|
4341
4360
|
visibility: assertChoice(visibility, ["PUBLIC", "PRIVATE", "STAFF_ONLY"], "--visibility"),
|
|
4342
4361
|
}
|
|
4343
4362
|
: {}),
|
|
4363
|
+
...(targetPlatform
|
|
4364
|
+
? {
|
|
4365
|
+
targetPlatform: assertChoice(targetPlatform.toUpperCase(), ["ANY", "MOBILE", "DESKTOP"], "--target-platform"),
|
|
4366
|
+
}
|
|
4367
|
+
: {}),
|
|
4344
4368
|
...(agentInstructionsFile
|
|
4345
4369
|
? {
|
|
4346
4370
|
agentInstructions: await fs.readFile(path.resolve(agentInstructionsFile), "utf8"),
|
|
@@ -4357,7 +4381,7 @@ export async function executeRecessCommand(argv, options = {}) {
|
|
|
4357
4381
|
// shape that caused the template incident; editing an existing spec goes
|
|
4358
4382
|
// through the guarded /ai patch path with its destructive-change token.
|
|
4359
4383
|
if (Object.keys(body).length === 1) {
|
|
4360
|
-
throw new CliError("invalid_arguments", "Pass at least one field to change (--title, --description, --emoji, --image-url, --coin-amount, --category, --tags, --sort-order, --is-starter, --setup-audience, --kind, --visibility, --agent-instructions-file, --output-template-file).");
|
|
4384
|
+
throw new CliError("invalid_arguments", "Pass at least one field to change (--title, --description, --emoji, --image-url, --coin-amount, --category, --tags, --sort-order, --is-starter, --setup-audience, --kind, --visibility, --target-platform, --agent-instructions-file, --output-template-file).");
|
|
4361
4385
|
}
|
|
4362
4386
|
return writeCommand(parsed, {
|
|
4363
4387
|
action: "update goal template metadata (never its setupWorkflowSpec)",
|
|
@@ -5129,6 +5153,9 @@ export async function executeRecessCommand(argv, options = {}) {
|
|
|
5129
5153
|
if (noun === "rooms") {
|
|
5130
5154
|
return runRoomsCommand({ parsed, api, writeCommand });
|
|
5131
5155
|
}
|
|
5156
|
+
if (noun === "feed") {
|
|
5157
|
+
return runFeedCommand({ parsed, api, writeCommand });
|
|
5158
|
+
}
|
|
5132
5159
|
if (noun === "students" && verb === "texts") {
|
|
5133
5160
|
return runStudentsTextsCommand({ parsed, api, writeCommand });
|
|
5134
5161
|
}
|
package/dist/command-schema.js
CHANGED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { currentOperationKey, unwrap } from "../api.js";
|
|
2
|
+
import { flagString, hasFlag } from "../args.js";
|
|
3
|
+
import { CliError } from "../errors.js";
|
|
4
|
+
import { flagIdList } from "./shared.js";
|
|
5
|
+
/**
|
|
6
|
+
* The post id is derived from the approved operation key: the server's replay
|
|
7
|
+
* fence keys on the request body, so a fresh random id on a retried
|
|
8
|
+
* confirmation would slip past it and publish the post twice.
|
|
9
|
+
*/
|
|
10
|
+
function activityIdForOperation() {
|
|
11
|
+
const hex = /^op_([a-f0-9]{32})_/.exec(currentOperationKey() ?? "")?.[1];
|
|
12
|
+
if (!hex) {
|
|
13
|
+
throw new CliError("confirmation_required", "A feed post can only be published through a confirmed operation.");
|
|
14
|
+
}
|
|
15
|
+
return [
|
|
16
|
+
hex.slice(0, 8),
|
|
17
|
+
hex.slice(8, 12),
|
|
18
|
+
hex.slice(12, 16),
|
|
19
|
+
hex.slice(16, 20),
|
|
20
|
+
hex.slice(20),
|
|
21
|
+
].join("-");
|
|
22
|
+
}
|
|
23
|
+
const describe = (person) => ({
|
|
24
|
+
id: person.id,
|
|
25
|
+
name: [person.firstName, person.lastName].filter(Boolean).join(" "),
|
|
26
|
+
role: person.role,
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* Read-only preflight so the approval names every recipient and the family
|
|
30
|
+
* adults the server adds to a private post. Sorted so a confirm-time rerun
|
|
31
|
+
* reproduces the approved preview byte for byte.
|
|
32
|
+
*/
|
|
33
|
+
async function resolveAudience(api, userIds) {
|
|
34
|
+
const profiles = await Promise.all(userIds.map(async (userId) => unwrap(await api.client.GET("/admin/users/{userId}", {
|
|
35
|
+
params: { path: { userId } },
|
|
36
|
+
}))));
|
|
37
|
+
const disabled = profiles.filter(({ user }) => user.role === "DISABLED");
|
|
38
|
+
if (disabled.length) {
|
|
39
|
+
throw new CliError("invalid_arguments", `Disabled accounts cannot receive posts: ${disabled
|
|
40
|
+
.map(({ user }) => user.id)
|
|
41
|
+
.join(", ")}.`);
|
|
42
|
+
}
|
|
43
|
+
const adults = new Map();
|
|
44
|
+
for (const { user } of profiles)
|
|
45
|
+
for (const member of user.family?.users ?? [])
|
|
46
|
+
if (member.role !== "KID" && !userIds.includes(member.id))
|
|
47
|
+
adults.set(member.id, member);
|
|
48
|
+
const byId = (a, b) => a.id.localeCompare(b.id);
|
|
49
|
+
return {
|
|
50
|
+
recipients: profiles.map(({ user }) => describe(user)).sort(byId),
|
|
51
|
+
familyAdultsAlsoReceiving: [...adults.values()].map(describe).sort(byId),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export async function runFeedCommand({ parsed, api, writeCommand, }) {
|
|
55
|
+
if (parsed.positionals[1] !== "post") {
|
|
56
|
+
throw new CliError("invalid_arguments", "Use `feed post`.");
|
|
57
|
+
}
|
|
58
|
+
const userIds = Array.from(new Set(flagIdList(parsed, "users")));
|
|
59
|
+
if (userIds.length === 0) {
|
|
60
|
+
throw new CliError("invalid_arguments", "--users is required.");
|
|
61
|
+
}
|
|
62
|
+
const text = flagString(parsed, "text", { required: true }).trim();
|
|
63
|
+
if (!text) {
|
|
64
|
+
throw new CliError("invalid_arguments", "--text must not be empty.");
|
|
65
|
+
}
|
|
66
|
+
const sendEmailBlast = hasFlag(parsed, "send-email");
|
|
67
|
+
return writeCommand(parsed, {
|
|
68
|
+
action: `publish a private feed post to ${userIds.length} user(s) and their guardians${sendEmailBlast ? ", AND EMAIL it to all of them" : ""}`,
|
|
69
|
+
target: { userIds },
|
|
70
|
+
request: { type: "PRIVATE_UPDATE", text, sendEmailBlast },
|
|
71
|
+
details: await resolveAudience(api, userIds),
|
|
72
|
+
}, async () => unwrap(await api.client.POST("/activity/", {
|
|
73
|
+
body: {
|
|
74
|
+
id: activityIdForOperation(),
|
|
75
|
+
type: "PRIVATE_UPDATE",
|
|
76
|
+
text,
|
|
77
|
+
targetUserIds: userIds,
|
|
78
|
+
sendEmailBlast,
|
|
79
|
+
},
|
|
80
|
+
})));
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=feed.js.map
|
package/dist/help.js
CHANGED
|
@@ -203,7 +203,9 @@ Usage:
|
|
|
203
203
|
recess [--json] cohorts resume-billing <cohort-id> [--confirm]
|
|
204
204
|
recess [--json] cohorts email <cohort-id> --target ALL_PARENTS|ALL_PARENTS_GUIDES
|
|
205
205
|
--content TEXT [--confirm]
|
|
206
|
+
recess [--json] feed post --users <id,id,...> --text TEXT [--send-email] [--confirm]
|
|
206
207
|
recess [--json] events get <event-id>
|
|
208
|
+
recess [--json] events list --date YYYY-MM-DD [--timezone <iana>] [--search TEXT]
|
|
207
209
|
recess [--json] events take-attendance <event-id> --attended <id,id,...>
|
|
208
210
|
[--absent <id,id,...>] [--excused <id,id,...>] [--confirm]
|
|
209
211
|
recess [--json] events cancel <event-id> --reason TEXT [--confirm]
|
|
@@ -427,8 +429,8 @@ Usage:
|
|
|
427
429
|
[--title TEXT] [--description TEXT] [--emoji X] [--category TEXT] [--tags A,B]
|
|
428
430
|
[--image-url URL] [--coin-amount N] [--sort-order N] [--is-starter true|false]
|
|
429
431
|
[--setup-audience KID_FRIENDLY|PARENT_SETUP] [--kind SIMPLE|BLUEPRINT]
|
|
430
|
-
[--visibility PUBLIC|PRIVATE|STAFF_ONLY] [--
|
|
431
|
-
[--output-template-file <path>] [--confirm]
|
|
432
|
+
[--visibility PUBLIC|PRIVATE|STAFF_ONLY] [--target-platform ANY|MOBILE|DESKTOP]
|
|
433
|
+
[--agent-instructions-file <path>] [--output-template-file <path>] [--confirm]
|
|
432
434
|
recess [--json] goal-templates delete <template-id> --expected-version N [--confirm]
|
|
433
435
|
recess [--json] goal-templates generate-image <template-id|slug>
|
|
434
436
|
[--prompt TEXT] [--confirm]
|