coursekit-lms 0.0.0-stage → 0.1.1

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 (105) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/LICENSE +21 -0
  3. package/README.md +258 -2
  4. package/dist/cli/index.js +5170 -0
  5. package/dist/cli/index.js.map +1 -0
  6. package/dist/server/index.js +4944 -0
  7. package/dist/server/index.js.map +1 -0
  8. package/dist/types/server/app.d.ts +4 -0
  9. package/dist/types/server/auth/session.d.ts +18 -0
  10. package/dist/types/server/config.d.ts +31 -0
  11. package/dist/types/server/context.d.ts +24 -0
  12. package/dist/types/server/db/index.d.ts +11 -0
  13. package/dist/types/server/db/migrations/001_initial.d.ts +7 -0
  14. package/dist/types/server/db/node-sqlite.d.ts +6 -0
  15. package/dist/types/server/db/schema.d.ts +253 -0
  16. package/dist/types/server/db/types.d.ts +4 -0
  17. package/dist/types/server/index.d.ts +64 -0
  18. package/dist/types/server/lib/events.d.ts +86 -0
  19. package/dist/types/server/lib/http.d.ts +21 -0
  20. package/dist/types/server/lib/password.d.ts +3 -0
  21. package/dist/types/server/lib/schemas.d.ts +23 -0
  22. package/dist/types/server/lib/storage.d.ts +10 -0
  23. package/dist/types/server/lib/util.d.ts +18 -0
  24. package/dist/types/server/paths.d.ts +10 -0
  25. package/dist/types/server/routes/activities.d.ts +3 -0
  26. package/dist/types/server/routes/admin.d.ts +3 -0
  27. package/dist/types/server/routes/auth.d.ts +3 -0
  28. package/dist/types/server/routes/categories.d.ts +3 -0
  29. package/dist/types/server/routes/content.d.ts +4 -0
  30. package/dist/types/server/routes/courses.d.ts +5 -0
  31. package/dist/types/server/routes/files.d.ts +3 -0
  32. package/dist/types/server/routes/forums.d.ts +3 -0
  33. package/dist/types/server/routes/grades.d.ts +3 -0
  34. package/dist/types/server/routes/me.d.ts +3 -0
  35. package/dist/types/server/routes/quizzes.d.ts +3 -0
  36. package/dist/types/server/seed/demo.d.ts +19 -0
  37. package/dist/types/server/services/access.d.ts +24 -0
  38. package/dist/types/server/services/activity-types.d.ts +20 -0
  39. package/dist/types/server/services/courses.d.ts +7 -0
  40. package/dist/types/server/services/grades.d.ts +11 -0
  41. package/dist/types/server/services/notify.d.ts +10 -0
  42. package/dist/types/server/services/progress.d.ts +9 -0
  43. package/dist/types/server/services/quiz.d.ts +28 -0
  44. package/dist/types/server/services/serialize.d.ts +13 -0
  45. package/dist/types/server/services/settings.d.ts +5 -0
  46. package/dist/types/server/services/users.d.ts +15 -0
  47. package/dist/types/shared/constants.d.ts +11 -0
  48. package/dist/types/shared/permissions.d.ts +13 -0
  49. package/dist/types/shared/types.d.ts +452 -0
  50. package/dist/web/assets/ActivityEditor-BVSZUV8l.js +3 -0
  51. package/dist/web/assets/ActivityPage-DPmSV_mU.js +1 -0
  52. package/dist/web/assets/AdminCoursesPage-uaSHNtzf.js +1 -0
  53. package/dist/web/assets/AdminLayout-DqoShZGn.js +1 -0
  54. package/dist/web/assets/AdminOverviewPage-DnTrdGbr.js +1 -0
  55. package/dist/web/assets/AdminSettingsPage-B82cX8xU.js +1 -0
  56. package/dist/web/assets/AdminUsersPage-3d2F9AEl.js +1 -0
  57. package/dist/web/assets/AnnouncementsPage-BKW30k0Z.js +1 -0
  58. package/dist/web/assets/CalendarPage-CLRWyTNT.js +1 -0
  59. package/dist/web/assets/CatalogPage-BiMgSSBR.js +1 -0
  60. package/dist/web/assets/CourseContentPage-BIDH0UbG.js +1 -0
  61. package/dist/web/assets/CourseLayout-ql01LEmj.js +1 -0
  62. package/dist/web/assets/CourseSettingsPage-CReoPqOa.js +1 -0
  63. package/dist/web/assets/CreateCoursePage-DFCHlq5M.js +1 -0
  64. package/dist/web/assets/DiscussionPage-CWwVpFQV.js +1 -0
  65. package/dist/web/assets/GradesPage-Bu5vphcG.js +1 -0
  66. package/dist/web/assets/MyCoursesPage-Dd-Oaygv.js +1 -0
  67. package/dist/web/assets/NotFoundPage-BRquC7-l.js +1 -0
  68. package/dist/web/assets/NotificationsPage-LJvqb6Dj.js +1 -0
  69. package/dist/web/assets/ParticipantsPage-wFxiphna.js +1 -0
  70. package/dist/web/assets/ProfilePage-CzfhacAX.js +1 -0
  71. package/dist/web/assets/QuizAttemptPage-CEAV6wAL.js +1 -0
  72. package/dist/web/assets/QuizEditorPage-DS_czQVM.js +3 -0
  73. package/dist/web/assets/SubmissionsPage-CQjcx09G.js +1 -0
  74. package/dist/web/assets/arrow-up-LHDup5m4.js +1 -0
  75. package/dist/web/assets/ban-D3Vsxg_g.js +1 -0
  76. package/dist/web/assets/chevron-left-D6IMQD6N.js +1 -0
  77. package/dist/web/assets/constants-DLDWTvvN.js +1 -0
  78. package/dist/web/assets/context-BLVW7NB7.js +1 -0
  79. package/dist/web/assets/copy-Bxxjq6zo.js +1 -0
  80. package/dist/web/assets/ellipsis-c2POIN-Y.js +1 -0
  81. package/dist/web/assets/frame-CGabirLa.js +1 -0
  82. package/dist/web/assets/hooks-BBARn-DA.js +1 -0
  83. package/dist/web/assets/index-B29bTBiJ.js +50 -0
  84. package/dist/web/assets/index-WxCvsbJq.css +2 -0
  85. package/dist/web/assets/inter-cyrillic-ext-wght-normal-BOeWTOD4.woff2 +0 -0
  86. package/dist/web/assets/inter-cyrillic-wght-normal-DqGufNeO.woff2 +0 -0
  87. package/dist/web/assets/inter-greek-ext-wght-normal-DlzME5K_.woff2 +0 -0
  88. package/dist/web/assets/inter-greek-wght-normal-CkhJZR-_.woff2 +0 -0
  89. package/dist/web/assets/inter-latin-ext-wght-normal-DO1Apj_S.woff2 +0 -0
  90. package/dist/web/assets/inter-latin-wght-normal-Dx4kXJAl.woff2 +0 -0
  91. package/dist/web/assets/inter-vietnamese-wght-normal-CBcvBZtf.woff2 +0 -0
  92. package/dist/web/assets/key-round-B_KI-brR.js +1 -0
  93. package/dist/web/assets/library-3WG9oLCb.js +1 -0
  94. package/dist/web/assets/lock-BjbqwA_0.js +1 -0
  95. package/dist/web/assets/markdown-ykrkPMbn.js +83 -0
  96. package/dist/web/assets/message-square-text-fe24gbEU.js +1 -0
  97. package/dist/web/assets/misc-DvgDEI3I.js +1 -0
  98. package/dist/web/assets/pencil-p0GQmIMo.js +1 -0
  99. package/dist/web/assets/pin-DlYC3uec.js +1 -0
  100. package/dist/web/assets/send-mxSHcdcD.js +1 -0
  101. package/dist/web/assets/settings-DRKWzSHN.js +1 -0
  102. package/dist/web/assets/trophy-Cch2iF1m.js +1 -0
  103. package/dist/web/favicon.svg +12 -0
  104. package/dist/web/index.html +26 -0
  105. package/package.json +108 -4
