recess-cli 3.10.0 → 3.12.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.
@@ -44,21 +44,38 @@ const dollars = (cents) => `$${(cents / 100).toLocaleString("en-US", {
44
44
  })}`;
45
45
  /** The tuition plan as terminal text, in the PDF's order: one block per term. */
46
46
  function renderPlan(plan, webUrl, pdfPath) {
47
- const out = [
48
- `RECESS ACADEMY ${plan.enrollment.indicative ? "ESTIMATED " : ""}TUITION PLAN (${plan.calendarLabel})`,
49
- ];
47
+ const out = [`RECESS ACADEMY TUITION PLAN (${plan.calendarLabel})`];
50
48
  if (plan.enrollment.disclaimer)
51
49
  out.push(`!! ${plan.enrollment.disclaimer}`);
52
50
  out.push("", `Tuition options for ${plan.studentName}`, `Prepared for ${plan.parentName} · ${plan.state.name} · ${plan.enrollment.partnerSchool
53
51
  ? `Through ${plan.enrollment.partnerSchool.name}`
54
- : "Direct enrollment"}`, "", plan.introduction);
52
+ : "Direct enrollment"}`);
53
+ const esa = plan.esaPreview;
54
+ if (esa) {
55
+ out.push("", `${esa.title.toUpperCase()} (PDF pages 1-2, before the prices)`, ` ${esa.introduction}`, ...esa.steps.map((s, i) => ` ${i + 1}. ${s.title}. ${s.body}`), "", ` ${esa.sectionsTitle}:`, ...esa.sections.map((s) => ` · ${s.title}. ${s.body}`), "", ` ${esa.chartTitle} (${esa.chartIntro})`, "", renderColumns([
56
+ [` ${esa.awardLabel}`, "Before aid", "Recess aid", "You pay"],
57
+ ...esa.scenarios.map((s) => [
58
+ ` ${s.label}`,
59
+ dollars(s.withoutAidCents),
60
+ dollars(s.recessAidCents),
61
+ dollars(s.familyCents),
62
+ ]),
63
+ ]), ...esa.scenarios.map((s) => ` · ${s.label}${s.detail ? ` (${s.detail.toLowerCase()})` : ""}: ${s.caption}`), ` ${esa.footnote}`);
64
+ }
65
+ out.push("", plan.introduction);
55
66
  for (const o of plan.options) {
56
67
  out.push("", `${o.label.toUpperCase()} (${o.startDate} → ${o.endDate}, ${o.instructionalDays} school days)`, ` ${o.description}`, renderColumns(o.paymentPlans.map((p) => [
57
68
  ` ${p.label}`,
58
- dollars(p.totalCents),
69
+ `${esa && p.kind !== "PAY_IN_FULL" ? "you pay at most " : ""}${dollars(p.totalCents)}`,
59
70
  p.summary,
60
71
  p.scheduleLine,
61
- ])));
72
+ ])),
73
+ // Award unknown: each payment is billed as is, or a ceiling for now.
74
+ ...(esa
75
+ ? o.paymentPlans
76
+ .filter((p) => p.kind !== "PAY_IN_FULL")
77
+ .flatMap((p) => p.installments.map((inst) => ` ${p.kind === "MONTHLY" ? `invoiced ${inst.invoiceDate}, due ${inst.dueDate}` : `${inst.serviceStart} → ${inst.serviceEnd}`} tuition ${dollars(inst.fullTuitionCents ?? inst.amountCents)} you pay ${inst.award === "NONE" ? dollars(inst.amountCents) : `up to ${dollars(inst.amountCents)}`}${inst.illustrativeNote ? ` (${inst.illustrativeNote})` : ""} ${inst.note ?? ""}`))
78
+ : []));
62
79
  }
63
80
  if (plan.staffNotes.length) {
64
81
  out.push("", "Notes:", ...plan.staffNotes.map((n) => ` ${n}`));
@@ -68,7 +85,7 @@ function renderPlan(plan, webUrl, pdfPath) {
68
85
  .join(" · ")}`, "", ...plan.footnotes.map((n) => ` · ${n}`), ...(plan.agreement
69
86
  ? [
70
87
  "",
71
- "ENROLLMENT AGREEMENT (page 2 of the PDF; parent checks one and signs)",
88
+ "ENROLLMENT AGREEMENT (last page of the PDF; parent checks one and signs)",
72
89
  ...plan.agreement.choices.map((c) => ` [ ] ${c.label}`),
73
90
  ...plan.agreement.clauses.map((c, i) => ` ${i + 1}. ${c}`),
74
91
  ]
@@ -77,32 +94,16 @@ function renderPlan(plan, webUrl, pdfPath) {
77
94
  out.push(`PDF: ${pdfPath}`);
78
95
  return out.join("\n");
79
96
  }
80
- export async function runTuitionPlansCommand({ parsed, api, }) {
81
- const verb = parsed.positionals[1];
82
- if (verb === "states") {
83
- return unwrap(await api.client.GET("/admin/tuition-plans/states/"));
84
- }
85
- if (verb !== "generate") {
86
- throw new CliError("invalid_arguments", "Usage: recess tuition-plans generate|states. See `recess help`.");
87
- }
97
+ /**
98
+ * The tuition-plan flags that describe the plan itself (everything but who
99
+ * it is for): shared by `tuition-plans generate` and `admissions create`,
100
+ * which stores them as the packet's plan spec.
101
+ */
102
+ export function parseTuitionPlanSpecFlags(parsed) {
88
103
  const annual = Number(requiredFlag(parsed, "annual").replace(/[$,]/g, ""));
89
104
  if (!Number.isFinite(annual) || annual <= 0) {
90
105
  throw new CliError("invalid_arguments", "--annual must be a positive dollar amount (net of Recess financial aid).");
91
106
  }
92
- // The server owns the supported-state list; resolve against it so a bad
93
- // code fails with the valid choices.
94
- const { states } = unwrap(await api.client.GET("/admin/tuition-plans/states/"));
95
- const state = assertChoice(requiredFlag(parsed, "state", /^[A-Za-z]{2}$/).toUpperCase(), states.map((s) => s.code), "--state");
96
- const enrollment = assertChoice(requiredFlag(parsed, "enrollment"), ["direct", "partner-school"], "--enrollment") === "partner-school"
97
- ? "PARTNER_SCHOOL"
98
- : "DIRECT";
99
- const partnerSchool = flagString(parsed, "partner-school")?.trim();
100
- if (enrollment === "PARTNER_SCHOOL" && !partnerSchool) {
101
- throw new CliError("invalid_arguments", "--enrollment partner-school needs --partner-school <slug|id> (see `recess users enrollment list-partner-schools`).");
102
- }
103
- if (enrollment === "DIRECT" && partnerSchool) {
104
- throw new CliError("invalid_arguments", "--partner-school applies only with --enrollment partner-school.");
105
- }
106
107
  // Add-on overrides; omitted = the server's school-pricing defaults.
107
108
  const addOnFlag = (name, integer) => {
108
109
  const raw = flagString(parsed, name)?.trim().replace(/[$,]/g, "");
@@ -124,11 +125,6 @@ export async function runTuitionPlansCommand({ parsed, api, }) {
124
125
  ...(oneOnOnePrice !== undefined ? { oneOnOnePrice } : {}),
125
126
  ...(oneOnOneSessions !== undefined ? { oneOnOneSessions } : {}),
126
127
  };
127
- // Optional: without it the sheet leaves out the student's age.
128
- const dob = flagString(parsed, "dob")?.trim();
129
- if (dob && !ISO_DATE.test(dob)) {
130
- throw new CliError("invalid_arguments", "--dob must look like YYYY-MM-DD.");
131
- }
132
128
  // Omitted = the full matrix (full year + school year [+ custom with --end]) ×
133
129
  // (upfront + installments). A full year past July 1 drops out of the
134
130
  // default; asking for it explicitly is refused by the server.
@@ -158,44 +154,117 @@ export async function runTuitionPlansCommand({ parsed, api, }) {
158
154
  }
159
155
  return `${key}=${date}`;
160
156
  });
157
+ const amounts = flagList(parsed, "amount").map((raw) => {
158
+ const [key, dollars] = raw.split("=").map((v) => v.trim());
159
+ if (!key ||
160
+ !dollars ||
161
+ !/^[1-9]\d*$/.test(key) ||
162
+ !/^\$?\d[\d,]*(\.\d{1,2})?$/.test(dollars)) {
163
+ throw new CliError("invalid_arguments", `--amount takes N=DOLLARS (installment N's amount), got "${raw}".`);
164
+ }
165
+ return `${key}=${dollars.replace(/[$,]/g, "")}`;
166
+ });
161
167
  const even = hasFlag(parsed, "even-installments");
168
+ // Award not yet known: --annual is the income-based price with no award.
169
+ const esaUnknown = hasFlag(parsed, "esa-award-unknown");
170
+ const esaScenarios = flagString(parsed, "esa-scenarios")
171
+ ?.trim()
172
+ .replace(/[$\s]/g, "");
173
+ if (esaScenarios !== undefined) {
174
+ if (!esaUnknown) {
175
+ throw new CliError("invalid_arguments", "--esa-scenarios applies only with --esa-award-unknown.");
176
+ }
177
+ if (!/^\d+(\.\d{1,2})?(,\d+(\.\d{1,2})?){0,5}$/.test(esaScenarios)) {
178
+ throw new CliError("invalid_arguments", "--esa-scenarios takes up to six dollar amounts, comma-separated (e.g. 7300,14000,34000).");
179
+ }
180
+ }
162
181
  const subsetQuery = {
182
+ // Florida is refused as a direct enrollment without this.
183
+ ...(hasFlag(parsed, "force-direct")
184
+ ? { forceDirect: "true" }
185
+ : {}),
186
+ ...(esaUnknown ? { esaAwardUnknown: "true" } : {}),
187
+ ...(esaScenarios ? { esaScenarios } : {}),
163
188
  ...(even ? { evenInstallments: "true" } : {}),
164
189
  ...(billDates.length ? { billDates: billDates.join(",") } : {}),
190
+ ...(amounts.length ? { amounts: amounts.join(",") } : {}),
165
191
  ...(endDate ? { endDate } : {}),
166
192
  ...(terms ? { terms: terms.join(",") } : {}),
167
193
  ...(payments ? { payments: payments.join(",") } : {}),
168
194
  };
169
- const query = {
170
- parentName: requiredFlag(parsed, "parent"),
171
- studentName: requiredFlag(parsed, "student"),
172
- ...(dob ? { studentDob: dob } : {}),
173
- state,
195
+ return {
174
196
  startDate: requiredFlag(parsed, "start", ISO_DATE),
175
197
  annualTuition: annual,
176
198
  stateFunding: hasFlag(parsed, "state-funding") ? "true" : "false",
177
- enrollment,
178
- ...(partnerSchool ? { partnerSchool } : {}),
179
199
  ...addOnQuery,
180
200
  ...subsetQuery,
181
201
  ...(notes.length ? { notes } : {}),
182
202
  };
183
- const plan = unwrap(await api.client.GET("/admin/tuition-plans/", { params: { query } }));
184
- const search = new URLSearchParams({
185
- parentName: query.parentName,
186
- studentName: query.studentName,
203
+ }
204
+ /** The query-string form of a plan spec, for the web deep link. */
205
+ export function planSpecSearchParams(spec) {
206
+ const search = new URLSearchParams();
207
+ for (const [key, value] of Object.entries(spec)) {
208
+ if (value === undefined || key === "notes")
209
+ continue;
210
+ if (key === "stateFunding" && value !== "true")
211
+ continue;
212
+ search.set(key, String(value));
213
+ }
214
+ for (const note of spec.notes ?? [])
215
+ search.append("notes", note);
216
+ return search;
217
+ }
218
+ export async function runTuitionPlansCommand({ parsed, api, }) {
219
+ const verb = parsed.positionals[1];
220
+ if (verb === "states") {
221
+ return unwrap(await api.client.GET("/admin/tuition-plans/states/"));
222
+ }
223
+ if (verb !== "generate") {
224
+ throw new CliError("invalid_arguments", "Usage: recess tuition-plans generate|states. See `recess help`.");
225
+ }
226
+ const spec = parseTuitionPlanSpecFlags(parsed);
227
+ // The server owns the supported-state list; resolve against it so a bad
228
+ // code fails with the valid choices.
229
+ const { states } = unwrap(await api.client.GET("/admin/tuition-plans/states/"));
230
+ const state = assertChoice(requiredFlag(parsed, "state", /^[A-Za-z]{2}$/).toUpperCase(), states.map((s) => s.code), "--state");
231
+ const enrollmentChoice = assertChoice(requiredFlag(parsed, "enrollment"), ["direct", "partner-school", "program"], "--enrollment");
232
+ const enrollment = enrollmentChoice === "partner-school"
233
+ ? "PARTNER_SCHOOL"
234
+ : enrollmentChoice === "program"
235
+ ? "PROGRAM"
236
+ : "DIRECT";
237
+ const partnerSchool = flagString(parsed, "partner-school")?.trim();
238
+ if (enrollment === "PARTNER_SCHOOL" && !partnerSchool) {
239
+ throw new CliError("invalid_arguments", "--enrollment partner-school needs --partner-school <slug|id> (see `recess users enrollment list-partner-schools`).");
240
+ }
241
+ if (enrollment !== "PARTNER_SCHOOL" && partnerSchool) {
242
+ throw new CliError("invalid_arguments", "--partner-school applies only with --enrollment partner-school.");
243
+ }
244
+ // Optional: without it the sheet leaves out the student's age.
245
+ const dob = flagString(parsed, "dob")?.trim();
246
+ if (dob && !ISO_DATE.test(dob)) {
247
+ throw new CliError("invalid_arguments", "--dob must look like YYYY-MM-DD.");
248
+ }
249
+ const query = {
250
+ parentName: requiredFlag(parsed, "parent"),
251
+ studentName: requiredFlag(parsed, "student"),
187
252
  ...(dob ? { studentDob: dob } : {}),
188
- state: query.state,
189
- startDate: query.startDate,
190
- annualTuition: String(annual),
191
- ...(query.stateFunding === "true" ? { stateFunding: "true" } : {}),
253
+ state,
192
254
  enrollment,
193
255
  ...(partnerSchool ? { partnerSchool } : {}),
194
- ...Object.fromEntries(Object.entries(addOnQuery).map(([k, v]) => [k, String(v)])),
195
- ...subsetQuery,
196
- });
197
- for (const note of notes)
198
- search.append("notes", note);
256
+ ...spec,
257
+ };
258
+ const plan = unwrap(await api.client.GET("/admin/tuition-plans/", { params: { query } }));
259
+ const search = planSpecSearchParams(spec);
260
+ search.set("parentName", query.parentName);
261
+ search.set("studentName", query.studentName);
262
+ if (dob)
263
+ search.set("studentDob", dob);
264
+ search.set("state", query.state);
265
+ search.set("enrollment", enrollment);
266
+ if (partnerSchool)
267
+ search.set("partnerSchool", partnerSchool);
199
268
  const webUrl = new URL(`/admin/tuition-plans?${search}`, api.config.webOrigin).toString();
200
269
  let pdfPath;
201
270
  const pdfFlag = flagString(parsed, "pdf");