coursekit-lms 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/README.md +127 -26
  3. package/dist/cli/index.js +7139 -1633
  4. package/dist/cli/index.js.map +1 -1
  5. package/dist/server/index.js +7128 -1655
  6. package/dist/server/index.js.map +1 -1
  7. package/dist/types/server/config.d.ts +4 -0
  8. package/dist/types/server/db/migrations/002_email.d.ts +8 -0
  9. package/dist/types/server/db/migrations/003_groups_cohorts.d.ts +7 -0
  10. package/dist/types/server/db/migrations/004_completion_badges.d.ts +8 -0
  11. package/dist/types/server/db/migrations/005_question_bank.d.ts +11 -0
  12. package/dist/types/server/db/migrations/006_grade_categories.d.ts +11 -0
  13. package/dist/types/server/db/schema-completion.d.ts +79 -0
  14. package/dist/types/server/db/schema.d.ts +165 -5
  15. package/dist/types/server/index.d.ts +7 -0
  16. package/dist/types/server/lib/events.d.ts +105 -0
  17. package/dist/types/server/routes/badges.d.ts +4 -0
  18. package/dist/types/server/routes/certificates.d.ts +3 -0
  19. package/dist/types/server/routes/cohorts.d.ts +6 -0
  20. package/dist/types/server/routes/completion.d.ts +4 -0
  21. package/dist/types/server/routes/email.d.ts +13 -0
  22. package/dist/types/server/routes/grade-categories.d.ts +4 -0
  23. package/dist/types/server/routes/groups.d.ts +4 -0
  24. package/dist/types/server/routes/question-bank.d.ts +4 -0
  25. package/dist/types/server/seed/demo-completion.d.ts +2 -0
  26. package/dist/types/server/seed/demo-email.d.ts +2 -0
  27. package/dist/types/server/seed/demo-grade-categories.d.ts +6 -0
  28. package/dist/types/server/seed/demo-groups.d.ts +6 -0
  29. package/dist/types/server/seed/demo-question-bank.d.ts +20 -0
  30. package/dist/types/server/services/badges.d.ts +39 -0
  31. package/dist/types/server/services/certificates.d.ts +42 -0
  32. package/dist/types/server/services/cohorts.d.ts +64 -0
  33. package/dist/types/server/services/completion.d.ts +63 -0
  34. package/dist/types/server/services/course-total.d.ts +107 -0
  35. package/dist/types/server/services/email/config.d.ts +55 -0
  36. package/dist/types/server/services/email/digests.d.ts +57 -0
  37. package/dist/types/server/services/email/outbox.d.ts +61 -0
  38. package/dist/types/server/services/email/preferences.d.ts +25 -0
  39. package/dist/types/server/services/email/service.d.ts +116 -0
  40. package/dist/types/server/services/email/templates.d.ts +74 -0
  41. package/dist/types/server/services/email/tokens.d.ts +11 -0
  42. package/dist/types/server/services/email/transport.d.ts +29 -0
  43. package/dist/types/server/services/enrolments.d.ts +32 -0
  44. package/dist/types/server/services/grade-categories.d.ts +31 -0
  45. package/dist/types/server/services/gradebook.d.ts +18 -0
  46. package/dist/types/server/services/groups.d.ts +90 -0
  47. package/dist/types/server/services/notify.d.ts +4 -1
  48. package/dist/types/server/services/question-bank.d.ts +53 -0
  49. package/dist/types/server/services/question-types.d.ts +146 -0
  50. package/dist/types/server/services/quiz-slots.d.ts +33 -0
  51. package/dist/types/server/services/quiz.d.ts +45 -14
  52. package/dist/types/shared/completion.d.ts +214 -0
  53. package/dist/types/shared/email.d.ts +117 -0
  54. package/dist/types/shared/grades.d.ts +18 -0
  55. package/dist/types/shared/groups.d.ts +17 -0
  56. package/dist/types/shared/permissions.d.ts +1 -1
  57. package/dist/types/shared/types.d.ts +268 -2
  58. package/dist/web/assets/{ActivityEditor-BVSZUV8l.js → ActivityEditor-BNG3aTQa.js} +2 -2
  59. package/dist/web/assets/ActivityPage-i0XHYD2Q.js +1 -0
  60. package/dist/web/assets/AdminBadgesPage-DvpxIg1P.js +1 -0
  61. package/dist/web/assets/AdminCohortsPage-B5PWBkjp.js +3 -0
  62. package/dist/web/assets/AdminCoursesPage-Dm1ECbS-.js +1 -0
  63. package/dist/web/assets/AdminEmailPage-D3E_Db1_.js +1 -0
  64. package/dist/web/assets/AdminLayout-BVeduyCQ.js +1 -0
  65. package/dist/web/assets/{AdminOverviewPage-DnTrdGbr.js → AdminOverviewPage-BaCKvhgr.js} +1 -1
  66. package/dist/web/assets/{AdminSettingsPage-B82cX8xU.js → AdminSettingsPage-B5Ag5K15.js} +1 -1
  67. package/dist/web/assets/AdminUsersPage-BVCG65EK.js +1 -0
  68. package/dist/web/assets/{AnnouncementsPage-BKW30k0Z.js → AnnouncementsPage-C0OAzyvW.js} +1 -1
  69. package/dist/web/assets/BadgePage-B3Ecudas.js +1 -0
  70. package/dist/web/assets/CalendarPage-CEks5F4m.js +1 -0
  71. package/dist/web/assets/{CatalogPage-BiMgSSBR.js → CatalogPage-e7lVtwUN.js} +1 -1
  72. package/dist/web/assets/CertificatePage-_eSGt8R-.js +9 -0
  73. package/dist/web/assets/CompletionPage-Dxp-ulA_.js +1 -0
  74. package/dist/web/assets/CourseBadgesPage-Vi3P1Lnc.js +1 -0
  75. package/dist/web/assets/CourseContentPage-IFlhVsO5.js +1 -0
  76. package/dist/web/assets/CourseLayout-BqwXol8L.js +1 -0
  77. package/dist/web/assets/CourseSettingsPage-BIagLirb.js +1 -0
  78. package/dist/web/assets/CreateCoursePage-BBcdiTtz.js +1 -0
  79. package/dist/web/assets/{DiscussionPage-CWwVpFQV.js → DiscussionPage-C23QoCSw.js} +1 -1
  80. package/dist/web/assets/GradebookSetupPage-a5GH4xIk.js +1 -0
  81. package/dist/web/assets/GradesPage-CY6MtJxs.js +1 -0
  82. package/dist/web/assets/GroupsPage-DS3HFeC4.js +1 -0
  83. package/dist/web/assets/{MyCoursesPage-Dd-Oaygv.js → MyCoursesPage-Ckj-1SCA.js} +1 -1
  84. package/dist/web/assets/{NotFoundPage-BRquC7-l.js → NotFoundPage-BmwVsGAy.js} +1 -1
  85. package/dist/web/assets/NotificationsPage-DBRM37F1.js +1 -0
  86. package/dist/web/assets/ParticipantsPage-DV4Mjfxo.js +1 -0
  87. package/dist/web/assets/ProfilePage-BqG55_02.js +1 -0
  88. package/dist/web/assets/QuestionAnswer-CJIoWSz2.js +1 -0
  89. package/dist/web/assets/QuestionBankPage-BkI44c4K.js +1 -0
  90. package/dist/web/assets/QuizAttemptPage-DQVfbLKI.js +1 -0
  91. package/dist/web/assets/QuizEditorPage-muk-KVG1.js +1 -0
  92. package/dist/web/assets/SubmissionsPage-Dx97JOzE.js +1 -0
  93. package/dist/web/assets/UnsubscribePage-BPLiTiaG.js +1 -0
  94. package/dist/web/assets/VerifyCertificatePage-Cw9iXN3C.js +1 -0
  95. package/dist/web/assets/achievements-DaIfUTKU.js +1 -0
  96. package/dist/web/assets/{arrow-up-LHDup5m4.js → arrow-up-lI30bvj5.js} +1 -1
  97. package/dist/web/assets/badge-art-QPo-pYql.js +1 -0
  98. package/dist/web/assets/badge-card-ByT0wR6q.js +1 -0
  99. package/dist/web/assets/badge-dialog-p2zTk4h0.js +1 -0
  100. package/dist/web/assets/{ban-D3Vsxg_g.js → ban-DEiI8npI.js} +1 -1
  101. package/dist/web/assets/bank-S3XEFPfe.js +3 -0
  102. package/dist/web/assets/bell-off-Bo2RE0kn.js +1 -0
  103. package/dist/web/assets/calendar-range-Cfg-P4Md.js +1 -0
  104. package/dist/web/assets/certificate-sheet-DzW0lfzR.js +2 -0
  105. package/dist/web/assets/chevron-left-Bu6IJANV.js +1 -0
  106. package/dist/web/assets/circle-dashed-D34ZjnSx.js +1 -0
  107. package/dist/web/assets/clock-DPBmdKAi.js +1 -0
  108. package/dist/web/assets/cohorts-DL0Dsxva.js +1 -0
  109. package/dist/web/assets/completion-2z7I-ypT.js +1 -0
  110. package/dist/web/assets/contact-NCWQa7wc.js +1 -0
  111. package/dist/web/assets/{context-BLVW7NB7.js → context-D8W_QqNi.js} +1 -1
  112. package/dist/web/assets/{copy-Bxxjq6zo.js → copy-B5IKRMFo.js} +1 -1
  113. package/dist/web/assets/download-BrtK5sVk.js +1 -0
  114. package/dist/web/assets/{ellipsis-c2POIN-Y.js → ellipsis-BDmYLoyn.js} +1 -1
  115. package/dist/web/assets/email-BZ3kGs-R.js +1 -0
  116. package/dist/web/assets/flag-DOzXVys0.js +1 -0
  117. package/dist/web/assets/folder-input-M2p_UJZX.js +1 -0
  118. package/dist/web/assets/{library-3WG9oLCb.js → folder-tree-B-DoLXMB.js} +1 -1
  119. package/dist/web/assets/frame-DZh5g5b3.js +1 -0
  120. package/dist/web/assets/globe-DDTr53UY.js +1 -0
  121. package/dist/web/assets/grades-ogaD0MDO.js +1 -0
  122. package/dist/web/assets/groups-CrYV_AFp.js +1 -0
  123. package/dist/web/assets/{hooks-BBARn-DA.js → hooks-EFhyJ5yU.js} +1 -1
  124. package/dist/web/assets/hourglass-BKca6Cje.js +1 -0
  125. package/dist/web/assets/inbox-x1U4YU-c.js +1 -0
  126. package/dist/web/assets/index-BdPmMS6n.css +2 -0
  127. package/dist/web/assets/index-CEZdqKdi.js +50 -0
  128. package/dist/web/assets/{key-round-B_KI-brR.js → key-round-fzvV-etw.js} +1 -1
  129. package/dist/web/assets/library-Bcm33ouq.js +1 -0
  130. package/dist/web/assets/lightbulb-CjSpJ1_v.js +1 -0
  131. package/dist/web/assets/{lock-BjbqwA_0.js → lock-C2edVDOc.js} +1 -1
  132. package/dist/web/assets/mail-CQ9yiBph.js +1 -0
  133. package/dist/web/assets/mail-x-B6oBqlcw.js +1 -0
  134. package/dist/web/assets/{markdown-ykrkPMbn.js → markdown-HNlXovsL.js} +3 -3
  135. package/dist/web/assets/message-square-text-wvO9_guT.js +1 -0
  136. package/dist/web/assets/{misc-DvgDEI3I.js → misc-CyGhN6HT.js} +1 -1
  137. package/dist/web/assets/{pencil-p0GQmIMo.js → pencil-DFUpj3YP.js} +1 -1
  138. package/dist/web/assets/{pin-DlYC3uec.js → pin-DNUQ6-WX.js} +1 -1
  139. package/dist/web/assets/revoke-dialog-DjBKaFTV.js +1 -0
  140. package/dist/web/assets/rotate-ccw-yBj9Ri49.js +1 -0
  141. package/dist/web/assets/scroll-text-RmPlZi3F.js +1 -0
  142. package/dist/web/assets/{send-mxSHcdcD.js → send-BnVkFV8w.js} +1 -1
  143. package/dist/web/assets/{settings-DRKWzSHN.js → settings-BxdCrDf8.js} +1 -1
  144. package/dist/web/assets/shield-x-RpNHS0o8.js +1 -0
  145. package/dist/web/assets/shuffle-C1aB_4dp.js +1 -0
  146. package/dist/web/assets/target-G9Q_WQLB.js +1 -0
  147. package/dist/web/assets/trophy-BFFngFEh.js +1 -0
  148. package/dist/web/assets/user-minus-CkOPT3ak.js +1 -0
  149. package/dist/web/assets/users-round-CNhv0Whm.js +1 -0
  150. package/dist/web/index.html +4 -4
  151. package/package.json +6 -1
  152. package/dist/web/assets/ActivityPage-DPmSV_mU.js +0 -1
  153. package/dist/web/assets/AdminCoursesPage-uaSHNtzf.js +0 -1
  154. package/dist/web/assets/AdminLayout-DqoShZGn.js +0 -1
  155. package/dist/web/assets/AdminUsersPage-3d2F9AEl.js +0 -1
  156. package/dist/web/assets/CalendarPage-CLRWyTNT.js +0 -1
  157. package/dist/web/assets/CourseContentPage-BIDH0UbG.js +0 -1
  158. package/dist/web/assets/CourseLayout-ql01LEmj.js +0 -1
  159. package/dist/web/assets/CourseSettingsPage-CReoPqOa.js +0 -1
  160. package/dist/web/assets/CreateCoursePage-DFCHlq5M.js +0 -1
  161. package/dist/web/assets/GradesPage-Bu5vphcG.js +0 -1
  162. package/dist/web/assets/NotificationsPage-LJvqb6Dj.js +0 -1
  163. package/dist/web/assets/ParticipantsPage-wFxiphna.js +0 -1
  164. package/dist/web/assets/ProfilePage-CzfhacAX.js +0 -1
  165. package/dist/web/assets/QuizAttemptPage-CEAV6wAL.js +0 -1
  166. package/dist/web/assets/QuizEditorPage-DS_czQVM.js +0 -3
  167. package/dist/web/assets/SubmissionsPage-CQjcx09G.js +0 -1
  168. package/dist/web/assets/chevron-left-D6IMQD6N.js +0 -1
  169. package/dist/web/assets/frame-CGabirLa.js +0 -1
  170. package/dist/web/assets/index-B29bTBiJ.js +0 -50
  171. package/dist/web/assets/index-WxCvsbJq.css +0 -2
  172. package/dist/web/assets/message-square-text-fe24gbEU.js +0 -1
  173. package/dist/web/assets/trophy-Cch2iF1m.js +0 -1