@@ -0,0 +1,3 @@
1
+ import { Hono } from 'hono';
2
+ import { type AppDeps, type AppEnv } from '../context.js';
3
+ export declare function quizRoutes(deps: AppDeps): Hono<AppEnv, import("hono/types").BlankSchema, "/">;
@@ -0,0 +1,19 @@
1
+ import type { AppDeps } from '../context.js';
2
+ import type { UserRow } from '../db/schema.js';
3
+ export interface SeedDemoOptions {
4
+ /** An existing administrator for the demo. If omitted, the first admin is used (or one is created). */
5
+ admin?: Pick<UserRow, 'id'> | undefined;
6
+ /** Password for all demo accounts. Defaults to a random one (admins can still use "Log in as"). */
7
+ password?: string | undefined;
8
+ }
9
+ export interface SeedDemoResult {
10
+ created: boolean;
11
+ password: string | null;
12
+ users: Array<{
13
+ name: string;
14
+ email: string;
15
+ role: string;
16
+ }>;
17
+ courses: number;
18
+ }
19
+ export declare function seedDemo(deps: Pick<AppDeps, 'db' | 'events'>, options?: SeedDemoOptions): Promise<SeedDemoResult>;
@@ -0,0 +1,24 @@
1
+ import { type CourseCapability } from '../../shared/permissions.js';
2
+ import type { CourseRole } from '../../shared/types.js';
3
+ import type { DB } from '../db/types.js';
4
+ import type { ActivityRow, CourseRow, EnrolmentRow, UserRow } from '../db/schema.js';
5
+ export interface CourseAccess {
6
+ course: CourseRow;
7
+ user: UserRow;
8
+ /** The user's active enrolment, if any. */
9
+ enrolment: EnrolmentRow | null;
10
+ role: CourseRole | null;
11
+ capabilities: CourseCapability[];
12
+ /** Archived courses are read-only for everyone except course managers. */
13
+ readOnly: boolean;
14
+ can(cap: CourseCapability): boolean;
15
+ }
16
+ export interface ActivityAccess extends CourseAccess {
17
+ activity: ActivityRow;
18
+ }
19
+ export declare function findCourse(db: DB, idOrSlug: string): Promise<CourseRow | undefined>;
20
+ export declare function loadCourseAccess(db: DB, user: UserRow, idOrSlug: string): Promise<CourseAccess>;
21
+ export declare function assertCan(access: CourseAccess, cap: CourseCapability, message?: string): void;
22
+ export declare function assertWritable(access: CourseAccess): void;
23
+ /** Loads an activity and checks that the user may view it (enrolled, and visible unless they can see hidden items). */
24
+ export declare function loadActivityAccess(db: DB, user: UserRow, activityId: string): Promise<ActivityAccess>;
@@ -0,0 +1,20 @@
1
+ import { z } from 'zod';
2
+ import type { ActivitySettingsMap, ActivityType, CompletionMode } from '../../shared/types.js';
3
+ /**
4
+ * Activity types and how their settings are validated. Built-in types are registered here;
5
+ * this is also the extension point for custom activity plugins.
6
+ */
7
+ export interface ActivityTypeDefinition<T extends ActivityType = ActivityType> {
8
+ type: T;
9
+ /** Activities of this type appear in the gradebook. */
10
+ graded: boolean;
11
+ defaultCompletion: CompletionMode;
12
+ /** Completion modes that make sense for this type. */
13
+ completionModes: CompletionMode[];
14
+ settings: z.ZodType<ActivitySettingsMap[T]>;
15
+ }
16
+ export declare const activityTypes: {
17
+ [K in ActivityType]: ActivityTypeDefinition<K>;
18
+ };
19
+ export declare function isActivityType(value: string): value is ActivityType;
20
+ export declare function parseSettings<T extends ActivityType>(type: T, raw: string): ActivitySettingsMap[T];
@@ -0,0 +1,7 @@
1
+ import type { CourseSummary } from '../../shared/types.js';
2
+ import type { DB } from '../db/types.js';
3
+ import type { CourseRow, UserRow } from '../db/schema.js';
4
+ /** Builds catalog/dashboard cards for a list of courses, as seen by `user`. */
5
+ export declare function summarizeCourses(db: DB, user: UserRow | null, courses: CourseRow[]): Promise<CourseSummary[]>;
6
+ /** Returns `base`, or `base-2`, `base-3`, ... if it is taken. */
7
+ export declare function uniqueCourseSlug(db: DB, base: string, exceptId?: string): Promise<string>;
@@ -0,0 +1,11 @@
1
+ import type { AppDeps } from '../context.js';
2
+ export interface GradeInput {
3
+ activityId: string;
4
+ courseId: string;
5
+ userId: string;
6
+ score: number | null;
7
+ /** Leave undefined to keep existing feedback. */
8
+ feedback?: string | null;
9
+ gradedBy: string | null;
10
+ }
11
+ export declare function upsertGrade(deps: Pick<AppDeps, 'db' | 'events'>, input: GradeInput): Promise<void>;
@@ -0,0 +1,10 @@
1
+ import type { DB } from '../db/types.js';
2
+ export interface NotificationInput {
3
+ type: string;
4
+ title: string;
5
+ body?: string;
6
+ link?: string | null;
7
+ }
8
+ /** Sends an in-app notification to each user (deduplicated). */
9
+ export declare function notify(db: DB, userIds: Iterable<string>, input: NotificationInput): Promise<void>;
10
+ export declare function courseMemberIds(db: DB, courseId: string, roles?: string[]): Promise<string[]>;
@@ -0,0 +1,9 @@
1
+ import type { AppDeps } from '../context.js';
2
+ import type { DB } from '../db/types.js';
3
+ import type { ActivityRow } from '../db/schema.js';
4
+ /** Progress (0-100) of one user in several courses. */
5
+ export declare function progressByCourse(db: DB, userId: string, courseIds: string[]): Promise<Map<string, number>>;
6
+ /** Progress (0-100) of several users in one course. */
7
+ export declare function progressByUser(db: DB, courseId: string, userIds: string[]): Promise<Map<string, number>>;
8
+ export declare function markCompleted(deps: Pick<AppDeps, 'db' | 'events'>, activity: ActivityRow, userId: string): Promise<void>;
9
+ export declare function unmarkCompleted(db: DB, activityId: string, userId: string): Promise<void>;
@@ -0,0 +1,28 @@
1
+ import type { AttemptAnswer, Question, QuestionResult, QuizAttempt, QuizSettings } from '../../shared/types.js';
2
+ import type { AppDeps } from '../context.js';
3
+ import type { DB } from '../db/types.js';
4
+ import type { ActivityRow, CourseRow, QuestionRow, QuizAttemptRow } from '../db/schema.js';
5
+ export interface StoredOption {
6
+ id: string;
7
+ text: string;
8
+ correct: boolean;
9
+ }
10
+ /** Answers saved within this window after the deadline are still accepted (network latency). */
11
+ export declare const ATTEMPT_GRACE_MS = 30000;
12
+ export declare function normalizeText(value: string): string;
13
+ export declare function gradeQuestion(q: QuestionRow, answer: AttemptAnswer | undefined): QuestionResult;
14
+ /** Question as an editor sees it, including correct answers. */
15
+ export declare function questionWithAnswers(q: QuestionRow): Question;
16
+ /** Question as a student sees it during an attempt: no answers. */
17
+ export declare function questionForStudent(q: QuestionRow): Question;
18
+ export declare function loadQuestions(db: DB, activityId: string): Promise<QuestionRow[]>;
19
+ export declare function isExpired(attempt: QuizAttemptRow): boolean;
20
+ /** Full review (correct answers and explanations) is allowed for this viewer. */
21
+ export declare function canReview(settings: QuizSettings, activity: ActivityRow, isManager: boolean): boolean;
22
+ export declare function startAttempt(deps: Pick<AppDeps, 'db' | 'events'>, activity: ActivityRow, userId: string, options: {
23
+ isManager: boolean;
24
+ }): Promise<QuizAttemptRow>;
25
+ export declare function finishAttempt(deps: Pick<AppDeps, 'db' | 'events'>, attempt: QuizAttemptRow, activity: ActivityRow, answers?: Record<string, AttemptAnswer>): Promise<QuizAttemptRow>;
26
+ /** Recomputes a student's quiz grade from their finished attempts using the quiz's grading method. */
27
+ export declare function updateQuizGrade(deps: Pick<AppDeps, 'db' | 'events'>, activity: ActivityRow, userId: string): Promise<void>;
28
+ export declare function toAttemptDto(attempt: QuizAttemptRow, activity: ActivityRow, course: CourseRow, questionRows: QuestionRow[], review: boolean): QuizAttempt;
@@ -0,0 +1,13 @@
1
+ import type { CourseRef, FileInfo, PublicUser, User } from '../../shared/types.js';
2
+ import type { CourseRow, FileRow, UserRow } from '../db/schema.js';
3
+ export declare function toPublicUser(u: Pick<UserRow, 'id' | 'name' | 'avatarUrl'>): PublicUser;
4
+ export declare function toUser(u: UserRow): User;
5
+ export declare function toCourseRef(c: Pick<CourseRow, 'id' | 'slug' | 'title' | 'coverColor'>): CourseRef;
6
+ export declare function fileUrl(id: string): string;
7
+ export declare function toFileInfo(f: FileRow): FileInfo;
8
+ /** Shorthand used by routes that select user columns under aliased names. */
9
+ export declare function userFrom(row: {
10
+ userId: string;
11
+ userName: string;
12
+ userAvatarUrl: string | null;
13
+ }): PublicUser;
@@ -0,0 +1,5 @@
1
+ import type { SiteSettings } from '../../shared/types.js';
2
+ import type { DB } from '../db/types.js';
3
+ export declare const DEFAULT_SITE_SETTINGS: SiteSettings;
4
+ export declare function getSiteSettings(db: DB): Promise<SiteSettings>;
5
+ export declare function updateSiteSettings(db: DB, patch: Partial<SiteSettings>): Promise<SiteSettings>;
@@ -0,0 +1,15 @@
1
+ import type { SiteRole } from '../../shared/types.js';
2
+ import type { AppDeps } from '../context.js';
3
+ import type { UserRow } from '../db/schema.js';
4
+ export interface CreateUserInput {
5
+ name: string;
6
+ email: string;
7
+ password?: string | null | undefined;
8
+ /** Pre-computed hash, e.g. when seeding many users with the same password. */
9
+ passwordHash?: string | null | undefined;
10
+ role?: SiteRole | undefined;
11
+ bio?: string | null | undefined;
12
+ avatarUrl?: string | null | undefined;
13
+ }
14
+ export declare function normalizeEmail(email: string): string;
15
+ export declare function createUser(deps: Pick<AppDeps, 'db' | 'events'>, input: CreateUserInput): Promise<UserRow>;
@@ -0,0 +1,11 @@
1
+ import type { ActivitySettingsMap, ActivityType, CompletionMode } from './types.js';
2
+ /** Gradient presets for course covers. The UI maps each key to a gradient. */
3
+ export declare const COVER_COLORS: readonly ['indigo', 'ocean', 'emerald', 'sunset', 'rose', 'amber', 'teal', 'fuchsia', 'lime', 'slate'];
4
+ export type CoverColor = (typeof COVER_COLORS)[number];
5
+ export declare const ACTIVITY_TYPES: readonly ActivityType[];
6
+ export declare const ACTIVITY_LABELS: Record<ActivityType, string>;
7
+ export declare const ACTIVITY_DESCRIPTIONS: Record<ActivityType, string>;
8
+ export declare const GRADED_ACTIVITY_TYPES: readonly ActivityType[];
9
+ export declare const DEFAULT_COMPLETION: Record<ActivityType, CompletionMode>;
10
+ export declare const DEFAULT_SETTINGS: ActivitySettingsMap;
11
+ export declare const DEFAULT_BRAND_COLOR = "#4f46e5";
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Role-based capabilities, in the spirit of Moodle's capability system.
3
+ * The server enforces these; the UI uses the same table to decide what to show.
4
+ */
5
+ import type { CourseRole, SiteRole } from './types.js';
6
+ export declare const COURSE_CAPABILITIES: readonly ['course:view', 'course:viewHidden', 'course:update', 'course:delete', 'course:manageContent', 'course:viewParticipants', 'course:manageParticipants', 'grades:viewAll', 'grades:edit', 'assignment:submit', 'quiz:attempt', 'quiz:viewAllAttempts', 'forum:post', 'forum:moderate', 'announcement:post'];
7
+ export type CourseCapability = (typeof COURSE_CAPABILITIES)[number];
8
+ export declare const ROLE_CAPABILITIES: Record<CourseRole, readonly CourseCapability[]>;
9
+ /** Capabilities a user has in a course, given their site role and (optional) course role. */
10
+ export declare function getCourseCapabilities(siteRole: SiteRole | null, courseRole: CourseRole | null): CourseCapability[];
11
+ export declare function canCreateCourses(role: SiteRole | null | undefined): boolean;
12
+ export declare const SITE_ROLE_LABELS: Record<SiteRole, string>;
13
+ export declare const COURSE_ROLE_LABELS: Record<CourseRole, string>;
@@ -0,0 +1,452 @@
1
+ /**
2
+ * Data shapes returned by the Coursekit REST API. Shared by the server and the web UI.
3
+ */
4
+ import type { CourseCapability } from './permissions.js';
5
+ export type SiteRole = 'admin' | 'instructor' | 'student';
6
+ export type CourseRole = 'teacher' | 'assistant' | 'student';
7
+ export type UserStatus = 'active' | 'suspended';
8
+ export type CourseVisibility = 'draft' | 'published' | 'archived';
9
+ export type EnrolmentMethod = 'open' | 'key' | 'invite';
10
+ export type ActivityType = 'lesson' | 'resource' | 'assignment' | 'quiz' | 'forum';
11
+ export type CompletionMode = 'none' | 'manual' | 'auto';
12
+ export type QuestionType = 'single' | 'multiple' | 'truefalse' | 'short' | 'numeric';
13
+ export interface PublicUser {
14
+ id: string;
15
+ name: string;
16
+ avatarUrl: string | null;
17
+ }
18
+ export interface User extends PublicUser {
19
+ email: string;
20
+ role: SiteRole;
21
+ bio: string | null;
22
+ status: UserStatus;
23
+ createdAt: string;
24
+ lastLoginAt: string | null;
25
+ }
26
+ export interface SiteSettings {
27
+ name: string;
28
+ tagline: string;
29
+ brandColor: string;
30
+ allowSignup: boolean;
31
+ welcomeMessage: string;
32
+ }
33
+ export interface SessionInfo {
34
+ user: User | null;
35
+ impersonator: PublicUser | null;
36
+ site: SiteSettings;
37
+ needsSetup: boolean;
38
+ version: string;
39
+ }
40
+ export interface Category {
41
+ id: string;
42
+ name: string;
43
+ slug: string;
44
+ description: string;
45
+ sortOrder: number;
46
+ courseCount: number;
47
+ }
48
+ export interface CourseRef {
49
+ id: string;
50
+ slug: string;
51
+ title: string;
52
+ coverColor: string;
53
+ }
54
+ export interface CourseSummary extends CourseRef {
55
+ summary: string;
56
+ categoryId: string | null;
57
+ categoryName: string | null;
58
+ coverImageUrl: string | null;
59
+ visibility: CourseVisibility;
60
+ enrolment: EnrolmentMethod;
61
+ startDate: string | null;
62
+ endDate: string | null;
63
+ teachers: PublicUser[];
64
+ studentCount: number;
65
+ activityCount: number;
66
+ myRole: CourseRole | null;
67
+ /** 0-100 for enrolled students, null otherwise. */
68
+ progress: number | null;
69
+ lastAccessAt: string | null;
70
+ }
71
+ export interface CourseDetail extends CourseSummary {
72
+ description: string;
73
+ capabilities: CourseCapability[];
74
+ sections: Section[];
75
+ hasEnrolmentKey: boolean;
76
+ /** Only returned to people who can update the course. */
77
+ enrolmentKey: string | null;
78
+ canEnrol: boolean;
79
+ /** True when the viewer can only see the outline (not enrolled). */
80
+ outlineOnly: boolean;
81
+ }
82
+ export interface Section {
83
+ id: string;
84
+ title: string;
85
+ summary: string;
86
+ position: number;
87
+ visible: boolean;
88
+ activities: ActivitySummary[];
89
+ }
90
+ export interface ActivitySummary {
91
+ id: string;
92
+ courseId: string;
93
+ sectionId: string;
94
+ type: ActivityType;
95
+ title: string;
96
+ visible: boolean;
97
+ position: number;
98
+ dueAt: string | null;
99
+ maxGrade: number | null;
100
+ completion: CompletionMode;
101
+ completed: boolean;
102
+ /** Short subtitle, e.g. "12 min read" or "8 questions". */
103
+ meta: string | null;
104
+ }
105
+ export interface LessonSettings {
106
+ body: string;
107
+ videoUrl: string | null;
108
+ estimatedMinutes: number | null;
109
+ }
110
+ export interface ResourceSettings {
111
+ kind: 'file' | 'link';
112
+ fileId: string | null;
113
+ url: string | null;
114
+ }
115
+ export interface AssignmentSettings {
116
+ submissionTypes: Array<'text' | 'file'>;
117
+ allowLate: boolean;
118
+ maxFiles: number;
119
+ }
120
+ export interface QuizSettings {
121
+ timeLimitMinutes: number | null;
122
+ /** 0 means unlimited. */
123
+ attemptsAllowed: number;
124
+ gradingMethod: 'highest' | 'last' | 'average';
125
+ shuffleQuestions: boolean;
126
+ /** When students can see correct answers. */
127
+ reviewMode: 'immediate' | 'after_due' | 'score_only';
128
+ passingPercent: number | null;
129
+ }
130
+ export interface ForumSettings {
131
+ studentsCanStartDiscussions: boolean;
132
+ }
133
+ export interface ActivitySettingsMap {
134
+ lesson: LessonSettings;
135
+ resource: ResourceSettings;
136
+ assignment: AssignmentSettings;
137
+ quiz: QuizSettings;
138
+ forum: ForumSettings;
139
+ }
140
+ export interface ActivityNavItem {
141
+ id: string;
142
+ title: string;
143
+ type: ActivityType;
144
+ }
145
+ export interface FileInfo {
146
+ id: string;
147
+ name: string;
148
+ size: number;
149
+ mime: string;
150
+ url: string;
151
+ createdAt: string;
152
+ }
153
+ export interface Grade {
154
+ score: number | null;
155
+ maxGrade: number;
156
+ feedback: string | null;
157
+ gradedBy: PublicUser | null;
158
+ gradedAt: string | null;
159
+ }
160
+ export interface Submission {
161
+ id: string;
162
+ activityId: string;
163
+ user: PublicUser;
164
+ text: string | null;
165
+ files: FileInfo[];
166
+ submittedAt: string;
167
+ late: boolean;
168
+ }
169
+ export interface QuizAttemptSummary {
170
+ id: string;
171
+ attemptNumber: number;
172
+ status: 'in_progress' | 'finished';
173
+ startedAt: string;
174
+ finishedAt: string | null;
175
+ score: number | null;
176
+ maxScore: number;
177
+ user?: PublicUser;
178
+ }
179
+ export interface QuizInfo {
180
+ questionCount: number;
181
+ totalPoints: number;
182
+ attempts: QuizAttemptSummary[];
183
+ attemptsUsed: number;
184
+ canAttempt: boolean;
185
+ inProgressAttemptId: string | null;
186
+ }
187
+ export interface ActivityDetail<T extends ActivityType = ActivityType> extends ActivitySummary {
188
+ type: T;
189
+ description: string;
190
+ settings: ActivitySettingsMap[T];
191
+ course: CourseRef;
192
+ sectionTitle: string;
193
+ capabilities: CourseCapability[];
194
+ myRole: CourseRole | null;
195
+ prev: ActivityNavItem | null;
196
+ next: ActivityNavItem | null;
197
+ /** resource */
198
+ file?: FileInfo | null;
199
+ /** assignment: the viewer's own submission */
200
+ submission?: Submission | null;
201
+ /** assignment/quiz: the viewer's own grade */
202
+ grade?: Grade | null;
203
+ /** assignment: summary for teachers */
204
+ submissionStats?: {
205
+ participants: number;
206
+ submitted: number;
207
+ needsGrading: number;
208
+ };
209
+ quiz?: QuizInfo;
210
+ forum?: {
211
+ discussionCount: number;
212
+ postCount: number;
213
+ };
214
+ }
215
+ export interface QuestionOption {
216
+ id: string;
217
+ text: string;
218
+ /** Only present for editors or in review. */
219
+ correct?: boolean;
220
+ }
221
+ export interface Question {
222
+ id: string;
223
+ type: QuestionType;
224
+ prompt: string;
225
+ points: number;
226
+ options: QuestionOption[];
227
+ /** short/numeric: accepted answers (editors and review only). */
228
+ acceptedAnswers?: string[];
229
+ /** numeric: allowed +/- error (editors and review only). */
230
+ tolerance?: number | null;
231
+ explanation?: string | null;
232
+ }
233
+ export interface AttemptAnswer {
234
+ optionIds?: string[];
235
+ text?: string;
236
+ }
237
+ export interface QuestionResult {
238
+ correct: boolean;
239
+ partial: boolean;
240
+ points: number;
241
+ maxPoints: number;
242
+ }
243
+ export interface QuizAttempt extends QuizAttemptSummary {
244
+ activityId: string;
245
+ quizTitle: string;
246
+ course: CourseRef;
247
+ deadlineAt: string | null;
248
+ questions: Question[];
249
+ answers: Record<string, AttemptAnswer>;
250
+ /** Whether correct answers are included. */
251
+ review: boolean;
252
+ results: Record<string, QuestionResult> | null;
253
+ passingPercent: number | null;
254
+ }
255
+ export interface Discussion {
256
+ id: string;
257
+ activityId: string;
258
+ title: string;
259
+ author: PublicUser;
260
+ pinned: boolean;
261
+ locked: boolean;
262
+ createdAt: string;
263
+ lastPostAt: string;
264
+ replyCount: number;
265
+ excerpt: string;
266
+ }
267
+ export interface Post {
268
+ id: string;
269
+ parentId: string | null;
270
+ author: PublicUser;
271
+ authorRole: CourseRole | null;
272
+ body: string;
273
+ createdAt: string;
274
+ updatedAt: string;
275
+ canEdit: boolean;
276
+ canDelete: boolean;
277
+ }
278
+ export interface DiscussionDetail extends Discussion {
279
+ posts: Post[];
280
+ canReply: boolean;
281
+ canModerate: boolean;
282
+ course: CourseRef;
283
+ activityTitle: string;
284
+ }
285
+ export interface Announcement {
286
+ id: string;
287
+ course: CourseRef;
288
+ title: string;
289
+ body: string;
290
+ author: PublicUser;
291
+ createdAt: string;
292
+ }
293
+ export interface Participant {
294
+ enrolmentId: string;
295
+ user: PublicUser & {
296
+ email: string | null;
297
+ };
298
+ role: CourseRole;
299
+ status: 'active' | 'suspended';
300
+ enrolledAt: string;
301
+ lastAccessAt: string | null;
302
+ progress: number | null;
303
+ }
304
+ export interface GradebookItem {
305
+ activityId: string;
306
+ title: string;
307
+ type: ActivityType;
308
+ maxGrade: number;
309
+ dueAt: string | null;
310
+ }
311
+ export interface GradebookCell {
312
+ score: number | null;
313
+ feedback: string | null;
314
+ }
315
+ export interface GradebookRow {
316
+ user: PublicUser & {
317
+ email: string;
318
+ };
319
+ cells: Record<string, GradebookCell>;
320
+ total: number;
321
+ max: number;
322
+ percentage: number | null;
323
+ }
324
+ export interface Gradebook {
325
+ items: GradebookItem[];
326
+ rows: GradebookRow[];
327
+ averages: Record<string, number | null>;
328
+ courseAverage: number | null;
329
+ }
330
+ export interface MyGrades {
331
+ items: Array<GradebookItem & {
332
+ score: number | null;
333
+ feedback: string | null;
334
+ gradedAt: string | null;
335
+ }>;
336
+ total: number;
337
+ max: number;
338
+ percentage: number | null;
339
+ }
340
+ export interface TimelineItem {
341
+ activityId: string;
342
+ title: string;
343
+ type: ActivityType;
344
+ course: CourseRef;
345
+ dueAt: string;
346
+ status: 'todo' | 'overdue' | 'submitted' | 'graded' | 'done';
347
+ }
348
+ export interface DashboardData {
349
+ courses: CourseSummary[];
350
+ timeline: TimelineItem[];
351
+ announcements: Announcement[];
352
+ recentGrades: Array<{
353
+ activityId: string;
354
+ title: string;
355
+ type: ActivityType;
356
+ course: CourseRef;
357
+ score: number;
358
+ maxGrade: number;
359
+ gradedAt: string;
360
+ }>;
361
+ toGrade: Array<{
362
+ activityId: string;
363
+ title: string;
364
+ course: CourseRef;
365
+ count: number;
366
+ }>;
367
+ stats: {
368
+ enrolled: number;
369
+ teaching: number;
370
+ completedActivities: number;
371
+ averageGrade: number | null;
372
+ dueThisWeek: number;
373
+ };
374
+ }
375
+ export interface CalendarEvent {
376
+ id: string;
377
+ title: string;
378
+ kind: 'due' | 'course' | 'personal' | 'course-start' | 'course-end';
379
+ startsAt: string;
380
+ endsAt: string | null;
381
+ description: string | null;
382
+ course: CourseRef | null;
383
+ link: string | null;
384
+ canDelete: boolean;
385
+ }
386
+ export interface AppNotification {
387
+ id: string;
388
+ type: string;
389
+ title: string;
390
+ body: string;
391
+ link: string | null;
392
+ readAt: string | null;
393
+ createdAt: string;
394
+ }
395
+ export interface SearchResults {
396
+ courses: CourseRef[];
397
+ activities: Array<{
398
+ id: string;
399
+ title: string;
400
+ type: ActivityType;
401
+ course: CourseRef;
402
+ }>;
403
+ users: Array<PublicUser & {
404
+ email: string;
405
+ }>;
406
+ }
407
+ export interface AdminOverview {
408
+ counts: {
409
+ users: number;
410
+ courses: number;
411
+ enrolments: number;
412
+ activities: number;
413
+ submissions: number;
414
+ posts: number;
415
+ };
416
+ signups: Array<{
417
+ date: string;
418
+ count: number;
419
+ }>;
420
+ topCourses: Array<CourseRef & {
421
+ students: number;
422
+ }>;
423
+ recentUsers: User[];
424
+ database: string;
425
+ version: string;
426
+ }
427
+ export interface AdminUserRow extends User {
428
+ courseCount: number;
429
+ }
430
+ export interface AdminCourseRow extends CourseRef {
431
+ visibility: CourseVisibility;
432
+ categoryName: string | null;
433
+ teachers: PublicUser[];
434
+ studentCount: number;
435
+ createdAt: string;
436
+ }
437
+ export interface Paginated<T> {
438
+ items: T[];
439
+ total: number;
440
+ page: number;
441
+ pageSize: number;
442
+ }
443
+ export interface ApiErrorBody {
444
+ error: {
445
+ message: string;
446
+ code: string;
447
+ issues?: Array<{
448
+ path: string;
449
+ message: string;
450
+ }>;
451
+ };
452
+ }