@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.
Files changed (33) 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 +19 -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-player/player.d.ts +12 -0
  21. package/dist/blocks/courses-player/player.js +51 -0
  22. package/dist/client/index.d.ts +933 -0
  23. package/dist/client/index.js +277 -0
  24. package/dist/dashboards.d.ts +5 -0
  25. package/dist/dashboards.js +119 -0
  26. package/dist/index.d.ts +746 -0
  27. package/dist/index.js +394 -0
  28. package/dist/outline.d.ts +85 -0
  29. package/dist/outline.js +188 -0
  30. package/dist/tools.d.ts +243 -0
  31. package/dist/tools.js +778 -0
  32. package/package.json +36 -4
  33. package/README.md +0 -3
@@ -0,0 +1,933 @@
1
+ import { type ClientHolding, type PackClient } from "@composable-os/client";
2
+ import type { z } from "@composable-os/sdk";
3
+ import { type Lesson, type LessonKind, type Outline, type Section } from "../outline.ts";
4
+ import type { buy, catalogue, course, endEnrolment, enrol, lesson, myCourses, progress, startSession, stats } from "../tools.ts";
5
+ export { completion, findLesson, lessonsOf, nextLesson, watchedToEnd } from "../outline.ts";
6
+ export type { Lesson, LessonKind, Outline, Section };
7
+ type Io<T extends {
8
+ input: z.ZodType;
9
+ output: z.ZodType;
10
+ }> = {
11
+ input: z.input<T["input"]>;
12
+ output: z.output<T["output"]>;
13
+ };
14
+ export declare const COURSE = "courses.course";
15
+ /** What media.play answers (ADR 0476). */
16
+ export interface Playback {
17
+ id: string;
18
+ token: string;
19
+ expiresAt: string;
20
+ hls: string;
21
+ dash: string;
22
+ iframe: string;
23
+ poster: string;
24
+ duration: number | null;
25
+ captions: {
26
+ language: string;
27
+ label: string;
28
+ }[];
29
+ }
30
+ /** The operations this entry calls, as the generated client types them. */
31
+ export type CoursesOperations = {
32
+ "x.courses.catalogue": {
33
+ kind: "query";
34
+ } & Io<typeof catalogue>;
35
+ "x.courses.course": {
36
+ kind: "query";
37
+ } & Io<typeof course>;
38
+ "x.courses.lesson": {
39
+ kind: "query";
40
+ } & Io<typeof lesson>;
41
+ "x.courses.myCourses": {
42
+ kind: "query";
43
+ } & Io<typeof myCourses>;
44
+ "x.courses.startSession": {
45
+ kind: "query";
46
+ } & Io<typeof startSession>;
47
+ "x.courses.progress": {
48
+ kind: "mutation";
49
+ } & Io<typeof progress>;
50
+ "x.courses.buy": {
51
+ kind: "mutation";
52
+ } & Io<typeof buy>;
53
+ "x.courses.enrol": {
54
+ kind: "mutation";
55
+ } & Io<typeof enrol>;
56
+ "x.courses.endEnrolment": {
57
+ kind: "mutation";
58
+ } & Io<typeof endEnrolment>;
59
+ "x.courses.stats": {
60
+ kind: "query";
61
+ } & Io<typeof stats>;
62
+ "media.play": {
63
+ kind: "query";
64
+ input: {
65
+ id: string;
66
+ record?: {
67
+ object: string;
68
+ id: string;
69
+ };
70
+ field?: string;
71
+ purpose?: "stream";
72
+ seconds?: number;
73
+ };
74
+ output: Playback;
75
+ };
76
+ "order.checkout": {
77
+ kind: "mutation";
78
+ input: {
79
+ id: string;
80
+ token?: string;
81
+ returnUrl: string;
82
+ };
83
+ output: {
84
+ url: string;
85
+ };
86
+ };
87
+ "record.update": {
88
+ kind: "mutation";
89
+ input: {
90
+ object: string;
91
+ id: string;
92
+ values: Record<string, unknown>;
93
+ };
94
+ output: {
95
+ id: string;
96
+ values: Record<string, unknown>;
97
+ };
98
+ };
99
+ "record.get": {
100
+ kind: "query";
101
+ input: {
102
+ object: string;
103
+ id: string;
104
+ };
105
+ output: {
106
+ id: string;
107
+ values: Record<string, unknown>;
108
+ };
109
+ };
110
+ "record.publish": {
111
+ kind: "mutation";
112
+ input: {
113
+ object: string;
114
+ id: string;
115
+ note?: string;
116
+ };
117
+ output: {
118
+ version: number;
119
+ publishedAt: string;
120
+ };
121
+ };
122
+ "media.list": {
123
+ kind: "query";
124
+ input: {
125
+ filter?: unknown;
126
+ limit?: number;
127
+ };
128
+ output: {
129
+ items: {
130
+ id: string;
131
+ values: Record<string, unknown>;
132
+ }[];
133
+ nextCursor: string | null;
134
+ };
135
+ };
136
+ "record.list": {
137
+ kind: "query";
138
+ input: {
139
+ object: string;
140
+ filter?: unknown;
141
+ limit?: number;
142
+ };
143
+ output: {
144
+ items: {
145
+ id: string;
146
+ title?: string | null;
147
+ values: Record<string, unknown>;
148
+ }[];
149
+ };
150
+ };
151
+ };
152
+ type In<N extends keyof CoursesOperations> = CoursesOperations[N]["input"];
153
+ export type CoursesClient = PackClient<CoursesOperations>;
154
+ /** A token is asked for again this long before it expires. */
155
+ export declare const PLAYBACK_REFRESH_BEFORE_MS: number;
156
+ /**
157
+ * How long to wait before asking for a new token: until `PLAYBACK_REFRESH_BEFORE_MS` before it
158
+ * expires, never less than 10 seconds (a token about to expire is asked for again at once after).
159
+ */
160
+ export declare function refreshInMs(expiresAt: string, now?: number): number;
161
+ /** A price as the host gave it, in its currency (`99.00 AUD`). Display only: never worked out. */
162
+ export declare function formatPrice(price: number | null | undefined, currency: string | null | undefined): string;
163
+ /** A lesson's length as a reader sees it: `12 min`. Display only. */
164
+ export declare function minutes(duration: number | null | undefined): string;
165
+ /** Where a phone asks the host for a picture (the course cover): as the Content pack's. */
166
+ export declare function hostMediaUrl(hostUrl: string): (id: string, width: number) => string;
167
+ /** A picture on the site's own media route (`/api/media/<id>?w=`), for the web blocks. */
168
+ export declare function mediaPath(id: string, width?: number, base?: string): string;
169
+ /** A key from a title, unused in `taken`: `wrist-prep`, `wrist-prep-2`. */
170
+ export declare function newKey(title: string, taken: ReadonlySet<string>): string;
171
+ /**
172
+ * Pure edits of an outline: each returns a new outline and never changes a lesson's key once it
173
+ * has one (progress is kept by it). The builder block saves the result with `record.update`.
174
+ */
175
+ export declare const outlineEdits: {
176
+ addSection(outline: Outline, title: string): Outline;
177
+ renameSection(outline: Outline, key: string, title: string): Outline;
178
+ removeSection(outline: Outline, key: string): Outline;
179
+ addLesson(outline: Outline, section: string, kind: LessonKind, title: string): Outline;
180
+ /** Changes a lesson's fields; its key and kind stay. */
181
+ updateLesson(outline: Outline, key: string, patch: Record<string, unknown>): Outline;
182
+ removeLesson(outline: Outline, key: string): Outline;
183
+ /** Moves a lesson to `index` of `section` (by drag or by keyboard). */
184
+ moveLesson(outline: Outline, key: string, section: string, index: number): Outline;
185
+ };
186
+ /** The app's `useQuery`, as far as these hooks use it. */
187
+ export type UseQuery = <T>(options: {
188
+ queryKey: readonly unknown[];
189
+ queryFn: () => Promise<T>;
190
+ enabled?: boolean;
191
+ refetchInterval?: number | false | ((query: {
192
+ state: {
193
+ data: T | undefined;
194
+ };
195
+ }) => number | false);
196
+ }) => {
197
+ data: T | undefined;
198
+ isPending: boolean;
199
+ error: unknown;
200
+ };
201
+ /** What a query hook returns, as `UseQuery` gives it. */
202
+ export interface QueryResult<T> {
203
+ data: T | undefined;
204
+ isPending: boolean;
205
+ error: unknown;
206
+ }
207
+ type Out<N extends keyof CoursesOperations> = CoursesOperations[N]["output"];
208
+ /** The app's `useMutation`, as far as these hooks use it. */
209
+ export type UseMutation = <I, O>(options: {
210
+ mutationKey: readonly unknown[];
211
+ mutationFn: (input: I) => Promise<O>;
212
+ }) => {
213
+ mutate(input: I): void;
214
+ mutateAsync(input: I): Promise<O>;
215
+ data: O | undefined;
216
+ isPending: boolean;
217
+ error: unknown;
218
+ };
219
+ /**
220
+ * The operations each hook calls (ADR 0453). The public's client gets the catalogue, the course
221
+ * page and buying; a customer's client also their lessons, playback, progress and courses; the
222
+ * staff client the course builder's and the enrolment hooks too.
223
+ */
224
+ export declare const COURSES_HOOKS_CALL: {
225
+ readonly useCatalogue: readonly ["x.courses.catalogue"];
226
+ readonly useCourse: readonly ["x.courses.course"];
227
+ readonly useBuy: readonly ["x.courses.buy", "order.checkout"];
228
+ readonly useLesson: readonly ["x.courses.lesson"];
229
+ readonly usePlayback: readonly ["media.play"];
230
+ readonly useProgress: readonly ["x.courses.progress"];
231
+ readonly useMyCourses: readonly ["x.courses.myCourses"];
232
+ readonly useStartSession: readonly ["x.courses.startSession"];
233
+ readonly useEnrol: readonly ["x.courses.enrol"];
234
+ readonly useEndEnrolment: readonly ["x.courses.endEnrolment"];
235
+ readonly useStats: readonly ["x.courses.stats"];
236
+ readonly useWorkingCopy: readonly ["record.get"];
237
+ readonly useSaveOutline: readonly ["record.update"];
238
+ readonly usePublishCourse: readonly ["record.publish"];
239
+ readonly useLibraryVideos: readonly ["media.list"];
240
+ readonly usePublishedPrograms: readonly ["record.list"];
241
+ };
242
+ /**
243
+ * Hooks for a React or React Native app:
244
+ * `const courses = createCoursesHooks({ useQuery, useMutation }, api)`. The hooks a client cannot
245
+ * back are not there, and calling one does not compile.
246
+ */
247
+ export declare function createCoursesHooks<C extends ClientHolding>(react: {
248
+ useQuery: UseQuery;
249
+ useMutation: UseMutation;
250
+ }, client: C): import("@composable-os/client").HooksFor<{
251
+ /** The catalogue: published courses, bundles and themes, with the host's prices. */
252
+ useCatalogue(input?: In<"x.courses.catalogue">): {
253
+ data: {
254
+ themes: {
255
+ id: string;
256
+ name: string | null;
257
+ slug: string | null;
258
+ summary: string | null;
259
+ picture: {
260
+ [x: string]: unknown;
261
+ media: string;
262
+ alt?: string | undefined;
263
+ } | null;
264
+ }[];
265
+ courses: {
266
+ id: string;
267
+ title: string | null;
268
+ slug: string | null;
269
+ theme: string | null;
270
+ level: number | null;
271
+ summary: string | null;
272
+ cover: {
273
+ [x: string]: unknown;
274
+ media: string;
275
+ alt?: string | undefined;
276
+ } | null;
277
+ trailer: {
278
+ media: string;
279
+ poster?: string | undefined;
280
+ } | null;
281
+ price: number | null;
282
+ lessons: number;
283
+ }[];
284
+ bundles: {
285
+ id: string;
286
+ title: string | null;
287
+ slug: string | null;
288
+ summary: string | null;
289
+ cover: {
290
+ [x: string]: unknown;
291
+ media: string;
292
+ alt?: string | undefined;
293
+ } | null;
294
+ courses: string[];
295
+ price: number | null;
296
+ }[];
297
+ currency: string | null;
298
+ } | undefined;
299
+ isPending: boolean;
300
+ error: unknown;
301
+ };
302
+ /** One published course by its address, with whether the caller holds it. */
303
+ useCourse(slug: string | null): QueryResult<Out<"x.courses.course">>;
304
+ /** Start an order for a course or a bundle; then `checkout` it (web only). */
305
+ useBuy(): {
306
+ start: {
307
+ mutate(input: {
308
+ courseId?: string | undefined;
309
+ bundleId?: string | undefined;
310
+ email?: string | undefined;
311
+ }): void;
312
+ mutateAsync(input: {
313
+ courseId?: string | undefined;
314
+ bundleId?: string | undefined;
315
+ email?: string | undefined;
316
+ }): Promise<{
317
+ id: string;
318
+ state: string;
319
+ currency: string;
320
+ total: number;
321
+ token: string | null;
322
+ }>;
323
+ data: {
324
+ id: string;
325
+ state: string;
326
+ currency: string;
327
+ total: number;
328
+ token: string | null;
329
+ } | undefined;
330
+ isPending: boolean;
331
+ error: unknown;
332
+ };
333
+ checkout: {
334
+ mutate(input: {
335
+ id: string;
336
+ token?: string;
337
+ returnUrl: string;
338
+ }): void;
339
+ mutateAsync(input: {
340
+ id: string;
341
+ token?: string;
342
+ returnUrl: string;
343
+ }): Promise<{
344
+ url: string;
345
+ }>;
346
+ data: {
347
+ url: string;
348
+ } | undefined;
349
+ isPending: boolean;
350
+ error: unknown;
351
+ };
352
+ };
353
+ /** One lesson for a holder (or a free preview). */
354
+ useLesson(courseId: string | null, lessonKey: string | null): QueryResult<Out<"x.courses.lesson">>;
355
+ /**
356
+ * A token to play a lesson's video (or a trailer), from the host's `media.play`; asked for
357
+ * again `PLAYBACK_REFRESH_BEFORE_MS` before it expires, so a long video keeps playing.
358
+ */
359
+ usePlayback(video: {
360
+ media: string;
361
+ record?: {
362
+ object: string;
363
+ id: string;
364
+ };
365
+ field?: string;
366
+ } | null): QueryResult<Playback>;
367
+ /** Mark a lesson started or done, and keep where its video was left. */
368
+ useProgress(): {
369
+ mutate(input: {
370
+ courseId: string;
371
+ lessonKey: string;
372
+ state?: "done" | "started" | undefined;
373
+ position?: number | undefined;
374
+ duration?: number | undefined;
375
+ }): void;
376
+ mutateAsync(input: {
377
+ courseId: string;
378
+ lessonKey: string;
379
+ state?: "done" | "started" | undefined;
380
+ position?: number | undefined;
381
+ duration?: number | undefined;
382
+ }): Promise<{
383
+ lessonKey: string;
384
+ state: "done" | "started";
385
+ position: number | null;
386
+ done: number;
387
+ counted: number;
388
+ complete: boolean;
389
+ }>;
390
+ data: {
391
+ lessonKey: string;
392
+ state: "done" | "started";
393
+ position: number | null;
394
+ done: number;
395
+ counted: number;
396
+ complete: boolean;
397
+ } | undefined;
398
+ isPending: boolean;
399
+ error: unknown;
400
+ };
401
+ /** What the caller holds, with progress. */
402
+ useMyCourses(): {
403
+ data: {
404
+ courses: {
405
+ id: string;
406
+ title: string | null;
407
+ slug: string | null;
408
+ theme: string | null;
409
+ level: number | null;
410
+ summary: string | null;
411
+ cover: {
412
+ [x: string]: unknown;
413
+ media: string;
414
+ alt?: string | undefined;
415
+ } | null;
416
+ trailer: {
417
+ media: string;
418
+ poster?: string | undefined;
419
+ } | null;
420
+ price: number | null;
421
+ lessons: number;
422
+ why: "bought" | "bundle" | "given" | "imported";
423
+ done: number;
424
+ counted: number;
425
+ complete: boolean;
426
+ continueWith: string | null;
427
+ }[];
428
+ } | undefined;
429
+ isPending: boolean;
430
+ error: unknown;
431
+ };
432
+ /** A session lesson's own Programs session, once it is assigned. */
433
+ useStartSession(courseId: string | null, lessonKey: string | null): QueryResult<Out<"x.courses.startSession">>;
434
+ /** Staff: give a person access, with a reason. */
435
+ useEnrol(): {
436
+ mutate(input: {
437
+ personId: string;
438
+ reason: string;
439
+ courseId?: string | undefined;
440
+ bundleId?: string | undefined;
441
+ until?: string | undefined;
442
+ }): void;
443
+ mutateAsync(input: {
444
+ personId: string;
445
+ reason: string;
446
+ courseId?: string | undefined;
447
+ bundleId?: string | undefined;
448
+ until?: string | undefined;
449
+ }): Promise<{
450
+ enrolmentId: string;
451
+ status: string;
452
+ source: string;
453
+ }>;
454
+ data: {
455
+ enrolmentId: string;
456
+ status: string;
457
+ source: string;
458
+ } | undefined;
459
+ isPending: boolean;
460
+ error: unknown;
461
+ };
462
+ /** Staff: end an enrolment staff gave or one imported. */
463
+ useEndEnrolment(): {
464
+ mutate(input: {
465
+ enrolmentId: string;
466
+ reason: string;
467
+ }): void;
468
+ mutateAsync(input: {
469
+ enrolmentId: string;
470
+ reason: string;
471
+ }): Promise<{
472
+ enrolmentId: string;
473
+ status: string;
474
+ source: string;
475
+ }>;
476
+ data: {
477
+ enrolmentId: string;
478
+ status: string;
479
+ source: string;
480
+ } | undefined;
481
+ isPending: boolean;
482
+ error: unknown;
483
+ };
484
+ /** Staff: enrolments and lessons done. */
485
+ useStats(courseId?: string): {
486
+ data: {
487
+ courses: {
488
+ courseId: string;
489
+ title: string | null;
490
+ active: number;
491
+ ended: number;
492
+ void: number;
493
+ lessonsDone: number;
494
+ }[];
495
+ byWeek: {
496
+ week: string;
497
+ done: number;
498
+ }[];
499
+ } | undefined;
500
+ isPending: boolean;
501
+ error: unknown;
502
+ };
503
+ /** Staff: a course's working copy, as the builder edits it. */
504
+ useWorkingCopy(courseId: string): {
505
+ data: {
506
+ id: string;
507
+ values: Record<string, unknown>;
508
+ } | undefined;
509
+ isPending: boolean;
510
+ error: unknown;
511
+ };
512
+ /** Staff: save the course's working copy (its outline). */
513
+ useSaveOutline(): {
514
+ mutate(input: {
515
+ object: string;
516
+ id: string;
517
+ values: Record<string, unknown>;
518
+ }): void;
519
+ mutateAsync(input: {
520
+ object: string;
521
+ id: string;
522
+ values: Record<string, unknown>;
523
+ }): Promise<{
524
+ id: string;
525
+ values: Record<string, unknown>;
526
+ }>;
527
+ data: {
528
+ id: string;
529
+ values: Record<string, unknown>;
530
+ } | undefined;
531
+ isPending: boolean;
532
+ error: unknown;
533
+ };
534
+ /** Staff: publish the course (a person; an assistant's request waits for one). */
535
+ usePublishCourse(): {
536
+ mutate(input: {
537
+ object: string;
538
+ id: string;
539
+ note?: string;
540
+ }): void;
541
+ mutateAsync(input: {
542
+ object: string;
543
+ id: string;
544
+ note?: string;
545
+ }): Promise<{
546
+ version: number;
547
+ publishedAt: string;
548
+ }>;
549
+ data: {
550
+ version: number;
551
+ publishedAt: string;
552
+ } | undefined;
553
+ isPending: boolean;
554
+ error: unknown;
555
+ };
556
+ /** Staff: the library's ready videos, to pick a lesson's video. */
557
+ useLibraryVideos(): {
558
+ data: {
559
+ items: {
560
+ id: string;
561
+ values: Record<string, unknown>;
562
+ }[];
563
+ nextCursor: string | null;
564
+ } | undefined;
565
+ isPending: boolean;
566
+ error: unknown;
567
+ };
568
+ /** Staff: the published Programs programs, to pick a session lesson's program. */
569
+ usePublishedPrograms(): {
570
+ data: {
571
+ items: {
572
+ id: string;
573
+ title?: string | null;
574
+ values: Record<string, unknown>;
575
+ }[];
576
+ } | undefined;
577
+ isPending: boolean;
578
+ error: unknown;
579
+ };
580
+ }, {
581
+ readonly useCatalogue: readonly ["x.courses.catalogue"];
582
+ readonly useCourse: readonly ["x.courses.course"];
583
+ readonly useBuy: readonly ["x.courses.buy", "order.checkout"];
584
+ readonly useLesson: readonly ["x.courses.lesson"];
585
+ readonly usePlayback: readonly ["media.play"];
586
+ readonly useProgress: readonly ["x.courses.progress"];
587
+ readonly useMyCourses: readonly ["x.courses.myCourses"];
588
+ readonly useStartSession: readonly ["x.courses.startSession"];
589
+ readonly useEnrol: readonly ["x.courses.enrol"];
590
+ readonly useEndEnrolment: readonly ["x.courses.endEnrolment"];
591
+ readonly useStats: readonly ["x.courses.stats"];
592
+ readonly useWorkingCopy: readonly ["record.get"];
593
+ readonly useSaveOutline: readonly ["record.update"];
594
+ readonly usePublishCourse: readonly ["record.publish"];
595
+ readonly useLibraryVideos: readonly ["media.list"];
596
+ readonly usePublishedPrograms: readonly ["record.list"];
597
+ }, import("@composable-os/client").OperationsOf<C>>;
598
+ declare function allCoursesHooks(react: {
599
+ useQuery: UseQuery;
600
+ useMutation: UseMutation;
601
+ }, api: CoursesClient): {
602
+ /** The catalogue: published courses, bundles and themes, with the host's prices. */
603
+ useCatalogue(input?: In<"x.courses.catalogue">): {
604
+ data: {
605
+ themes: {
606
+ id: string;
607
+ name: string | null;
608
+ slug: string | null;
609
+ summary: string | null;
610
+ picture: {
611
+ [x: string]: unknown;
612
+ media: string;
613
+ alt?: string | undefined;
614
+ } | null;
615
+ }[];
616
+ courses: {
617
+ id: string;
618
+ title: string | null;
619
+ slug: string | null;
620
+ theme: string | null;
621
+ level: number | null;
622
+ summary: string | null;
623
+ cover: {
624
+ [x: string]: unknown;
625
+ media: string;
626
+ alt?: string | undefined;
627
+ } | null;
628
+ trailer: {
629
+ media: string;
630
+ poster?: string | undefined;
631
+ } | null;
632
+ price: number | null;
633
+ lessons: number;
634
+ }[];
635
+ bundles: {
636
+ id: string;
637
+ title: string | null;
638
+ slug: string | null;
639
+ summary: string | null;
640
+ cover: {
641
+ [x: string]: unknown;
642
+ media: string;
643
+ alt?: string | undefined;
644
+ } | null;
645
+ courses: string[];
646
+ price: number | null;
647
+ }[];
648
+ currency: string | null;
649
+ } | undefined;
650
+ isPending: boolean;
651
+ error: unknown;
652
+ };
653
+ /** One published course by its address, with whether the caller holds it. */
654
+ useCourse(slug: string | null): QueryResult<Out<"x.courses.course">>;
655
+ /** Start an order for a course or a bundle; then `checkout` it (web only). */
656
+ useBuy(): {
657
+ start: {
658
+ mutate(input: {
659
+ courseId?: string | undefined;
660
+ bundleId?: string | undefined;
661
+ email?: string | undefined;
662
+ }): void;
663
+ mutateAsync(input: {
664
+ courseId?: string | undefined;
665
+ bundleId?: string | undefined;
666
+ email?: string | undefined;
667
+ }): Promise<{
668
+ id: string;
669
+ state: string;
670
+ currency: string;
671
+ total: number;
672
+ token: string | null;
673
+ }>;
674
+ data: {
675
+ id: string;
676
+ state: string;
677
+ currency: string;
678
+ total: number;
679
+ token: string | null;
680
+ } | undefined;
681
+ isPending: boolean;
682
+ error: unknown;
683
+ };
684
+ checkout: {
685
+ mutate(input: {
686
+ id: string;
687
+ token?: string;
688
+ returnUrl: string;
689
+ }): void;
690
+ mutateAsync(input: {
691
+ id: string;
692
+ token?: string;
693
+ returnUrl: string;
694
+ }): Promise<{
695
+ url: string;
696
+ }>;
697
+ data: {
698
+ url: string;
699
+ } | undefined;
700
+ isPending: boolean;
701
+ error: unknown;
702
+ };
703
+ };
704
+ /** One lesson for a holder (or a free preview). */
705
+ useLesson(courseId: string | null, lessonKey: string | null): QueryResult<Out<"x.courses.lesson">>;
706
+ /**
707
+ * A token to play a lesson's video (or a trailer), from the host's `media.play`; asked for
708
+ * again `PLAYBACK_REFRESH_BEFORE_MS` before it expires, so a long video keeps playing.
709
+ */
710
+ usePlayback(video: {
711
+ media: string;
712
+ record?: {
713
+ object: string;
714
+ id: string;
715
+ };
716
+ field?: string;
717
+ } | null): QueryResult<Playback>;
718
+ /** Mark a lesson started or done, and keep where its video was left. */
719
+ useProgress(): {
720
+ mutate(input: {
721
+ courseId: string;
722
+ lessonKey: string;
723
+ state?: "done" | "started" | undefined;
724
+ position?: number | undefined;
725
+ duration?: number | undefined;
726
+ }): void;
727
+ mutateAsync(input: {
728
+ courseId: string;
729
+ lessonKey: string;
730
+ state?: "done" | "started" | undefined;
731
+ position?: number | undefined;
732
+ duration?: number | undefined;
733
+ }): Promise<{
734
+ lessonKey: string;
735
+ state: "done" | "started";
736
+ position: number | null;
737
+ done: number;
738
+ counted: number;
739
+ complete: boolean;
740
+ }>;
741
+ data: {
742
+ lessonKey: string;
743
+ state: "done" | "started";
744
+ position: number | null;
745
+ done: number;
746
+ counted: number;
747
+ complete: boolean;
748
+ } | undefined;
749
+ isPending: boolean;
750
+ error: unknown;
751
+ };
752
+ /** What the caller holds, with progress. */
753
+ useMyCourses(): {
754
+ data: {
755
+ courses: {
756
+ id: string;
757
+ title: string | null;
758
+ slug: string | null;
759
+ theme: string | null;
760
+ level: number | null;
761
+ summary: string | null;
762
+ cover: {
763
+ [x: string]: unknown;
764
+ media: string;
765
+ alt?: string | undefined;
766
+ } | null;
767
+ trailer: {
768
+ media: string;
769
+ poster?: string | undefined;
770
+ } | null;
771
+ price: number | null;
772
+ lessons: number;
773
+ why: "bought" | "bundle" | "given" | "imported";
774
+ done: number;
775
+ counted: number;
776
+ complete: boolean;
777
+ continueWith: string | null;
778
+ }[];
779
+ } | undefined;
780
+ isPending: boolean;
781
+ error: unknown;
782
+ };
783
+ /** A session lesson's own Programs session, once it is assigned. */
784
+ useStartSession(courseId: string | null, lessonKey: string | null): QueryResult<Out<"x.courses.startSession">>;
785
+ /** Staff: give a person access, with a reason. */
786
+ useEnrol(): {
787
+ mutate(input: {
788
+ personId: string;
789
+ reason: string;
790
+ courseId?: string | undefined;
791
+ bundleId?: string | undefined;
792
+ until?: string | undefined;
793
+ }): void;
794
+ mutateAsync(input: {
795
+ personId: string;
796
+ reason: string;
797
+ courseId?: string | undefined;
798
+ bundleId?: string | undefined;
799
+ until?: string | undefined;
800
+ }): Promise<{
801
+ enrolmentId: string;
802
+ status: string;
803
+ source: string;
804
+ }>;
805
+ data: {
806
+ enrolmentId: string;
807
+ status: string;
808
+ source: string;
809
+ } | undefined;
810
+ isPending: boolean;
811
+ error: unknown;
812
+ };
813
+ /** Staff: end an enrolment staff gave or one imported. */
814
+ useEndEnrolment(): {
815
+ mutate(input: {
816
+ enrolmentId: string;
817
+ reason: string;
818
+ }): void;
819
+ mutateAsync(input: {
820
+ enrolmentId: string;
821
+ reason: string;
822
+ }): Promise<{
823
+ enrolmentId: string;
824
+ status: string;
825
+ source: string;
826
+ }>;
827
+ data: {
828
+ enrolmentId: string;
829
+ status: string;
830
+ source: string;
831
+ } | undefined;
832
+ isPending: boolean;
833
+ error: unknown;
834
+ };
835
+ /** Staff: enrolments and lessons done. */
836
+ useStats(courseId?: string): {
837
+ data: {
838
+ courses: {
839
+ courseId: string;
840
+ title: string | null;
841
+ active: number;
842
+ ended: number;
843
+ void: number;
844
+ lessonsDone: number;
845
+ }[];
846
+ byWeek: {
847
+ week: string;
848
+ done: number;
849
+ }[];
850
+ } | undefined;
851
+ isPending: boolean;
852
+ error: unknown;
853
+ };
854
+ /** Staff: a course's working copy, as the builder edits it. */
855
+ useWorkingCopy(courseId: string): {
856
+ data: {
857
+ id: string;
858
+ values: Record<string, unknown>;
859
+ } | undefined;
860
+ isPending: boolean;
861
+ error: unknown;
862
+ };
863
+ /** Staff: save the course's working copy (its outline). */
864
+ useSaveOutline(): {
865
+ mutate(input: {
866
+ object: string;
867
+ id: string;
868
+ values: Record<string, unknown>;
869
+ }): void;
870
+ mutateAsync(input: {
871
+ object: string;
872
+ id: string;
873
+ values: Record<string, unknown>;
874
+ }): Promise<{
875
+ id: string;
876
+ values: Record<string, unknown>;
877
+ }>;
878
+ data: {
879
+ id: string;
880
+ values: Record<string, unknown>;
881
+ } | undefined;
882
+ isPending: boolean;
883
+ error: unknown;
884
+ };
885
+ /** Staff: publish the course (a person; an assistant's request waits for one). */
886
+ usePublishCourse(): {
887
+ mutate(input: {
888
+ object: string;
889
+ id: string;
890
+ note?: string;
891
+ }): void;
892
+ mutateAsync(input: {
893
+ object: string;
894
+ id: string;
895
+ note?: string;
896
+ }): Promise<{
897
+ version: number;
898
+ publishedAt: string;
899
+ }>;
900
+ data: {
901
+ version: number;
902
+ publishedAt: string;
903
+ } | undefined;
904
+ isPending: boolean;
905
+ error: unknown;
906
+ };
907
+ /** Staff: the library's ready videos, to pick a lesson's video. */
908
+ useLibraryVideos(): {
909
+ data: {
910
+ items: {
911
+ id: string;
912
+ values: Record<string, unknown>;
913
+ }[];
914
+ nextCursor: string | null;
915
+ } | undefined;
916
+ isPending: boolean;
917
+ error: unknown;
918
+ };
919
+ /** Staff: the published Programs programs, to pick a session lesson's program. */
920
+ usePublishedPrograms(): {
921
+ data: {
922
+ items: {
923
+ id: string;
924
+ title?: string | null;
925
+ values: Record<string, unknown>;
926
+ }[];
927
+ } | undefined;
928
+ isPending: boolean;
929
+ error: unknown;
930
+ };
931
+ };
932
+ /** Every hook of this entry. A block takes the ones it calls: `Pick<CoursesHooks, "useLesson">`. */
933
+ export type CoursesHooks = ReturnType<typeof allCoursesHooks>;