@composable-os/pack-courses 0.0.0-stage → 0.1.0-beta.8
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/LICENSE +109 -0
- package/dist/automations.d.ts +12 -0
- package/dist/automations.js +84 -0
- package/dist/blocks/courses-builder/course-builder.d.ts +5 -0
- package/dist/blocks/courses-builder/course-builder.js +69 -0
- package/dist/blocks/courses-catalogue/catalogue.d.ts +6 -0
- package/dist/blocks/courses-catalogue/catalogue.js +21 -0
- package/dist/blocks/courses-course/course-page.d.ts +10 -0
- package/dist/blocks/courses-course/course-page.js +51 -0
- package/dist/blocks/courses-my-courses/my-courses.d.ts +5 -0
- package/dist/blocks/courses-my-courses/my-courses.js +19 -0
- package/dist/blocks/courses-native-catalogue/catalogue-screen.d.ts +6 -0
- package/dist/blocks/courses-native-catalogue/catalogue-screen.js +15 -0
- package/dist/blocks/courses-native-course/course-screen.d.ts +7 -0
- package/dist/blocks/courses-native-course/course-screen.js +18 -0
- package/dist/blocks/courses-native-my-courses/my-courses-screen.d.ts +5 -0
- package/dist/blocks/courses-native-my-courses/my-courses-screen.js +9 -0
- package/dist/blocks/courses-native-player/lesson-screen.d.ts +19 -0
- package/dist/blocks/courses-native-player/lesson-screen.js +11 -0
- package/dist/blocks/courses-player/player.d.ts +12 -0
- package/dist/blocks/courses-player/player.js +51 -0
- package/dist/client/index.d.ts +933 -0
- package/dist/client/index.js +277 -0
- package/dist/dashboards.d.ts +5 -0
- package/dist/dashboards.js +119 -0
- package/dist/index.d.ts +746 -0
- package/dist/index.js +394 -0
- package/dist/outline.d.ts +85 -0
- package/dist/outline.js +188 -0
- package/dist/tools.d.ts +243 -0
- package/dist/tools.js +778 -0
- package/package.json +36 -4
- package/README.md +0 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
// Courses (stage 42): video courses a studio sells, one at a time or in fixed bundles, which a
|
|
2
|
+
// buyer watches lesson by lesson on the web and in the app. Requires Programs (a lesson can be a
|
|
3
|
+
// training session). A product that does not list it has none of this.
|
|
4
|
+
//
|
|
5
|
+
// Everything that is a rule is the host's, declared here as behaviours (ADR 0404):
|
|
6
|
+
// - a course and a bundle are `publishable` with a public half (ADRs 0446, 0442): staff and the
|
|
7
|
+
// assistant edit the working copy; a person publishes; the public reads the published version;
|
|
8
|
+
// - both are `sellable` (ADR 0435): the host prices an order from the record, and a paid line
|
|
9
|
+
// grants one enrolment in the paid batch; a full refund voids it in the refund's batch;
|
|
10
|
+
// - who holds access to a course is `access` (ADR 0477): an enrolment of theirs that is active
|
|
11
|
+
// and inside its `until`, pointing at the course or at a bundle whose published version lists
|
|
12
|
+
// it. The outline's lesson material is for holders (the `holders` flag in outline.ts), so the
|
|
13
|
+
// host removes it for everyone else, and `media.play` plays a lesson's video only to a holder;
|
|
14
|
+
// - an enrolment and a lesson's progress are their student's (`customer`); progress is written
|
|
15
|
+
// only while the student holds access to its course (`requireAccess`, ADR 0478).
|
|
16
|
+
// The tools in tools.ts compose the host's operations and hold no rule of their own.
|
|
17
|
+
import { defineExtension } from "@composable-os/sdk";
|
|
18
|
+
import { coursesAutomations } from "./automations.js";
|
|
19
|
+
import { coursesDashboards } from "./dashboards.js";
|
|
20
|
+
import { OUTLINE_MAX_BYTES, OUTLINE_SCHEMA } from "./outline.js";
|
|
21
|
+
import { buy, catalogue, course, draft, endEnrolment, enrol, lesson, myCourses, progress, startSession, stats, } from "./tools.js";
|
|
22
|
+
const ACTIVE = { states: ["active"], until: "until" };
|
|
23
|
+
export default defineExtension({
|
|
24
|
+
id: "courses",
|
|
25
|
+
version: "0.1.0",
|
|
26
|
+
contractVersion: 1,
|
|
27
|
+
label: "Courses",
|
|
28
|
+
description: "Video courses sold one at a time or in bundles, watched lesson by lesson, with progress. " +
|
|
29
|
+
"A lesson can be a training session from Programs.",
|
|
30
|
+
// A session lesson is a Programs program: the host installs Courses only beside Programs.
|
|
31
|
+
requires: ["programs"],
|
|
32
|
+
permissions: {
|
|
33
|
+
// person.get: a student's name in the stats. programs.*: a session lesson's program, its
|
|
34
|
+
// assignment and dated sessions, made by x.programs.assign for the student (step 6).
|
|
35
|
+
read: ["person", "programs.program", "programs.assignment", "programs.session"],
|
|
36
|
+
write: ["programs.assignment", "programs.session"],
|
|
37
|
+
operations: [
|
|
38
|
+
"public.list",
|
|
39
|
+
"public.get",
|
|
40
|
+
"my.list",
|
|
41
|
+
"my.get",
|
|
42
|
+
"my.create",
|
|
43
|
+
"my.update",
|
|
44
|
+
"access.check",
|
|
45
|
+
"order.start",
|
|
46
|
+
"record.create",
|
|
47
|
+
"record.update",
|
|
48
|
+
"record.get",
|
|
49
|
+
"record.list",
|
|
50
|
+
"media.list",
|
|
51
|
+
"order.settings.get",
|
|
52
|
+
"record.version",
|
|
53
|
+
"query.sql",
|
|
54
|
+
// A session lesson's program, assigned to its student on their first open (step 6).
|
|
55
|
+
"x.programs.assign",
|
|
56
|
+
],
|
|
57
|
+
modules: ["ops", "ai"],
|
|
58
|
+
},
|
|
59
|
+
objects: {
|
|
60
|
+
theme: {
|
|
61
|
+
label: "Theme",
|
|
62
|
+
plural: "Themes",
|
|
63
|
+
icon: "shapes",
|
|
64
|
+
titleField: "name",
|
|
65
|
+
description: "What courses are grouped by in the catalogue: handstands, mobility.",
|
|
66
|
+
navigation: "settings",
|
|
67
|
+
fields: {
|
|
68
|
+
name: { type: "text", label: "Name", required: true },
|
|
69
|
+
slug: { type: "slug", label: "Slug" },
|
|
70
|
+
order: { type: "number", label: "Order", min: 0, max: 1000, step: 1 },
|
|
71
|
+
summary: { type: "text", label: "Short description" },
|
|
72
|
+
picture: { type: "image", label: "Picture" },
|
|
73
|
+
},
|
|
74
|
+
// Every live theme is the catalogue's.
|
|
75
|
+
public: { read: ["name", "slug", "order", "summary", "picture"] },
|
|
76
|
+
},
|
|
77
|
+
course: {
|
|
78
|
+
label: "Course",
|
|
79
|
+
plural: "Courses",
|
|
80
|
+
icon: "graduation-cap",
|
|
81
|
+
titleField: "title",
|
|
82
|
+
description: "A course of lessons a studio sells: its outline, price, trailer and cover.",
|
|
83
|
+
navigation: "main",
|
|
84
|
+
navigationOrder: 15,
|
|
85
|
+
fields: {
|
|
86
|
+
title: { type: "text", label: "Title", required: true },
|
|
87
|
+
slug: { type: "slug", label: "Slug" },
|
|
88
|
+
theme: { type: "relation", label: "Theme", to: "courses.theme" },
|
|
89
|
+
level: {
|
|
90
|
+
type: "number",
|
|
91
|
+
label: "Level",
|
|
92
|
+
min: 1,
|
|
93
|
+
max: 3,
|
|
94
|
+
step: 1,
|
|
95
|
+
description: "1 to 3: beginner, intermediate, advanced.",
|
|
96
|
+
},
|
|
97
|
+
summary: { type: "text", label: "Summary" },
|
|
98
|
+
description: { type: "richText", label: "Description" },
|
|
99
|
+
cover: { type: "image", label: "Cover" },
|
|
100
|
+
trailer: { type: "video", label: "Trailer" },
|
|
101
|
+
price: { type: "currency", label: "Price", required: true },
|
|
102
|
+
onSaleFrom: { type: "datetime", label: "On sale from" },
|
|
103
|
+
outline: {
|
|
104
|
+
type: "document",
|
|
105
|
+
label: "Outline",
|
|
106
|
+
schema: OUTLINE_SCHEMA,
|
|
107
|
+
maxBytes: OUTLINE_MAX_BYTES,
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
publishable: {
|
|
111
|
+
content: [
|
|
112
|
+
"title",
|
|
113
|
+
"theme",
|
|
114
|
+
"level",
|
|
115
|
+
"summary",
|
|
116
|
+
"description",
|
|
117
|
+
"cover",
|
|
118
|
+
"trailer",
|
|
119
|
+
"outline",
|
|
120
|
+
],
|
|
121
|
+
slug: "slug",
|
|
122
|
+
},
|
|
123
|
+
public: {
|
|
124
|
+
read: [
|
|
125
|
+
"title",
|
|
126
|
+
"slug",
|
|
127
|
+
"theme",
|
|
128
|
+
"level",
|
|
129
|
+
"summary",
|
|
130
|
+
"description",
|
|
131
|
+
"cover",
|
|
132
|
+
"trailer",
|
|
133
|
+
"price",
|
|
134
|
+
"onSaleFrom",
|
|
135
|
+
"outline",
|
|
136
|
+
],
|
|
137
|
+
},
|
|
138
|
+
sellable: {
|
|
139
|
+
price: "price",
|
|
140
|
+
saleWindow: { from: "onSaleFrom" },
|
|
141
|
+
// On-demand online courses, no place (ADR 0479): taxed only once an admin turns tax on.
|
|
142
|
+
tax: { code: "txcd_20060158" },
|
|
143
|
+
grants: {
|
|
144
|
+
object: "enrolment",
|
|
145
|
+
set: { holder: "order.person", course: "item", order: "order", code: "code" },
|
|
146
|
+
void: "void",
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
access: {
|
|
150
|
+
sources: [
|
|
151
|
+
{ via: "courses.enrolment", field: "course", ...ACTIVE },
|
|
152
|
+
{ via: "courses.enrolment", field: "bundle", through: "courses", ...ACTIVE },
|
|
153
|
+
],
|
|
154
|
+
},
|
|
155
|
+
indexes: [["theme"]],
|
|
156
|
+
},
|
|
157
|
+
bundle: {
|
|
158
|
+
label: "Bundle",
|
|
159
|
+
plural: "Bundles",
|
|
160
|
+
icon: "package",
|
|
161
|
+
titleField: "title",
|
|
162
|
+
description: "A fixed set of courses sold together at one price.",
|
|
163
|
+
navigation: "main",
|
|
164
|
+
navigationOrder: 16,
|
|
165
|
+
fields: {
|
|
166
|
+
title: { type: "text", label: "Title", required: true },
|
|
167
|
+
slug: { type: "slug", label: "Slug" },
|
|
168
|
+
summary: { type: "text", label: "Summary" },
|
|
169
|
+
description: { type: "richText", label: "Description" },
|
|
170
|
+
cover: { type: "image", label: "Cover" },
|
|
171
|
+
courses: {
|
|
172
|
+
type: "document",
|
|
173
|
+
label: "Courses",
|
|
174
|
+
schema: {
|
|
175
|
+
root: {
|
|
176
|
+
type: "object",
|
|
177
|
+
fields: {
|
|
178
|
+
items: {
|
|
179
|
+
type: "array",
|
|
180
|
+
min: 2,
|
|
181
|
+
max: 10,
|
|
182
|
+
of: { type: "ref", to: "courses.course" },
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
price: { type: "currency", label: "Price", required: true },
|
|
189
|
+
},
|
|
190
|
+
publishable: {
|
|
191
|
+
content: ["title", "summary", "description", "cover", "courses"],
|
|
192
|
+
slug: "slug",
|
|
193
|
+
},
|
|
194
|
+
public: { read: ["title", "slug", "summary", "description", "cover", "courses", "price"] },
|
|
195
|
+
sellable: {
|
|
196
|
+
price: "price",
|
|
197
|
+
tax: { code: "txcd_20060158" },
|
|
198
|
+
grants: {
|
|
199
|
+
object: "enrolment",
|
|
200
|
+
set: { holder: "order.person", bundle: "item", order: "order", code: "code" },
|
|
201
|
+
void: "void",
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
enrolment: {
|
|
206
|
+
label: "Enrolment",
|
|
207
|
+
plural: "Enrolments",
|
|
208
|
+
icon: "badge-check",
|
|
209
|
+
titleField: "code",
|
|
210
|
+
description: "A student's access to a course or a bundle: bought (granted by a paid order), given by " +
|
|
211
|
+
"staff, or imported. Voided when its order is refunded in full.",
|
|
212
|
+
navigation: "main",
|
|
213
|
+
navigationOrder: 17,
|
|
214
|
+
fields: {
|
|
215
|
+
code: { type: "text", label: "Code", readOnly: true },
|
|
216
|
+
holder: { type: "relation", label: "Student", to: "person" },
|
|
217
|
+
course: { type: "relation", label: "Course", to: "courses.course" },
|
|
218
|
+
bundle: { type: "relation", label: "Bundle", to: "courses.bundle" },
|
|
219
|
+
order: { type: "text", label: "Order" },
|
|
220
|
+
source: {
|
|
221
|
+
type: "select",
|
|
222
|
+
label: "Where it came from",
|
|
223
|
+
default: "purchase",
|
|
224
|
+
options: [
|
|
225
|
+
{ value: "purchase", label: "Bought" },
|
|
226
|
+
{ value: "staff", label: "Given by staff" },
|
|
227
|
+
{ value: "import", label: "Imported" },
|
|
228
|
+
],
|
|
229
|
+
},
|
|
230
|
+
reason: { type: "text", label: "Why it was given or ended" },
|
|
231
|
+
from: { type: "datetime", label: "From" },
|
|
232
|
+
until: {
|
|
233
|
+
type: "datetime",
|
|
234
|
+
label: "Until",
|
|
235
|
+
description: "Empty: for as long as the course is offered.",
|
|
236
|
+
},
|
|
237
|
+
completed: {
|
|
238
|
+
type: "boolean",
|
|
239
|
+
label: "Completed (imported)",
|
|
240
|
+
description: "Marked done on the old platform: the course shows as complete.",
|
|
241
|
+
},
|
|
242
|
+
status: {
|
|
243
|
+
type: "select",
|
|
244
|
+
label: "Status",
|
|
245
|
+
track: "timeline",
|
|
246
|
+
options: [
|
|
247
|
+
{ value: "active", label: "Active" },
|
|
248
|
+
{ value: "ended", label: "Ended" },
|
|
249
|
+
{ value: "void", label: "Void" },
|
|
250
|
+
],
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
states: {
|
|
254
|
+
field: "status",
|
|
255
|
+
initial: "active",
|
|
256
|
+
moves: [
|
|
257
|
+
{ from: "active", to: "ended", by: ["staff"] },
|
|
258
|
+
{ from: "ended", to: "active", by: ["staff"] },
|
|
259
|
+
// A full refund of its order (the host, ADR 0435); never a customer.
|
|
260
|
+
{ from: ["active", "ended"], to: "void", by: ["host"], final: true },
|
|
261
|
+
],
|
|
262
|
+
},
|
|
263
|
+
customer: {
|
|
264
|
+
field: "holder",
|
|
265
|
+
read: ["course", "bundle", "source", "from", "until", "completed", "status"],
|
|
266
|
+
write: [],
|
|
267
|
+
},
|
|
268
|
+
timelineLinks: ["holder"],
|
|
269
|
+
indexes: [["holder"], ["course"], ["bundle"], ["order"]],
|
|
270
|
+
},
|
|
271
|
+
progress: {
|
|
272
|
+
label: "Progress",
|
|
273
|
+
plural: "Progress",
|
|
274
|
+
icon: "list-checks",
|
|
275
|
+
titleField: "lessonKey",
|
|
276
|
+
description: "One student's progress on one lesson: started or done, and where a video was left.",
|
|
277
|
+
navigation: "settings",
|
|
278
|
+
fields: {
|
|
279
|
+
holder: { type: "relation", label: "Student", to: "person", required: true },
|
|
280
|
+
course: { type: "relation", label: "Course", to: "courses.course", required: true },
|
|
281
|
+
lessonKey: { type: "text", label: "Lesson", required: true },
|
|
282
|
+
state: {
|
|
283
|
+
type: "select",
|
|
284
|
+
label: "State",
|
|
285
|
+
options: [
|
|
286
|
+
{ value: "started", label: "Started" },
|
|
287
|
+
{ value: "done", label: "Done" },
|
|
288
|
+
],
|
|
289
|
+
},
|
|
290
|
+
startedAt: { type: "datetime", label: "Started" },
|
|
291
|
+
doneAt: { type: "datetime", label: "Done" },
|
|
292
|
+
position: {
|
|
293
|
+
type: "number",
|
|
294
|
+
label: "Position (seconds)",
|
|
295
|
+
min: 0,
|
|
296
|
+
max: 86_400,
|
|
297
|
+
description: "Where the video was left, so the player resumes there.",
|
|
298
|
+
},
|
|
299
|
+
source: {
|
|
300
|
+
type: "select",
|
|
301
|
+
label: "Where it came from",
|
|
302
|
+
default: "self",
|
|
303
|
+
options: [
|
|
304
|
+
{ value: "self", label: "The student" },
|
|
305
|
+
{ value: "import", label: "Imported" },
|
|
306
|
+
],
|
|
307
|
+
},
|
|
308
|
+
},
|
|
309
|
+
customer: {
|
|
310
|
+
field: "holder",
|
|
311
|
+
read: ["course", "lessonKey", "state", "startedAt", "doneAt", "position", "source"],
|
|
312
|
+
write: ["course", "lessonKey", "state", "startedAt", "doneAt", "position"],
|
|
313
|
+
// Written only while the student holds access to the course (ADR 0478).
|
|
314
|
+
requireAccess: ["course"],
|
|
315
|
+
},
|
|
316
|
+
indexes: [
|
|
317
|
+
["holder", "course"],
|
|
318
|
+
["course", "lessonKey"],
|
|
319
|
+
],
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
views: {
|
|
323
|
+
published: {
|
|
324
|
+
label: "Published courses",
|
|
325
|
+
object: "courses.course",
|
|
326
|
+
filter: { field: "publishState", op: "eq", value: "published" },
|
|
327
|
+
sort: { field: "title", direction: "asc" },
|
|
328
|
+
columns: ["title", "theme", "level", "price", "publishedAt"],
|
|
329
|
+
},
|
|
330
|
+
drafts: {
|
|
331
|
+
label: "Drafts",
|
|
332
|
+
object: "courses.course",
|
|
333
|
+
filter: { field: "publishState", op: "eq", value: "draft" },
|
|
334
|
+
sort: { field: "updatedAt", direction: "desc" },
|
|
335
|
+
columns: ["title", "theme", "level", "updatedAt"],
|
|
336
|
+
},
|
|
337
|
+
enrolmentsThisMonth: {
|
|
338
|
+
label: "Enrolments this month",
|
|
339
|
+
object: "courses.enrolment",
|
|
340
|
+
filter: { field: "createdAt", op: "gte", value: { $relative: "startOfMonth" } },
|
|
341
|
+
sort: { field: "createdAt", direction: "desc" },
|
|
342
|
+
columns: ["holder", "course", "bundle", "source", "status", "createdAt"],
|
|
343
|
+
},
|
|
344
|
+
importedEnrolments: {
|
|
345
|
+
label: "Imported enrolments",
|
|
346
|
+
object: "courses.enrolment",
|
|
347
|
+
filter: { field: "source", op: "eq", value: "import" },
|
|
348
|
+
sort: { field: "createdAt", direction: "desc" },
|
|
349
|
+
columns: ["holder", "course", "bundle", "completed", "until", "createdAt"],
|
|
350
|
+
},
|
|
351
|
+
},
|
|
352
|
+
dashboards: coursesDashboards,
|
|
353
|
+
recordTabs: {
|
|
354
|
+
personCourses: {
|
|
355
|
+
label: "Courses",
|
|
356
|
+
on: "person",
|
|
357
|
+
view: {
|
|
358
|
+
type: "table",
|
|
359
|
+
object: "courses.enrolment",
|
|
360
|
+
relation: "holder",
|
|
361
|
+
columns: ["course", "bundle", "source", "status", "until", "createdAt"],
|
|
362
|
+
sort: { field: "createdAt", direction: "desc" },
|
|
363
|
+
},
|
|
364
|
+
order: 35,
|
|
365
|
+
},
|
|
366
|
+
personProgress: {
|
|
367
|
+
label: "Lessons",
|
|
368
|
+
on: "person",
|
|
369
|
+
view: {
|
|
370
|
+
type: "table",
|
|
371
|
+
object: "courses.progress",
|
|
372
|
+
relation: "holder",
|
|
373
|
+
columns: ["course", "lessonKey", "state", "doneAt", "position"],
|
|
374
|
+
sort: { field: "updatedAt", direction: "desc" },
|
|
375
|
+
},
|
|
376
|
+
order: 36,
|
|
377
|
+
},
|
|
378
|
+
},
|
|
379
|
+
automations: coursesAutomations,
|
|
380
|
+
grantable: ["courses:enrol"],
|
|
381
|
+
tools: {
|
|
382
|
+
catalogue,
|
|
383
|
+
course,
|
|
384
|
+
lesson,
|
|
385
|
+
progress,
|
|
386
|
+
myCourses,
|
|
387
|
+
buy,
|
|
388
|
+
enrol,
|
|
389
|
+
endEnrolment,
|
|
390
|
+
stats,
|
|
391
|
+
draft,
|
|
392
|
+
startSession,
|
|
393
|
+
},
|
|
394
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { type DocumentSchema } from "@composable-os/sdk";
|
|
2
|
+
/** The kinds of lesson, in the order the builder offers them. */
|
|
3
|
+
export declare const LESSON_KINDS: readonly ["video", "text", "session", "download"];
|
|
4
|
+
export type LessonKind = (typeof LESSON_KINDS)[number];
|
|
5
|
+
/** The most sections a course has, and lessons a section. */
|
|
6
|
+
export declare const MAX_SECTIONS = 50;
|
|
7
|
+
export declare const MAX_LESSONS_PER_SECTION = 100;
|
|
8
|
+
/** The most an outline may be, in bytes of its JSON. */
|
|
9
|
+
export declare const OUTLINE_MAX_BYTES = 524288;
|
|
10
|
+
/** The outline's schema: a document field's `schema` (with rich text's definitions in it). */
|
|
11
|
+
export declare const OUTLINE_SCHEMA: DocumentSchema;
|
|
12
|
+
/** A video value (`VIDEO_NODE`). */
|
|
13
|
+
export interface VideoValue {
|
|
14
|
+
media: string;
|
|
15
|
+
poster?: string;
|
|
16
|
+
}
|
|
17
|
+
interface LessonBase {
|
|
18
|
+
key: string;
|
|
19
|
+
title: string;
|
|
20
|
+
duration?: number;
|
|
21
|
+
preview?: boolean;
|
|
22
|
+
sourceId?: string;
|
|
23
|
+
}
|
|
24
|
+
/** A lesson as the outline holds it. Holders' parts are absent for a reader without access. */
|
|
25
|
+
export type Lesson = (LessonBase & {
|
|
26
|
+
kind: "video";
|
|
27
|
+
video?: VideoValue;
|
|
28
|
+
notes?: unknown;
|
|
29
|
+
}) | (LessonBase & {
|
|
30
|
+
kind: "text";
|
|
31
|
+
body?: unknown;
|
|
32
|
+
}) | (LessonBase & {
|
|
33
|
+
kind: "session";
|
|
34
|
+
program?: string;
|
|
35
|
+
week?: number;
|
|
36
|
+
session?: number;
|
|
37
|
+
video?: VideoValue;
|
|
38
|
+
}) | (LessonBase & {
|
|
39
|
+
kind: "download";
|
|
40
|
+
file?: string;
|
|
41
|
+
note?: string;
|
|
42
|
+
});
|
|
43
|
+
export interface Section {
|
|
44
|
+
key: string;
|
|
45
|
+
title: string;
|
|
46
|
+
lessons: Lesson[];
|
|
47
|
+
}
|
|
48
|
+
export interface Outline {
|
|
49
|
+
sections: Section[];
|
|
50
|
+
}
|
|
51
|
+
/** An empty outline. */
|
|
52
|
+
export declare const EMPTY_OUTLINE: Outline;
|
|
53
|
+
/** The value as an outline, or an empty one when it is not one. */
|
|
54
|
+
export declare function asOutline(value: unknown): Outline;
|
|
55
|
+
/** Every lesson in order, with its section's key. */
|
|
56
|
+
export declare function lessonsOf(outline: Outline): (Lesson & {
|
|
57
|
+
section: string;
|
|
58
|
+
})[];
|
|
59
|
+
/** One lesson by its key, or null. */
|
|
60
|
+
export declare function findLesson(outline: Outline, key: string): (Lesson & {
|
|
61
|
+
section: string;
|
|
62
|
+
}) | null;
|
|
63
|
+
/** The lesson after this one, or null at the end. */
|
|
64
|
+
export declare function nextLesson(outline: Outline, key: string): Lesson | null;
|
|
65
|
+
/** Where a lesson's video is, if it has one (a video lesson's, or a session's follow-along). */
|
|
66
|
+
export declare function lessonVideo(lesson: Lesson): VideoValue | null;
|
|
67
|
+
/** The programs a course's session lessons use, each once. */
|
|
68
|
+
export declare function sessionPrograms(outline: Outline): string[];
|
|
69
|
+
/**
|
|
70
|
+
* How far a student is: the lessons that count (every lesson that is not a download), how many of
|
|
71
|
+
* them are done, and whether the course is complete (all of them, or imported as completed). A
|
|
72
|
+
* lesson the outline no longer has does not count, whatever its progress row says.
|
|
73
|
+
*/
|
|
74
|
+
export declare function completion(outline: Outline, done: ReadonlySet<string>, importedComplete?: boolean): {
|
|
75
|
+
counted: number;
|
|
76
|
+
done: number;
|
|
77
|
+
complete: boolean;
|
|
78
|
+
};
|
|
79
|
+
/** A video counts as watched once its position is within this many seconds of its end. */
|
|
80
|
+
export declare const END_SECONDS = 10;
|
|
81
|
+
/** Whether a video left at `position` of `duration` seconds has been watched to its end. */
|
|
82
|
+
export declare function watchedToEnd(position: number, duration: number | null | undefined): boolean;
|
|
83
|
+
/** What is wrong with an outline beyond its schema: a lesson key used twice across sections. */
|
|
84
|
+
export declare function outlineProblems(outline: Outline): string[];
|
|
85
|
+
export {};
|
package/dist/outline.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// A course's outline (stage 42, step 4; ADR 0478): one document of sections of lessons, versioned
|
|
2
|
+
// and copied whole when the course is published, as a program's layout is (ADR 0448).
|
|
3
|
+
//
|
|
4
|
+
// outline → sections (a key, a title) → lessons, each one kind:
|
|
5
|
+
// video a ready video from the media library, and notes in rich text
|
|
6
|
+
// text a page of rich text
|
|
7
|
+
// session a published Programs program and one session of its layout (week, position),
|
|
8
|
+
// with an optional video to follow along to
|
|
9
|
+
// download a file from the media library (a PDF) and a note
|
|
10
|
+
//
|
|
11
|
+
// Every lesson has a key that names it for good (progress is kept by it), a title, a duration in
|
|
12
|
+
// minutes, whether it is a free preview, and the id it had on the old platform (for the import).
|
|
13
|
+
// The title, kind, duration and preview flag are for everyone who may read the course; the rest is
|
|
14
|
+
// for holders only (`holders`, ADR 0477), unless the lesson is a free preview. The host removes
|
|
15
|
+
// those parts for everyone else and plays their videos only to a holder: nothing here decides it.
|
|
16
|
+
import { FILE_NODE, RICH_TEXT_SCHEMA, VIDEO_NODE, } from "@composable-os/sdk";
|
|
17
|
+
/** The kinds of lesson, in the order the builder offers them. */
|
|
18
|
+
export const LESSON_KINDS = ["video", "text", "session", "download"];
|
|
19
|
+
/** The most sections a course has, and lessons a section. */
|
|
20
|
+
export const MAX_SECTIONS = 50;
|
|
21
|
+
export const MAX_LESSONS_PER_SECTION = 100;
|
|
22
|
+
/** The most an outline may be, in bytes of its JSON. */
|
|
23
|
+
export const OUTLINE_MAX_BYTES = 524_288;
|
|
24
|
+
const KEY_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-";
|
|
25
|
+
const optional = (node) => ({ ...node, optional: true });
|
|
26
|
+
const richText = { type: "use", def: "richText" };
|
|
27
|
+
/** What every lesson has, whatever its kind. */
|
|
28
|
+
const common = {
|
|
29
|
+
key: {
|
|
30
|
+
type: "text",
|
|
31
|
+
min: 1,
|
|
32
|
+
max: 40,
|
|
33
|
+
chars: KEY_CHARS,
|
|
34
|
+
description: "The lesson's name for good: progress is kept by it. Never changed once published.",
|
|
35
|
+
},
|
|
36
|
+
title: { type: "text", min: 1, max: 200, noMarkup: true },
|
|
37
|
+
duration: optional({
|
|
38
|
+
type: "number",
|
|
39
|
+
min: 0,
|
|
40
|
+
max: 600,
|
|
41
|
+
integer: true,
|
|
42
|
+
description: "Minutes",
|
|
43
|
+
}),
|
|
44
|
+
preview: optional({
|
|
45
|
+
type: "boolean",
|
|
46
|
+
description: "A free preview: everyone who may read the course reads it, and plays its video",
|
|
47
|
+
}),
|
|
48
|
+
sourceId: optional({
|
|
49
|
+
type: "text",
|
|
50
|
+
max: 100,
|
|
51
|
+
description: "Its id on the platform it was imported from",
|
|
52
|
+
}),
|
|
53
|
+
};
|
|
54
|
+
const lesson = (fields, holders) => ({
|
|
55
|
+
type: "object",
|
|
56
|
+
fields: { ...common, ...fields },
|
|
57
|
+
// The lesson's own material is for holders, unless it is a free preview.
|
|
58
|
+
holders: { keys: holders, unless: "preview" },
|
|
59
|
+
});
|
|
60
|
+
/** The outline's schema: a document field's `schema` (with rich text's definitions in it). */
|
|
61
|
+
export const OUTLINE_SCHEMA = {
|
|
62
|
+
root: {
|
|
63
|
+
type: "object",
|
|
64
|
+
fields: {
|
|
65
|
+
sections: {
|
|
66
|
+
type: "array",
|
|
67
|
+
max: MAX_SECTIONS,
|
|
68
|
+
unique: "key",
|
|
69
|
+
of: {
|
|
70
|
+
type: "object",
|
|
71
|
+
fields: {
|
|
72
|
+
key: { type: "text", min: 1, max: 40, chars: KEY_CHARS },
|
|
73
|
+
title: { type: "text", min: 1, max: 200, noMarkup: true },
|
|
74
|
+
lessons: {
|
|
75
|
+
type: "array",
|
|
76
|
+
max: MAX_LESSONS_PER_SECTION,
|
|
77
|
+
unique: "key",
|
|
78
|
+
// A lesson's key once in the whole outline: its progress is kept by it.
|
|
79
|
+
uniqueAcross: true,
|
|
80
|
+
of: {
|
|
81
|
+
type: "union",
|
|
82
|
+
tag: "kind",
|
|
83
|
+
variants: {
|
|
84
|
+
video: lesson({ video: VIDEO_NODE, notes: optional(richText) }, [
|
|
85
|
+
"video",
|
|
86
|
+
"notes",
|
|
87
|
+
]),
|
|
88
|
+
text: lesson({ body: richText }, ["body"]),
|
|
89
|
+
session: lesson({
|
|
90
|
+
program: {
|
|
91
|
+
type: "ref",
|
|
92
|
+
to: "programs.program",
|
|
93
|
+
description: "A published Programs program",
|
|
94
|
+
},
|
|
95
|
+
week: { type: "number", min: 1, max: 52, integer: true },
|
|
96
|
+
session: {
|
|
97
|
+
type: "number",
|
|
98
|
+
min: 0,
|
|
99
|
+
max: 13,
|
|
100
|
+
integer: true,
|
|
101
|
+
description: "Which session of that week (0 is the first)",
|
|
102
|
+
},
|
|
103
|
+
video: optional(VIDEO_NODE),
|
|
104
|
+
}, ["program", "week", "session", "video"]),
|
|
105
|
+
download: lesson({
|
|
106
|
+
file: FILE_NODE,
|
|
107
|
+
note: optional({ type: "text", max: 2000, multiline: true, noMarkup: true }),
|
|
108
|
+
}, ["file", "note"]),
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
defs: { ...(RICH_TEXT_SCHEMA.defs ?? {}), richText: RICH_TEXT_SCHEMA.root },
|
|
118
|
+
};
|
|
119
|
+
/** An empty outline. */
|
|
120
|
+
export const EMPTY_OUTLINE = { sections: [] };
|
|
121
|
+
/** The value as an outline, or an empty one when it is not one. */
|
|
122
|
+
export function asOutline(value) {
|
|
123
|
+
const v = value;
|
|
124
|
+
return v && Array.isArray(v.sections) ? v : EMPTY_OUTLINE;
|
|
125
|
+
}
|
|
126
|
+
/** Every lesson in order, with its section's key. */
|
|
127
|
+
export function lessonsOf(outline) {
|
|
128
|
+
return outline.sections.flatMap((section) => (section.lessons ?? []).map((l) => ({ ...l, section: section.key })));
|
|
129
|
+
}
|
|
130
|
+
/** One lesson by its key, or null. */
|
|
131
|
+
export function findLesson(outline, key) {
|
|
132
|
+
return lessonsOf(outline).find((l) => l.key === key) ?? null;
|
|
133
|
+
}
|
|
134
|
+
/** The lesson after this one, or null at the end. */
|
|
135
|
+
export function nextLesson(outline, key) {
|
|
136
|
+
const all = lessonsOf(outline);
|
|
137
|
+
const at = all.findIndex((l) => l.key === key);
|
|
138
|
+
return at >= 0 ? (all[at + 1] ?? null) : null;
|
|
139
|
+
}
|
|
140
|
+
/** Where a lesson's video is, if it has one (a video lesson's, or a session's follow-along). */
|
|
141
|
+
export function lessonVideo(lesson) {
|
|
142
|
+
return (lesson.kind === "video" || lesson.kind === "session") && lesson.video
|
|
143
|
+
? lesson.video
|
|
144
|
+
: null;
|
|
145
|
+
}
|
|
146
|
+
/** The programs a course's session lessons use, each once. */
|
|
147
|
+
export function sessionPrograms(outline) {
|
|
148
|
+
return [
|
|
149
|
+
...new Set(lessonsOf(outline)
|
|
150
|
+
.map((l) => (l.kind === "session" ? l.program : undefined))
|
|
151
|
+
.filter((p) => Boolean(p))),
|
|
152
|
+
];
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* How far a student is: the lessons that count (every lesson that is not a download), how many of
|
|
156
|
+
* them are done, and whether the course is complete (all of them, or imported as completed). A
|
|
157
|
+
* lesson the outline no longer has does not count, whatever its progress row says.
|
|
158
|
+
*/
|
|
159
|
+
export function completion(outline, done, importedComplete = false) {
|
|
160
|
+
const counted = lessonsOf(outline).filter((l) => l.kind !== "download");
|
|
161
|
+
const doneCount = counted.filter((l) => done.has(l.key)).length;
|
|
162
|
+
return {
|
|
163
|
+
counted: counted.length,
|
|
164
|
+
done: doneCount,
|
|
165
|
+
complete: importedComplete || (counted.length > 0 && doneCount === counted.length),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/** A video counts as watched once its position is within this many seconds of its end. */
|
|
169
|
+
export const END_SECONDS = 10;
|
|
170
|
+
/** Whether a video left at `position` of `duration` seconds has been watched to its end. */
|
|
171
|
+
export function watchedToEnd(position, duration) {
|
|
172
|
+
return typeof duration === "number" && duration > 0 && position >= duration - END_SECONDS;
|
|
173
|
+
}
|
|
174
|
+
/** What is wrong with an outline beyond its schema: a lesson key used twice across sections. */
|
|
175
|
+
export function outlineProblems(outline) {
|
|
176
|
+
const seen = new Map();
|
|
177
|
+
const problems = [];
|
|
178
|
+
for (const section of outline.sections) {
|
|
179
|
+
for (const l of section.lessons ?? []) {
|
|
180
|
+
const before = seen.get(l.key);
|
|
181
|
+
if (before)
|
|
182
|
+
problems.push(`The lesson key "${l.key}" is in ${before} and ${section.key}`);
|
|
183
|
+
else
|
|
184
|
+
seen.set(l.key, section.key);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return problems;
|
|
188
|
+
}
|