@@ -1,3 +1,4 @@
1
+ import { type EmailOptions, type ResolvedEmailConfig } from './services/email/config.js';
1
2
  export interface CoursekitOptions {
2
3
  /** `sqlite://./data/coursekit.db` (default), `sqlite::memory:` or a `postgres://` URL. */
3
4
  databaseUrl?: string | undefined;
@@ -15,6 +16,8 @@ export interface CoursekitOptions {
15
16
  migrate?: boolean | undefined;
16
17
  /** Log each request to the console. */
17
18
  logRequests?: boolean | undefined;
19
+ /** Outgoing email (notifications and digests). Off unless a transport or COURSEKIT_SMTP_URL is set. */
20
+ email?: EmailOptions | undefined;
18
21
  }
19
22
  export interface ResolvedConfig {
20
23
  databaseUrl: string;
@@ -27,5 +30,6 @@ export interface ResolvedConfig {
27
30
  migrate: boolean;
28
31
  logRequests: boolean;
29
32
  secureCookies: boolean;
33
+ email: ResolvedEmailConfig;
30
34
  }
31
35
  export declare function resolveConfig(options?: CoursekitOptions, env?: NodeJS.ProcessEnv): ResolvedConfig;
@@ -0,0 +1,8 @@
1
+ import type { Kysely } from 'kysely';
2
+ /**
3
+ * Email notifications: per-person delivery preferences and an outbox that the background worker
4
+ * delivers from. Existing people get no preference row, which means "use the site default", so sites
5
+ * upgrading from 0.1.x need no data changes.
6
+ */
7
+ export declare function up(db: Kysely<any>): Promise<void>;
8
+ export declare function down(db: Kysely<any>): Promise<void>;
@@ -0,0 +1,7 @@
1
+ import { type Kysely } from 'kysely';
2
+ /**
3
+ * Course groups and site cohorts (0.2.0). Only adds tables, so sites upgrading from 0.1.x keep all their data.
4
+ * Portable column types only, as in 001_initial, so the same migration runs on SQLite and PostgreSQL.
5
+ */
6
+ export declare function up(db: Kysely<any>): Promise<void>;
7
+ export declare function down(db: Kysely<any>): Promise<void>;
@@ -0,0 +1,8 @@
1
+ import type { Kysely } from 'kysely';
2
+ /**
3
+ * Course completion, certificates and badges. Only adds tables, so sites upgrading from 0.1.x keep
4
+ * all their data; completion tracking stays off for every course until a teacher turns it on.
5
+ * Portable column types only (text, integer, double precision), like 001_initial.
6
+ */
7
+ export declare function up(db: Kysely<any>): Promise<void>;
8
+ export declare function down(db: Kysely<any>): Promise<void>;
@@ -0,0 +1,11 @@
1
+ import type { Kysely } from 'kysely';
2
+ /**
3
+ * Question banks (0.2.0). Questions move out of individual quizzes into a bank per course, organised in
4
+ * categories. A quiz becomes an ordered list of slots: a bank question, or N random questions from a
5
+ * category. Attempts keep a snapshot of the questions they use, so later edits never change them.
6
+ *
7
+ * Existing data is carried forward: each quiz's questions keep their ids and move into a category named
8
+ * after the quiz, they become that quiz's slots (same order and marks), and every attempt gets a snapshot
9
+ * of the questions it used.
10
+ */
11
+ export declare function up(db: Kysely<any>): Promise<void>;
@@ -0,0 +1,11 @@
1
+ import type { Kysely } from 'kysely';
2
+ /**
3
+ * Gradebook categories and weights (0.2.0).
4
+ *
5
+ * Nothing needs converting when a 0.1.x site upgrades: a course without a `grade_settings` row
6
+ * keeps natural (points) aggregation, an activity without a `grade_items` row sits in the course's
7
+ * default category and is weighted by its points, so every existing course total stays the same.
8
+ * The default category's row (id = course id) is only written once a teacher saves the setup.
9
+ */
10
+ export declare function up(db: Kysely<any>): Promise<void>;
11
+ export declare function down(db: Kysely<any>): Promise<void>;
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Tables for course completion, certificates and badges (migration 004_completion_badges).
3
+ * Same conventions as schema.ts: 0/1 booleans, ISO-8601 strings and JSON stored as text.
4
+ */
5
+ import type { Selectable } from 'kysely';
6
+ import type { BadgeColor, BadgeCriteria, BadgeIcon, CompletionCriteriaMode } from '../../shared/completion.js';
7
+ /** One row per course that has (ever) been configured; no row means completion tracking is off. */
8
+ export interface CourseCompletionSettingsTable {
9
+ courseId: string;
10
+ enabled: number;
11
+ mode: CompletionCriteriaMode;
12
+ /** JSON array of activity ids (required activities in `selected` mode). */
13
+ activityIds: string;
14
+ /** Minimum course total in percent, or null. */
15
+ minGrade: number | null;
16
+ certificateEnabled: number;
17
+ certificateTitle: string;
18
+ certificateBody: string;
19
+ certificateSignatureName: string;
20
+ certificateSignatureTitle: string;
21
+ updatedAt: string;
22
+ updatedBy: string | null;
23
+ }
24
+ export interface CourseCompletionsTable {
25
+ courseId: string;
26
+ userId: string;
27
+ completedAt: string;
28
+ }
29
+ /** Issued certificates keep a snapshot of the name, course title and template, so later edits don't change them. */
30
+ export interface CertificatesTable {
31
+ id: string;
32
+ /** 12 upper-case Crockford base32 characters, unique. */
33
+ code: string;
34
+ /** null once the course is deleted; the certificate stays verifiable. */
35
+ courseId: string | null;
36
+ userId: string;
37
+ recipientName: string;
38
+ courseTitle: string;
39
+ siteName: string;
40
+ title: string;
41
+ body: string;
42
+ signatureName: string;
43
+ signatureTitle: string;
44
+ completedAt: string;
45
+ issuedAt: string;
46
+ revokedAt: string | null;
47
+ revokedBy: string | null;
48
+ revokeReason: string | null;
49
+ }
50
+ export interface BadgesTable {
51
+ id: string;
52
+ /** null for site badges. */
53
+ courseId: string | null;
54
+ name: string;
55
+ description: string;
56
+ icon: BadgeIcon;
57
+ color: BadgeColor;
58
+ criteria: BadgeCriteria;
59
+ /** JSON array of course ids (site badges with `courses` criteria). */
60
+ criteriaCourseIds: string;
61
+ createdBy: string | null;
62
+ createdAt: string;
63
+ updatedAt: string;
64
+ }
65
+ /** One row per badge and person. Revoked awards are kept so automatic criteria don't award them again. */
66
+ export interface BadgeAwardsTable {
67
+ badgeId: string;
68
+ userId: string;
69
+ awardedAt: string;
70
+ /** null when awarded automatically. */
71
+ awardedBy: string | null;
72
+ note: string | null;
73
+ revokedAt: string | null;
74
+ revokedBy: string | null;
75
+ }
76
+ export type CourseCompletionSettingsRow = Selectable<CourseCompletionSettingsTable>;
77
+ export type CertificateRow = Selectable<CertificatesTable>;
78
+ export type BadgeRow = Selectable<BadgesTable>;
79
+ export type BadgeAwardRow = Selectable<BadgeAwardsTable>;
@@ -4,8 +4,10 @@
4
4
  * timestamps as ISO-8601 strings and structured values as JSON text, which keeps the
5
5
  * schema portable between SQLite and PostgreSQL.
6
6
  */
7
- import type { Insertable, Selectable } from 'kysely';
7
+ import type { Generated, Insertable, Selectable } from 'kysely';
8
8
  import type { ActivityType, CompletionMode, CourseRole, CourseVisibility, EnrolmentMethod, QuestionType, SiteRole, UserStatus } from '../../shared/types.js';
9
+ import type { EmailFrequency } from '../../shared/email.js';
10
+ import type { BadgeAwardsTable, BadgesTable, CertificatesTable, CourseCompletionSettingsTable, CourseCompletionsTable } from './schema-completion.js';
9
11
  export interface SettingsTable {
10
12
  key: string;
11
13
  value: string;
@@ -132,19 +134,59 @@ export interface GradesTable {
132
134
  gradedAt: string | null;
133
135
  updatedAt: string;
134
136
  }
135
- export interface QuestionsTable {
137
+ /** Per-course gradebook settings. A course without a row uses natural (points) aggregation. */
138
+ export interface GradeSettingsTable {
139
+ courseId: string;
140
+ aggregation: 'natural' | 'weighted';
141
+ updatedAt: string;
142
+ }
143
+ /**
144
+ * Grade categories. Each course has one default category whose id is the course id; it is
145
+ * created the first time the setup is saved and stands in for activities without a category.
146
+ */
147
+ export interface GradeCategoriesTable {
136
148
  id: string;
149
+ courseId: string;
150
+ name: string;
151
+ /** Percentage of the course total in weighted aggregation. */
152
+ weight: number;
153
+ dropLowest: number;
154
+ position: number;
155
+ createdAt: string;
156
+ updatedAt: string;
157
+ }
158
+ /** Gradebook settings of one graded activity. Activities without a row are uncategorised and weighted by points. */
159
+ export interface GradeItemsTable {
137
160
  activityId: string;
161
+ courseId: string;
162
+ /** null = the course's default category. */
163
+ categoryId: string | null;
164
+ /** Weight within the category (used by weighted aggregation); null = the activity's max grade. */
165
+ weight: number | null;
166
+ updatedAt: string;
167
+ }
168
+ /** A question in a course's question bank. Quizzes use questions through quiz slots. */
169
+ export interface QuestionsTable {
170
+ id: string;
171
+ courseId: string;
172
+ categoryId: string;
138
173
  type: QuestionType;
174
+ /** Optional short name for the question bank; the prompt is shown when empty. */
175
+ name: string;
139
176
  prompt: string;
177
+ /** Default mark when the question is added to a quiz. */
140
178
  points: number;
141
- /** JSON array of { id, text, correct }. */
179
+ /** JSON array: choices { id, text, correct }, ordering items { id, text } in the right order, or matching pairs { id, text, answer }. */
142
180
  options: string;
143
181
  /** JSON array of strings. */
144
182
  acceptedAnswers: string;
145
183
  tolerance: number | null;
146
184
  explanation: string | null;
147
- position: number;
185
+ /** JSON object: essay word limits and grader notes, matching distractors. */
186
+ settings: string;
187
+ createdBy: string | null;
188
+ createdAt: string;
189
+ updatedAt: string;
148
190
  }
149
191
  export interface QuizAttemptsTable {
150
192
  id: string;
@@ -152,7 +194,8 @@ export interface QuizAttemptsTable {
152
194
  courseId: string;
153
195
  userId: string;
154
196
  attemptNumber: number;
155
- status: 'in_progress' | 'finished';
197
+ /** `needs_grading`: submitted, waiting for a teacher to mark essay answers. */
198
+ status: 'in_progress' | 'needs_grading' | 'finished';
156
199
  /** JSON array of question ids. */
157
200
  questionOrder: string;
158
201
  /** JSON object keyed by question id. */
@@ -164,6 +207,8 @@ export interface QuizAttemptsTable {
164
207
  startedAt: string;
165
208
  deadlineAt: string | null;
166
209
  finishedAt: string | null;
210
+ /** JSON array of the questions as they were when the attempt started (see services/question-types.ts). */
211
+ snapshot: Generated<string>;
167
212
  }
168
213
  export interface DiscussionsTable {
169
214
  id: string;
@@ -216,6 +261,29 @@ export interface CalendarEventsTable {
216
261
  createdBy: string;
217
262
  createdAt: string;
218
263
  }
264
+ export interface QuestionCategoriesTable {
265
+ id: string;
266
+ courseId: string;
267
+ parentId: string | null;
268
+ name: string;
269
+ description: string;
270
+ position: number;
271
+ createdAt: string;
272
+ }
273
+ /** One entry in a quiz: a specific bank question, or `questionCount` random questions from a category. */
274
+ export interface QuizSlotsTable {
275
+ id: string;
276
+ activityId: string;
277
+ position: number;
278
+ kind: 'question' | 'random';
279
+ questionId: string | null;
280
+ categoryId: string | null;
281
+ /** 1 for a question slot; how many questions to pick for a random slot. */
282
+ questionCount: number;
283
+ includeSubcategories: number;
284
+ /** Mark for each question in the slot. */
285
+ points: number;
286
+ }
219
287
  export interface Database {
220
288
  settings: SettingsTable;
221
289
  users: UsersTable;
@@ -236,6 +304,23 @@ export interface Database {
236
304
  announcements: AnnouncementsTable;
237
305
  notifications: NotificationsTable;
238
306
  calendarEvents: CalendarEventsTable;
307
+ emailPreferences: EmailPreferencesTable;
308
+ emailOutbox: EmailOutboxTable;
309
+ courseGroups: CourseGroupsTable;
310
+ courseGroupMembers: CourseGroupMembersTable;
311
+ cohorts: CohortsTable;
312
+ cohortMembers: CohortMembersTable;
313
+ cohortCourses: CohortCoursesTable;
314
+ courseCompletionSettings: CourseCompletionSettingsTable;
315
+ courseCompletions: CourseCompletionsTable;
316
+ certificates: CertificatesTable;
317
+ badges: BadgesTable;
318
+ badgeAwards: BadgeAwardsTable;
319
+ questionCategories: QuestionCategoriesTable;
320
+ quizSlots: QuizSlotsTable;
321
+ gradeSettings: GradeSettingsTable;
322
+ gradeCategories: GradeCategoriesTable;
323
+ gradeItems: GradeItemsTable;
239
324
  }
240
325
  export type UserRow = Selectable<UsersTable>;
241
326
  export type SessionRow = Selectable<SessionsTable>;
@@ -251,3 +336,78 @@ export type QuizAttemptRow = Selectable<QuizAttemptsTable>;
251
336
  export type DiscussionRow = Selectable<DiscussionsTable>;
252
337
  export type PostRow = Selectable<PostsTable>;
253
338
  export type NewActivity = Insertable<ActivitiesTable>;
339
+ export interface EmailPreferencesTable {
340
+ userId: string;
341
+ /** null follows the site default. */
342
+ frequency: EmailFrequency | null;
343
+ /** JSON array of email category ids. */
344
+ disabledCategories: string;
345
+ lastDigestAt: string | null;
346
+ digestClaim: string | null;
347
+ updatedAt: string;
348
+ }
349
+ export interface EmailOutboxTable {
350
+ id: string;
351
+ kind: 'notification' | 'digest' | 'test';
352
+ userId: string | null;
353
+ notificationId: string | null;
354
+ toAddress: string;
355
+ subject: string;
356
+ html: string;
357
+ text: string;
358
+ /** JSON object of extra headers. */
359
+ headers: string;
360
+ status: 'pending' | 'sending' | 'sent' | 'failed';
361
+ attempts: number;
362
+ maxAttempts: number;
363
+ nextAttemptAt: string;
364
+ lockId: string | null;
365
+ lockedUntil: string | null;
366
+ lastError: string | null;
367
+ lastErrorAt: string | null;
368
+ sentAt: string | null;
369
+ createdAt: string;
370
+ updatedAt: string;
371
+ }
372
+ export type EmailOutboxRow = Selectable<EmailOutboxTable>;
373
+ export interface CourseGroupsTable {
374
+ id: string;
375
+ courseId: string;
376
+ name: string;
377
+ description: string;
378
+ createdAt: string;
379
+ updatedAt: string;
380
+ }
381
+ /** Group membership. Rows of people no longer enrolled are kept but hidden, and come back if they re-enrol. */
382
+ export interface CourseGroupMembersTable {
383
+ groupId: string;
384
+ userId: string;
385
+ courseId: string;
386
+ createdAt: string;
387
+ }
388
+ export interface CohortsTable {
389
+ id: string;
390
+ name: string;
391
+ description: string;
392
+ createdAt: string;
393
+ updatedAt: string;
394
+ }
395
+ export interface CohortMembersTable {
396
+ cohortId: string;
397
+ userId: string;
398
+ createdAt: string;
399
+ }
400
+ /** A cohort linked to a course: its members are enrolled with `role`, now and whenever they join the cohort later. */
401
+ export interface CohortCoursesTable {
402
+ id: string;
403
+ cohortId: string;
404
+ courseId: string;
405
+ role: CourseRole;
406
+ createdBy: string | null;
407
+ createdAt: string;
408
+ }
409
+ export type CourseGroupRow = Selectable<CourseGroupsTable>;
410
+ export type CohortRow = Selectable<CohortsTable>;
411
+ export type CohortCourseRow = Selectable<CohortCoursesTable>;
412
+ export type QuestionCategoryRow = Selectable<QuestionCategoriesTable>;
413
+ export type QuizSlotRow = Selectable<QuizSlotsTable>;
@@ -19,6 +19,7 @@ import type { User } from '../shared/types.js';
19
19
  import { EventBus } from './lib/events.js';
20
20
  import { type FileStorage } from './lib/storage.js';
21
21
  import { type SeedDemoOptions, type SeedDemoResult } from './seed/demo.js';
22
+ import { type CoursekitEmail } from './services/email/service.js';
22
23
  import { type CreateUserInput } from './services/users.js';
23
24
  export interface CreateCoursekitOptions extends CoursekitOptions {
24
25
  /** Custom file storage (S3, R2, ...). Defaults to `<dataDir>/uploads` on disk. */
@@ -47,6 +48,8 @@ export interface Coursekit {
47
48
  /** Creates an account. Returns the public user (never the password hash). */
48
49
  createUser(input: CreateUserInput): Promise<User>;
49
50
  seedDemo(options?: SeedDemoOptions): Promise<SeedDemoResult>;
51
+ /** Outgoing email: digests, delivery of the outbox and test messages (no-ops while email is off). */
52
+ email: CoursekitEmail;
50
53
  close(): Promise<void>;
51
54
  }
52
55
  export declare function createCoursekit(options?: CreateCoursekitOptions): Promise<Coursekit>;
@@ -60,5 +63,9 @@ export type { DB, DatabaseKind } from './db/types.js';
60
63
  export type { AppDeps, AppEnv } from './context.js';
61
64
  export type { CreateUserInput } from './services/users.js';
62
65
  export type { SeedDemoOptions, SeedDemoResult } from './seed/demo.js';
66
+ export type { EmailMessage, EmailOptions, EmailTransport, ResolvedEmailConfig } from './services/email/config.js';
67
+ export type { CoursekitEmail, DigestRunResult, OutboxRunResult } from './services/email/service.js';
68
+ export type * from '../shared/email.js';
63
69
  export type * from '../shared/types.js';
70
+ export type * from '../shared/completion.js';
64
71
  export { COURSE_CAPABILITIES, ROLE_CAPABILITIES, getCourseCapabilities, type CourseCapability } from '../shared/permissions.js';
@@ -70,6 +70,111 @@ export interface CoursekitEvents {
70
70
  courseId: string;
71
71
  userId: string;
72
72
  };
73
+ 'email.sent': {
74
+ emailId: string;
75
+ kind: 'notification' | 'digest' | 'test';
76
+ userId: string | null;
77
+ to: string;
78
+ };
79
+ 'email.failed': {
80
+ emailId: string;
81
+ kind: 'notification' | 'digest' | 'test';
82
+ userId: string | null;
83
+ to: string;
84
+ error: string;
85
+ /** False when the message was given up on. */
86
+ willRetry: boolean;
87
+ };
88
+ 'group.created': {
89
+ groupId: string;
90
+ courseId: string;
91
+ };
92
+ 'group.updated': {
93
+ groupId: string;
94
+ courseId: string;
95
+ };
96
+ 'group.deleted': {
97
+ groupId: string;
98
+ courseId: string;
99
+ };
100
+ 'group.member.added': {
101
+ groupId: string;
102
+ courseId: string;
103
+ userId: string;
104
+ };
105
+ 'group.member.removed': {
106
+ groupId: string;
107
+ courseId: string;
108
+ userId: string;
109
+ };
110
+ 'cohort.created': {
111
+ cohortId: string;
112
+ };
113
+ 'cohort.updated': {
114
+ cohortId: string;
115
+ };
116
+ 'cohort.deleted': {
117
+ cohortId: string;
118
+ };
119
+ 'cohort.member.added': {
120
+ cohortId: string;
121
+ userId: string;
122
+ };
123
+ 'cohort.member.removed': {
124
+ cohortId: string;
125
+ userId: string;
126
+ };
127
+ 'cohort.linked': {
128
+ cohortId: string;
129
+ courseId: string;
130
+ role: CourseRole;
131
+ };
132
+ 'cohort.unlinked': {
133
+ cohortId: string;
134
+ courseId: string;
135
+ };
136
+ 'course.completed': {
137
+ courseId: string;
138
+ userId: string;
139
+ completedAt: string;
140
+ };
141
+ 'certificate.issued': {
142
+ certificateId: string;
143
+ courseId: string;
144
+ userId: string;
145
+ code: string;
146
+ };
147
+ 'certificate.revoked': {
148
+ certificateId: string;
149
+ courseId: string | null;
150
+ userId: string;
151
+ revokedBy: string;
152
+ };
153
+ 'badge.awarded': {
154
+ badgeId: string;
155
+ courseId: string | null;
156
+ userId: string;
157
+ awardedBy: string | null;
158
+ };
159
+ 'badge.revoked': {
160
+ badgeId: string;
161
+ courseId: string | null;
162
+ userId: string;
163
+ revokedBy: string;
164
+ };
165
+ /** A quiz attempt was handed in. `needsGrading`: essays wait for a teacher; `quiz.attempt.finished` follows once they are marked. */
166
+ 'quiz.attempt.submitted': {
167
+ attemptId: string;
168
+ activityId: string;
169
+ courseId: string;
170
+ userId: string;
171
+ needsGrading: boolean;
172
+ };
173
+ /** Grade categories, weights or the aggregation changed, so course totals may have changed for everyone. */
174
+ 'gradebook.setup.updated': {
175
+ courseId: string;
176
+ userId: string;
177
+ };
73
178
  }
74
179
  export type EventName = keyof CoursekitEvents;
75
180
  type Handler<T> = (payload: T) => void | Promise<void>;
@@ -0,0 +1,4 @@
1
+ import { Hono } from 'hono';
2
+ import { type AppDeps, type AppEnv } from '../context.js';
3
+ /** Course badges (made by teachers) and site badges (made by administrators), and awarding them. */
4
+ export declare function badgeRoutes(deps: AppDeps): Hono<AppEnv, import("hono/types").BlankSchema, "/">;
@@ -0,0 +1,3 @@
1
+ import { Hono } from 'hono';
2
+ import { type AppDeps, type AppEnv } from '../context.js';
3
+ export declare function certificateRoutes(deps: AppDeps): Hono<AppEnv, import("hono/types").BlankSchema, "/">;
@@ -0,0 +1,6 @@
1
+ import { Hono } from 'hono';
2
+ import { type AppDeps, type AppEnv } from '../context.js';
3
+ /** Site cohorts, for administrators: `/api/admin/cohorts`. */
4
+ export declare function cohortRoutes(deps: AppDeps): Hono<AppEnv, import("hono/types").BlankSchema, "/">;
5
+ /** Cohort enrolment for one course: `/api/courses/:courseId/cohorts`, with `course:manageParticipants`. */
6
+ export declare function courseCohortRoutes(deps: AppDeps): Hono<AppEnv, import("hono/types").BlankSchema, "/">;
@@ -0,0 +1,4 @@
1
+ import { Hono } from 'hono';
2
+ import { type AppDeps, type AppEnv } from '../context.js';
3
+ /** Course completion: criteria settings, the student's checklist, the teacher's report and issued certificates. */
4
+ export declare function completionRoutes(deps: AppDeps): Hono<AppEnv, import("hono/types").BlankSchema, "/">;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Email routes, mounted at the root:
3
+ * - /api/email/preferences: the signed-in person's delivery preferences
4
+ * - /api/email/unsubscribe: the unsubscribe page's API (no sign-in; the signed token is the credential)
5
+ * - POST /unsubscribe: RFC 8058 one-click unsubscribe, posted by mail providers to the List-Unsubscribe URL.
6
+ * It lives outside /api because those requests carry no Origin header, which /api's CSRF check requires.
7
+ * - /api/admin/email: delivery status, settings and test emails for administrators
8
+ */
9
+ import { Hono } from 'hono';
10
+ import { type AppDeps, type AppEnv } from '../context.js';
11
+ /** "a•••@example.com" */
12
+ export declare function maskEmail(email: string): string;
13
+ export declare function emailRoutes(deps: AppDeps): Hono<AppEnv, import("hono/types").BlankSchema, "/">;
@@ -0,0 +1,4 @@
1
+ import { Hono } from 'hono';
2
+ import { type AppDeps, type AppEnv } from '../context.js';
3
+ /** Gradebook setup: grade categories, weights, drop-lowest rules and the course total's aggregation. */
4
+ export declare function gradeCategoryRoutes(deps: AppDeps): Hono<AppEnv, import("hono/types").BlankSchema, "/">;
@@ -0,0 +1,4 @@
1
+ import { Hono } from 'hono';
2
+ import { type AppDeps, type AppEnv } from '../context.js';
3
+ /** Course groups: `/api/courses/:courseId/groups`. Changing groups needs `course:manageGroups`. */
4
+ export declare function groupRoutes(deps: AppDeps): Hono<AppEnv, import("hono/types").BlankSchema, "/">;
@@ -0,0 +1,4 @@
1
+ import { Hono } from 'hono';
2
+ import { type AppDeps, type AppEnv } from '../context.js';
3
+ /** The course question bank: categories and questions. Everything needs `questionbank:manage`. */
4
+ export declare function questionBankRoutes(deps: AppDeps): Hono<AppEnv, import("hono/types").BlankSchema, "/">;
@@ -0,0 +1,2 @@
1
+ import type { AppDeps } from '../context.js';
2
+ export declare function seedCompletionDemo(deps: Pick<AppDeps, 'db' | 'events'>): Promise<void>;
@@ -0,0 +1,2 @@
1
+ import type { AppDeps } from '../context.js';
2
+ export declare function seedDemoEmail(deps: Pick<AppDeps, 'db'>): Promise<void>;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Demo gradebook setup: Modern Web Development uses weighted categories, so the demo shows
3
+ * category subtotals, weights and a drop-lowest rule. The other demo courses stay natural.
4
+ */
5
+ import type { DB } from '../db/types.js';
6
+ export declare function seedDemoGradeCategories(db: DB): Promise<void>;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Demo groups and cohorts: project teams in Modern Web Development (Alex is in two groups) and a
3
+ * bootcamp cohort linked to Data Science Fundamentals. Runs after the rest of the demo is inserted.
4
+ */
5
+ import type { AppDeps } from '../context.js';
6
+ export declare function seedDemoGroups(deps: Pick<AppDeps, 'db'>): Promise<void>;
@@ -0,0 +1,20 @@
1
+ import type { QuestionType } from '../../shared/types.js';
2
+ import type { AppDeps } from '../context.js';
3
+ import type { DB } from '../db/types.js';
4
+ /** A demo quiz question as the demo course specs describe it (one quiz each). */
5
+ export interface DemoQuestionRow {
6
+ id: string;
7
+ activityId: string;
8
+ type: QuestionType;
9
+ prompt: string;
10
+ points: number;
11
+ options: string;
12
+ acceptedAnswers: string;
13
+ tolerance: number | null;
14
+ explanation: string | null;
15
+ position: number;
16
+ }
17
+ /** Puts each demo quiz's questions into its course's bank (a category per quiz) and makes them the quiz's slots. */
18
+ export declare function insertDemoQuizQuestions(db: DB, rows: DemoQuestionRow[]): Promise<void>;
19
+ /** The bank, quiz and attempts for Modern Web Development, plus snapshots for the other demo attempts. */
20
+ export declare function seedQuestionBankDemo(deps: Pick<AppDeps, 'db' | 'events'>): Promise<void>;
@@ -0,0 +1,39 @@
1
+ import type { BadgeRecipient, BadgeSummary, EarnedBadge } from '../../shared/completion.js';
2
+ import type { AppDeps } from '../context.js';
3
+ import type { DB } from '../db/types.js';
4
+ import type { BadgeRow } from '../db/schema-completion.js';
5
+ export interface AwardOptions {
6
+ awardedBy: string | null;
7
+ note?: string | null;
8
+ at?: string;
9
+ /** Manual awards bring back a revoked award; automatic ones never do. */
10
+ restoreRevoked: boolean;
11
+ }
12
+ export interface BadgeAwards {
13
+ badge: BadgeRow;
14
+ userIds: string[];
15
+ }
16
+ export declare function criteriaCourseIds(badge: Pick<BadgeRow, 'criteriaCourseIds'>): string[];
17
+ /** Awards `badge` to each user once. Returns the users who received it now (new, or restored from revoked). */
18
+ export declare function insertAwards(db: DB, badge: BadgeRow, userIds: string[], options: AwardOptions): Promise<string[]>;
19
+ /** People (optionally limited to `userIds`) who completed every course in `courseIds`. */
20
+ export declare function usersWhoCompletedAll(db: DB, courseIds: string[], userIds?: string[]): Promise<string[]>;
21
+ /**
22
+ * Automatic awards for people who just completed `courseId`: the course's completion badges and any
23
+ * site badge whose courses they have now all completed.
24
+ */
25
+ export declare function awardBadgesForCompletion(db: DB, courseId: string, userIds: string[], at: string): Promise<BadgeAwards[]>;
26
+ /** Retroactive automatic awards, e.g. right after a completion badge is created. */
27
+ export declare function awardQualifyingUsers(db: DB, badge: BadgeRow): Promise<string[]>;
28
+ /** Notifies new recipients and emits `badge.awarded`. Call after the awards are committed. */
29
+ export declare function announceAwards(deps: Pick<AppDeps, 'db' | 'events'>, awards: BadgeAwards[], awardedBy: string | null): Promise<void>;
30
+ /** Badge cards with their courses, recipient counts and the viewer's own awards, in a fixed number of queries. */
31
+ export declare function summarizeBadges(db: DB, badges: BadgeRow[], options: {
32
+ earnedBy: string | null;
33
+ countRecipients: boolean;
34
+ }): Promise<BadgeSummary[]>;
35
+ /** Everyone who has (or had) the badge, newest first. Emails only for people who may see them. */
36
+ export declare function badgeRecipients(db: DB, badgeId: string, showEmails: boolean): Promise<BadgeRecipient[]>;
37
+ export declare function earnedBadges(db: DB, userId: string): Promise<EarnedBadge[]>;
38
+ /** Drops a deleted course from site badge criteria; a badge left without courses becomes a manual one. */
39
+ export declare function pruneDeletedCourse(db: DB, courseId: string): Promise<void>;