@composable-os/pack-courses 0.0.0-stage → 0.1.0-beta.11

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.
Files changed (39) hide show
  1. package/LICENSE +109 -0
  2. package/dist/automations.d.ts +12 -0
  3. package/dist/automations.js +84 -0
  4. package/dist/blocks/courses-builder/course-builder.d.ts +5 -0
  5. package/dist/blocks/courses-builder/course-builder.js +69 -0
  6. package/dist/blocks/courses-catalogue/catalogue.d.ts +6 -0
  7. package/dist/blocks/courses-catalogue/catalogue.js +21 -0
  8. package/dist/blocks/courses-course/course-page.d.ts +10 -0
  9. package/dist/blocks/courses-course/course-page.js +51 -0
  10. package/dist/blocks/courses-my-courses/my-courses.d.ts +5 -0
  11. package/dist/blocks/courses-my-courses/my-courses.js +20 -0
  12. package/dist/blocks/courses-native-catalogue/catalogue-screen.d.ts +6 -0
  13. package/dist/blocks/courses-native-catalogue/catalogue-screen.js +15 -0
  14. package/dist/blocks/courses-native-course/course-screen.d.ts +7 -0
  15. package/dist/blocks/courses-native-course/course-screen.js +18 -0
  16. package/dist/blocks/courses-native-my-courses/my-courses-screen.d.ts +5 -0
  17. package/dist/blocks/courses-native-my-courses/my-courses-screen.js +9 -0
  18. package/dist/blocks/courses-native-player/lesson-screen.d.ts +19 -0
  19. package/dist/blocks/courses-native-player/lesson-screen.js +11 -0
  20. package/dist/blocks/courses-native-subscription/subscription-screen.d.ts +4 -0
  21. package/dist/blocks/courses-native-subscription/subscription-screen.js +17 -0
  22. package/dist/blocks/courses-player/player.d.ts +12 -0
  23. package/dist/blocks/courses-player/player.js +51 -0
  24. package/dist/blocks/courses-subscribe/subscribe.d.ts +28 -0
  25. package/dist/blocks/courses-subscribe/subscribe.js +146 -0
  26. package/dist/blocks/courses-subscription/my-subscription.d.ts +6 -0
  27. package/dist/blocks/courses-subscription/my-subscription.js +50 -0
  28. package/dist/client/index.d.ts +1319 -0
  29. package/dist/client/index.js +414 -0
  30. package/dist/dashboards.d.ts +5 -0
  31. package/dist/dashboards.js +119 -0
  32. package/dist/index.d.ts +809 -0
  33. package/dist/index.js +427 -0
  34. package/dist/outline.d.ts +85 -0
  35. package/dist/outline.js +188 -0
  36. package/dist/tools.d.ts +255 -0
  37. package/dist/tools.js +826 -0
  38. package/package.json +36 -4
  39. package/README.md +0 -3
package/dist/index.js ADDED
@@ -0,0 +1,427 @@
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
+ // - a course plan is `sellable` with `recurring` (stage 32a, ADR 0485): a subscription to it,
17
+ // which the payment provider charges every month, gives every live course through the host's
18
+ // `subscription` access source (ADR 0488), to its holder, while the host's record says it
19
+ // runs. One free trial per person per plan object is the host's rule (ADR 0489).
20
+ // The tools in tools.ts compose the host's operations and hold no rule of their own.
21
+ import { defineExtension } from "@composable-os/sdk";
22
+ import { coursesAutomations } from "./automations.js";
23
+ import { coursesDashboards } from "./dashboards.js";
24
+ import { OUTLINE_MAX_BYTES, OUTLINE_SCHEMA } from "./outline.js";
25
+ import { buy, catalogue, course, draft, endEnrolment, enrol, lesson, myCourses, plans, progress, startSession, stats, } from "./tools.js";
26
+ const ACTIVE = { states: ["active"], until: "until" };
27
+ export default defineExtension({
28
+ id: "courses",
29
+ version: "0.1.0",
30
+ contractVersion: 1,
31
+ label: "Courses",
32
+ description: "Video courses sold one at a time or in bundles, watched lesson by lesson, with progress. " +
33
+ "A lesson can be a training session from Programs.",
34
+ // A session lesson is a Programs program: the host installs Courses only beside Programs.
35
+ requires: ["programs"],
36
+ permissions: {
37
+ // person.get: a student's name in the stats. programs.*: a session lesson's program, its
38
+ // assignment and dated sessions, made by x.programs.assign for the student (step 6).
39
+ read: ["person", "programs.program", "programs.assignment", "programs.session"],
40
+ write: ["programs.assignment", "programs.session"],
41
+ // record.* and my.* are not listed: listed, they would reach every object. Courses' own
42
+ // objects need no grant, and Programs' are the read and write lists above.
43
+ operations: [
44
+ "public.list",
45
+ "public.get",
46
+ "access.check",
47
+ "order.start",
48
+ "media.list",
49
+ "order.settings.get",
50
+ "query.sql",
51
+ // A session lesson's program, assigned to its student on their first open (step 6).
52
+ "x.programs.assign",
53
+ ],
54
+ modules: ["ops", "ai"],
55
+ },
56
+ objects: {
57
+ theme: {
58
+ label: "Theme",
59
+ plural: "Themes",
60
+ icon: "shapes",
61
+ titleField: "name",
62
+ description: "What courses are grouped by in the catalogue: handstands, mobility.",
63
+ navigation: "settings",
64
+ fields: {
65
+ name: { type: "text", label: "Name", required: true },
66
+ slug: { type: "slug", label: "Slug" },
67
+ order: { type: "number", label: "Order", min: 0, max: 1000, step: 1 },
68
+ summary: { type: "text", label: "Short description" },
69
+ picture: { type: "image", label: "Picture" },
70
+ },
71
+ // Every live theme is the catalogue's.
72
+ public: { read: ["name", "slug", "order", "summary", "picture"] },
73
+ },
74
+ course: {
75
+ label: "Course",
76
+ plural: "Courses",
77
+ icon: "graduation-cap",
78
+ titleField: "title",
79
+ description: "A course of lessons a studio sells: its outline, price, trailer and cover.",
80
+ navigation: "main",
81
+ navigationOrder: 15,
82
+ fields: {
83
+ title: { type: "text", label: "Title", required: true },
84
+ slug: { type: "slug", label: "Slug" },
85
+ theme: { type: "relation", label: "Theme", to: "courses.theme" },
86
+ level: {
87
+ type: "number",
88
+ label: "Level",
89
+ min: 1,
90
+ max: 3,
91
+ step: 1,
92
+ description: "1 to 3: beginner, intermediate, advanced.",
93
+ },
94
+ summary: { type: "text", label: "Summary" },
95
+ description: { type: "richText", label: "Description" },
96
+ cover: { type: "image", label: "Cover" },
97
+ trailer: { type: "video", label: "Trailer" },
98
+ price: { type: "currency", label: "Price", required: true },
99
+ onSaleFrom: { type: "datetime", label: "On sale from" },
100
+ outline: {
101
+ type: "document",
102
+ label: "Outline",
103
+ schema: OUTLINE_SCHEMA,
104
+ maxBytes: OUTLINE_MAX_BYTES,
105
+ },
106
+ },
107
+ publishable: {
108
+ content: [
109
+ "title",
110
+ "theme",
111
+ "level",
112
+ "summary",
113
+ "description",
114
+ "cover",
115
+ "trailer",
116
+ "outline",
117
+ ],
118
+ slug: "slug",
119
+ },
120
+ public: {
121
+ read: [
122
+ "title",
123
+ "slug",
124
+ "theme",
125
+ "level",
126
+ "summary",
127
+ "description",
128
+ "cover",
129
+ "trailer",
130
+ "price",
131
+ "onSaleFrom",
132
+ "outline",
133
+ ],
134
+ },
135
+ sellable: {
136
+ price: "price",
137
+ saleWindow: { from: "onSaleFrom" },
138
+ // On-demand online courses, no place (ADR 0479): taxed only once an admin turns tax on.
139
+ tax: { code: "txcd_20060158" },
140
+ grants: {
141
+ object: "enrolment",
142
+ set: { holder: "order.person", course: "item", order: "order", code: "code" },
143
+ void: "void",
144
+ },
145
+ },
146
+ access: {
147
+ sources: [
148
+ { via: "courses.enrolment", field: "course", ...ACTIVE },
149
+ { via: "courses.enrolment", field: "bundle", through: "courses", ...ACTIVE },
150
+ // A running course subscription (stage 32a, ADR 0488): every live course, including
151
+ // ones published later, while the host's subscription record says it gives access.
152
+ { kind: "subscription", options: { plans: "courses.plan", covers: "all" } },
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
+ plan: {
206
+ label: "Course plan",
207
+ plural: "Course plans",
208
+ icon: "repeat",
209
+ titleField: "title",
210
+ description: "A subscription to every published course, paid every month, with a free trial when it " +
211
+ "has trial days. One trial per person per plan; the payment provider charges each month.",
212
+ navigation: "main",
213
+ navigationOrder: 18,
214
+ fields: {
215
+ title: { type: "text", label: "Title", required: true },
216
+ description: { type: "text", label: "Description" },
217
+ price: { type: "currency", label: "Price per month", required: true },
218
+ trialDays: {
219
+ type: "number",
220
+ label: "Free trial (days)",
221
+ min: 0,
222
+ max: 90,
223
+ step: 1,
224
+ description: "Empty or 0: charged from the start. A person gets one trial on any plan.",
225
+ },
226
+ },
227
+ // Every live plan is offered on the site.
228
+ public: { read: ["title", "description", "price", "trialDays"] },
229
+ sellable: {
230
+ price: "price",
231
+ // As its courses (ADR 0479): taxed only once a human admin turns tax on.
232
+ tax: { code: "txcd_20060158" },
233
+ // A plan (ADR 0485): subscribed to with subscription.start, never put on an order.
234
+ recurring: { interval: "month", trialDays: "trialDays" },
235
+ },
236
+ },
237
+ enrolment: {
238
+ label: "Enrolment",
239
+ plural: "Enrolments",
240
+ icon: "badge-check",
241
+ titleField: "code",
242
+ description: "A student's access to a course or a bundle: bought (granted by a paid order), given by " +
243
+ "staff, or imported. Voided when its order is refunded in full.",
244
+ navigation: "main",
245
+ navigationOrder: 17,
246
+ fields: {
247
+ code: { type: "text", label: "Code", readOnly: true },
248
+ holder: { type: "relation", label: "Student", to: "person" },
249
+ course: { type: "relation", label: "Course", to: "courses.course" },
250
+ bundle: { type: "relation", label: "Bundle", to: "courses.bundle" },
251
+ order: { type: "text", label: "Order" },
252
+ source: {
253
+ type: "select",
254
+ label: "Where it came from",
255
+ default: "purchase",
256
+ options: [
257
+ { value: "purchase", label: "Bought" },
258
+ { value: "staff", label: "Given by staff" },
259
+ { value: "import", label: "Imported" },
260
+ ],
261
+ },
262
+ reason: { type: "text", label: "Why it was given or ended" },
263
+ from: { type: "datetime", label: "From" },
264
+ until: {
265
+ type: "datetime",
266
+ label: "Until",
267
+ description: "Empty: for as long as the course is offered.",
268
+ },
269
+ completed: {
270
+ type: "boolean",
271
+ label: "Completed (imported)",
272
+ description: "Marked done on the old platform: the course shows as complete.",
273
+ },
274
+ status: {
275
+ type: "select",
276
+ label: "Status",
277
+ track: "timeline",
278
+ options: [
279
+ { value: "active", label: "Active" },
280
+ { value: "ended", label: "Ended" },
281
+ { value: "void", label: "Void" },
282
+ ],
283
+ },
284
+ },
285
+ states: {
286
+ field: "status",
287
+ initial: "active",
288
+ moves: [
289
+ { from: "active", to: "ended", by: ["staff"] },
290
+ { from: "ended", to: "active", by: ["staff"] },
291
+ // A full refund of its order (the host, ADR 0435); never a customer.
292
+ { from: ["active", "ended"], to: "void", by: ["host"], final: true },
293
+ ],
294
+ },
295
+ customer: {
296
+ field: "holder",
297
+ read: ["course", "bundle", "source", "from", "until", "completed", "status"],
298
+ write: [],
299
+ },
300
+ timelineLinks: ["holder"],
301
+ indexes: [["holder"], ["course"], ["bundle"], ["order"]],
302
+ },
303
+ progress: {
304
+ label: "Progress",
305
+ plural: "Progress",
306
+ icon: "list-checks",
307
+ titleField: "lessonKey",
308
+ description: "One student's progress on one lesson: started or done, and where a video was left.",
309
+ navigation: "settings",
310
+ fields: {
311
+ holder: { type: "relation", label: "Student", to: "person", required: true },
312
+ course: { type: "relation", label: "Course", to: "courses.course", required: true },
313
+ lessonKey: { type: "text", label: "Lesson", required: true },
314
+ state: {
315
+ type: "select",
316
+ label: "State",
317
+ options: [
318
+ { value: "started", label: "Started" },
319
+ { value: "done", label: "Done" },
320
+ ],
321
+ },
322
+ startedAt: { type: "datetime", label: "Started" },
323
+ doneAt: { type: "datetime", label: "Done" },
324
+ position: {
325
+ type: "number",
326
+ label: "Position (seconds)",
327
+ min: 0,
328
+ max: 86_400,
329
+ description: "Where the video was left, so the player resumes there.",
330
+ },
331
+ source: {
332
+ type: "select",
333
+ label: "Where it came from",
334
+ default: "self",
335
+ options: [
336
+ { value: "self", label: "The student" },
337
+ { value: "import", label: "Imported" },
338
+ ],
339
+ },
340
+ },
341
+ customer: {
342
+ field: "holder",
343
+ read: ["course", "lessonKey", "state", "startedAt", "doneAt", "position", "source"],
344
+ write: ["course", "lessonKey", "state", "startedAt", "doneAt", "position"],
345
+ // Written only while the student holds access to the course (ADR 0478).
346
+ requireAccess: ["course"],
347
+ },
348
+ indexes: [
349
+ ["holder", "course"],
350
+ ["course", "lessonKey"],
351
+ ],
352
+ },
353
+ },
354
+ views: {
355
+ published: {
356
+ label: "Published courses",
357
+ object: "courses.course",
358
+ filter: { field: "publishState", op: "eq", value: "published" },
359
+ sort: { field: "title", direction: "asc" },
360
+ columns: ["title", "theme", "level", "price", "publishedAt"],
361
+ },
362
+ drafts: {
363
+ label: "Drafts",
364
+ object: "courses.course",
365
+ filter: { field: "publishState", op: "eq", value: "draft" },
366
+ sort: { field: "updatedAt", direction: "desc" },
367
+ columns: ["title", "theme", "level", "updatedAt"],
368
+ },
369
+ enrolmentsThisMonth: {
370
+ label: "Enrolments this month",
371
+ object: "courses.enrolment",
372
+ filter: { field: "createdAt", op: "gte", value: { $relative: "startOfMonth" } },
373
+ sort: { field: "createdAt", direction: "desc" },
374
+ columns: ["holder", "course", "bundle", "source", "status", "createdAt"],
375
+ },
376
+ importedEnrolments: {
377
+ label: "Imported enrolments",
378
+ object: "courses.enrolment",
379
+ filter: { field: "source", op: "eq", value: "import" },
380
+ sort: { field: "createdAt", direction: "desc" },
381
+ columns: ["holder", "course", "bundle", "completed", "until", "createdAt"],
382
+ },
383
+ },
384
+ dashboards: coursesDashboards,
385
+ recordTabs: {
386
+ personCourses: {
387
+ label: "Courses",
388
+ on: "person",
389
+ view: {
390
+ type: "table",
391
+ object: "courses.enrolment",
392
+ relation: "holder",
393
+ columns: ["course", "bundle", "source", "status", "until", "createdAt"],
394
+ sort: { field: "createdAt", direction: "desc" },
395
+ },
396
+ order: 35,
397
+ },
398
+ personProgress: {
399
+ label: "Lessons",
400
+ on: "person",
401
+ view: {
402
+ type: "table",
403
+ object: "courses.progress",
404
+ relation: "holder",
405
+ columns: ["course", "lessonKey", "state", "doneAt", "position"],
406
+ sort: { field: "updatedAt", direction: "desc" },
407
+ },
408
+ order: 36,
409
+ },
410
+ },
411
+ automations: coursesAutomations,
412
+ grantable: ["courses:enrol"],
413
+ tools: {
414
+ catalogue,
415
+ course,
416
+ lesson,
417
+ progress,
418
+ myCourses,
419
+ plans,
420
+ buy,
421
+ enrol,
422
+ endEnrolment,
423
+ stats,
424
+ draft,
425
+ startSession,
426
+ },
427
+ });
@@ -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 {};