coursekit-lms 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +258 -2
- package/dist/cli/index.js +5166 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/server/index.js +4940 -0
- package/dist/server/index.js.map +1 -0
- package/dist/types/server/app.d.ts +4 -0
- package/dist/types/server/auth/session.d.ts +18 -0
- package/dist/types/server/config.d.ts +31 -0
- package/dist/types/server/context.d.ts +24 -0
- package/dist/types/server/db/index.d.ts +13 -0
- package/dist/types/server/db/migrations/001_initial.d.ts +7 -0
- package/dist/types/server/db/node-sqlite.d.ts +6 -0
- package/dist/types/server/db/schema.d.ts +253 -0
- package/dist/types/server/index.d.ts +58 -0
- package/dist/types/server/lib/events.d.ts +86 -0
- package/dist/types/server/lib/http.d.ts +21 -0
- package/dist/types/server/lib/password.d.ts +3 -0
- package/dist/types/server/lib/schemas.d.ts +23 -0
- package/dist/types/server/lib/storage.d.ts +10 -0
- package/dist/types/server/lib/util.d.ts +18 -0
- package/dist/types/server/paths.d.ts +10 -0
- package/dist/types/server/routes/activities.d.ts +3 -0
- package/dist/types/server/routes/admin.d.ts +3 -0
- package/dist/types/server/routes/auth.d.ts +3 -0
- package/dist/types/server/routes/categories.d.ts +3 -0
- package/dist/types/server/routes/content.d.ts +4 -0
- package/dist/types/server/routes/courses.d.ts +5 -0
- package/dist/types/server/routes/files.d.ts +3 -0
- package/dist/types/server/routes/forums.d.ts +3 -0
- package/dist/types/server/routes/grades.d.ts +3 -0
- package/dist/types/server/routes/me.d.ts +3 -0
- package/dist/types/server/routes/quizzes.d.ts +3 -0
- package/dist/types/server/seed/demo.d.ts +19 -0
- package/dist/types/server/services/access.d.ts +24 -0
- package/dist/types/server/services/activity-types.d.ts +20 -0
- package/dist/types/server/services/courses.d.ts +7 -0
- package/dist/types/server/services/grades.d.ts +11 -0
- package/dist/types/server/services/notify.d.ts +10 -0
- package/dist/types/server/services/progress.d.ts +9 -0
- package/dist/types/server/services/quiz.d.ts +28 -0
- package/dist/types/server/services/serialize.d.ts +13 -0
- package/dist/types/server/services/settings.d.ts +5 -0
- package/dist/types/server/services/users.d.ts +15 -0
- package/dist/types/shared/constants.d.ts +11 -0
- package/dist/types/shared/permissions.d.ts +13 -0
- package/dist/types/shared/types.d.ts +452 -0
- package/dist/web/assets/ActivityEditor-LKK0d5Mb.js +3 -0
- package/dist/web/assets/ActivityPage-BhRtXLwW.js +1 -0
- package/dist/web/assets/AdminCoursesPage-BT9AQTuZ.js +1 -0
- package/dist/web/assets/AdminLayout-ChXLxrl_.js +1 -0
- package/dist/web/assets/AdminOverviewPage-BGsUzMXN.js +1 -0
- package/dist/web/assets/AdminSettingsPage-B4ZeIbVO.js +1 -0
- package/dist/web/assets/AdminUsersPage-BmBSnct8.js +1 -0
- package/dist/web/assets/AnnouncementsPage-KJUA3o7v.js +1 -0
- package/dist/web/assets/CalendarPage-DQdBEQN-.js +1 -0
- package/dist/web/assets/CatalogPage-CIFyefBY.js +1 -0
- package/dist/web/assets/CourseContentPage-CZEP3VMH.js +1 -0
- package/dist/web/assets/CourseLayout-CwpWuS7V.js +1 -0
- package/dist/web/assets/CourseSettingsPage-DwEIXO2s.js +1 -0
- package/dist/web/assets/CreateCoursePage-BDfIRStx.js +1 -0
- package/dist/web/assets/DiscussionPage-Dyt0qgUe.js +1 -0
- package/dist/web/assets/GradesPage-Brj-Wqu1.js +1 -0
- package/dist/web/assets/MyCoursesPage-GCdSHlYs.js +1 -0
- package/dist/web/assets/NotFoundPage-CJIpDg1F.js +1 -0
- package/dist/web/assets/NotificationsPage-Y3shIm5z.js +1 -0
- package/dist/web/assets/ParticipantsPage-OHnKj_8Z.js +1 -0
- package/dist/web/assets/ProfilePage-Dgj-HYPS.js +1 -0
- package/dist/web/assets/QuizAttemptPage-CiW3E3K0.js +1 -0
- package/dist/web/assets/QuizEditorPage-bT0jpSFE.js +3 -0
- package/dist/web/assets/SubmissionsPage-DXZGSqup.js +1 -0
- package/dist/web/assets/arrow-up-LHDup5m4.js +1 -0
- package/dist/web/assets/ban-D3Vsxg_g.js +1 -0
- package/dist/web/assets/chevron-left-D6IMQD6N.js +1 -0
- package/dist/web/assets/constants-DLDWTvvN.js +1 -0
- package/dist/web/assets/context-B5ZaAO90.js +1 -0
- package/dist/web/assets/copy-Bxxjq6zo.js +1 -0
- package/dist/web/assets/ellipsis-c2POIN-Y.js +1 -0
- package/dist/web/assets/frame-BjgJqbS9.js +1 -0
- package/dist/web/assets/hooks-BBARn-DA.js +1 -0
- package/dist/web/assets/index-DkBZ18Ts.js +50 -0
- package/dist/web/assets/index-WxCvsbJq.css +2 -0
- package/dist/web/assets/inter-cyrillic-ext-wght-normal-BOeWTOD4.woff2 +0 -0
- package/dist/web/assets/inter-cyrillic-wght-normal-DqGufNeO.woff2 +0 -0
- package/dist/web/assets/inter-greek-ext-wght-normal-DlzME5K_.woff2 +0 -0
- package/dist/web/assets/inter-greek-wght-normal-CkhJZR-_.woff2 +0 -0
- package/dist/web/assets/inter-latin-ext-wght-normal-DO1Apj_S.woff2 +0 -0
- package/dist/web/assets/inter-latin-wght-normal-Dx4kXJAl.woff2 +0 -0
- package/dist/web/assets/inter-vietnamese-wght-normal-CBcvBZtf.woff2 +0 -0
- package/dist/web/assets/key-round-B_KI-brR.js +1 -0
- package/dist/web/assets/library-3WG9oLCb.js +1 -0
- package/dist/web/assets/lock-BjbqwA_0.js +1 -0
- package/dist/web/assets/markdown-C1oaAmMK.js +83 -0
- package/dist/web/assets/message-square-text-fe24gbEU.js +1 -0
- package/dist/web/assets/misc-DvgDEI3I.js +1 -0
- package/dist/web/assets/pencil-p0GQmIMo.js +1 -0
- package/dist/web/assets/pin-DlYC3uec.js +1 -0
- package/dist/web/assets/send-mxSHcdcD.js +1 -0
- package/dist/web/assets/settings-DRKWzSHN.js +1 -0
- package/dist/web/assets/trophy-Cch2iF1m.js +1 -0
- package/dist/web/favicon.svg +12 -0
- package/dist/web/index.html +26 -0
- package/package.json +105 -4
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { MiddlewareHandler } from 'hono';
|
|
2
|
+
import type { AppContext, AppDeps, AppEnv } from '../context.js';
|
|
3
|
+
import type { UserRow } from '../db/schema.js';
|
|
4
|
+
export declare const SESSION_COOKIE = "coursekit_session";
|
|
5
|
+
/**
|
|
6
|
+
* Creates a session for the user, sets the session cookie and makes the user current
|
|
7
|
+
* for the rest of the request. Only a hash of the token is stored.
|
|
8
|
+
*/
|
|
9
|
+
export declare function startSession(c: AppContext, deps: AppDeps, user: UserRow, impersonatorId?: string | null): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Ends the current session. Pass `{ replacing: true }` when a new session is started right
|
|
12
|
+
* after (impersonation), so the response doesn't carry a redundant cookie deletion.
|
|
13
|
+
*/
|
|
14
|
+
export declare function endSession(c: AppContext, deps: AppDeps, options?: {
|
|
15
|
+
replacing?: boolean;
|
|
16
|
+
}): Promise<void>;
|
|
17
|
+
/** Resolves the signed-in user (if any) from the session cookie. Sessions slide forward when used. */
|
|
18
|
+
export declare function sessionMiddleware(deps: AppDeps): MiddlewareHandler<AppEnv>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface CoursekitOptions {
|
|
2
|
+
/** `sqlite://./data/coursekit.db` (default), `sqlite::memory:` or a `postgres://` URL. */
|
|
3
|
+
databaseUrl?: string;
|
|
4
|
+
/** Folder for uploaded files and the default SQLite database. Defaults to `./data`. */
|
|
5
|
+
dataDir?: string;
|
|
6
|
+
port?: number;
|
|
7
|
+
host?: string;
|
|
8
|
+
/** Public URL of the site. An https URL turns on secure cookies. */
|
|
9
|
+
publicUrl?: string;
|
|
10
|
+
/** Maximum upload size in megabytes. Defaults to 50. */
|
|
11
|
+
maxUploadMb?: number;
|
|
12
|
+
/** Folder with the built web UI. `false` serves the API only. */
|
|
13
|
+
webDir?: string | false;
|
|
14
|
+
/** Run pending database migrations on startup. Defaults to true. */
|
|
15
|
+
migrate?: boolean;
|
|
16
|
+
/** Log each request to the console. */
|
|
17
|
+
logRequests?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface ResolvedConfig {
|
|
20
|
+
databaseUrl: string;
|
|
21
|
+
dataDir: string;
|
|
22
|
+
port: number;
|
|
23
|
+
host: string;
|
|
24
|
+
publicUrl: string | null;
|
|
25
|
+
maxUploadBytes: number;
|
|
26
|
+
webDir: string | null;
|
|
27
|
+
migrate: boolean;
|
|
28
|
+
logRequests: boolean;
|
|
29
|
+
secureCookies: boolean;
|
|
30
|
+
}
|
|
31
|
+
export declare function resolveConfig(options?: CoursekitOptions, env?: NodeJS.ProcessEnv): ResolvedConfig;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import type { ResolvedConfig } from './config.js';
|
|
3
|
+
import type { DB, DatabaseKind } from './db/index.js';
|
|
4
|
+
import type { SessionRow, UserRow } from './db/schema.js';
|
|
5
|
+
import type { EventBus } from './lib/events.js';
|
|
6
|
+
import type { FileStorage } from './lib/storage.js';
|
|
7
|
+
/** Everything a route needs. Created once per Coursekit instance. */
|
|
8
|
+
export interface AppDeps {
|
|
9
|
+
db: DB;
|
|
10
|
+
dbKind: DatabaseKind;
|
|
11
|
+
config: ResolvedConfig;
|
|
12
|
+
events: EventBus;
|
|
13
|
+
storage: FileStorage;
|
|
14
|
+
version: string;
|
|
15
|
+
}
|
|
16
|
+
export type AppEnv = {
|
|
17
|
+
Variables: {
|
|
18
|
+
user: UserRow | null;
|
|
19
|
+
session: SessionRow | null;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export type AppContext = Context<AppEnv>;
|
|
23
|
+
export declare function requireUser(c: AppContext): UserRow;
|
|
24
|
+
export declare function requireAdmin(c: AppContext): UserRow;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Kysely } from 'kysely';
|
|
2
|
+
import { type Migration, type MigrationResult } from 'kysely/migration';
|
|
3
|
+
import type { Database } from './schema.js';
|
|
4
|
+
export type DB = Kysely<Database>;
|
|
5
|
+
export type DatabaseKind = 'sqlite' | 'postgres';
|
|
6
|
+
/** Migrations are registered in code so they survive bundling. Append new ones; never edit old ones. */
|
|
7
|
+
export declare const migrations: Record<string, Migration>;
|
|
8
|
+
export declare function createDatabase(url: string): Promise<{
|
|
9
|
+
db: DB;
|
|
10
|
+
kind: DatabaseKind;
|
|
11
|
+
}>;
|
|
12
|
+
/** Runs all pending migrations. Migrations use explicit snake_case names, so plugins are disabled. */
|
|
13
|
+
export declare function migrateToLatest(db: DB): Promise<MigrationResult[]>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
/**
|
|
3
|
+
* Initial schema. Uses only portable column types (text, integer, double precision)
|
|
4
|
+
* 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,6 @@
|
|
|
1
|
+
import type { SqliteDatabase } from 'kysely';
|
|
2
|
+
/**
|
|
3
|
+
* Adapts Node's built-in `node:sqlite` module to the interface Kysely's SqliteDialect expects,
|
|
4
|
+
* so Coursekit runs on SQLite with no native dependencies.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createNodeSqliteDatabase(filename: string): SqliteDatabase;
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kysely table types. Columns are snake_case in the database and camelCase here
|
|
3
|
+
* (Kysely's CamelCasePlugin maps between them). Booleans are stored as 0/1 integers,
|
|
4
|
+
* timestamps as ISO-8601 strings and structured values as JSON text, which keeps the
|
|
5
|
+
* schema portable between SQLite and PostgreSQL.
|
|
6
|
+
*/
|
|
7
|
+
import type { Insertable, Selectable } from 'kysely';
|
|
8
|
+
import type { ActivityType, CompletionMode, CourseRole, CourseVisibility, EnrolmentMethod, QuestionType, SiteRole, UserStatus } from '../../shared/types.js';
|
|
9
|
+
export interface SettingsTable {
|
|
10
|
+
key: string;
|
|
11
|
+
value: string;
|
|
12
|
+
}
|
|
13
|
+
export interface UsersTable {
|
|
14
|
+
id: string;
|
|
15
|
+
email: string;
|
|
16
|
+
name: string;
|
|
17
|
+
passwordHash: string | null;
|
|
18
|
+
role: SiteRole;
|
|
19
|
+
avatarUrl: string | null;
|
|
20
|
+
bio: string | null;
|
|
21
|
+
status: UserStatus;
|
|
22
|
+
lastLoginAt: string | null;
|
|
23
|
+
createdAt: string;
|
|
24
|
+
updatedAt: string;
|
|
25
|
+
}
|
|
26
|
+
export interface SessionsTable {
|
|
27
|
+
id: string;
|
|
28
|
+
userId: string;
|
|
29
|
+
impersonatorId: string | null;
|
|
30
|
+
expiresAt: string;
|
|
31
|
+
createdAt: string;
|
|
32
|
+
userAgent: string | null;
|
|
33
|
+
}
|
|
34
|
+
export interface CategoriesTable {
|
|
35
|
+
id: string;
|
|
36
|
+
name: string;
|
|
37
|
+
slug: string;
|
|
38
|
+
description: string;
|
|
39
|
+
sortOrder: number;
|
|
40
|
+
createdAt: string;
|
|
41
|
+
}
|
|
42
|
+
export interface CoursesTable {
|
|
43
|
+
id: string;
|
|
44
|
+
slug: string;
|
|
45
|
+
title: string;
|
|
46
|
+
summary: string;
|
|
47
|
+
description: string;
|
|
48
|
+
categoryId: string | null;
|
|
49
|
+
coverColor: string;
|
|
50
|
+
coverImageUrl: string | null;
|
|
51
|
+
visibility: CourseVisibility;
|
|
52
|
+
enrolment: EnrolmentMethod;
|
|
53
|
+
enrolmentKey: string | null;
|
|
54
|
+
startDate: string | null;
|
|
55
|
+
endDate: string | null;
|
|
56
|
+
createdBy: string | null;
|
|
57
|
+
createdAt: string;
|
|
58
|
+
updatedAt: string;
|
|
59
|
+
}
|
|
60
|
+
export interface EnrolmentsTable {
|
|
61
|
+
id: string;
|
|
62
|
+
courseId: string;
|
|
63
|
+
userId: string;
|
|
64
|
+
role: CourseRole;
|
|
65
|
+
status: 'active' | 'suspended';
|
|
66
|
+
lastAccessAt: string | null;
|
|
67
|
+
createdAt: string;
|
|
68
|
+
}
|
|
69
|
+
export interface SectionsTable {
|
|
70
|
+
id: string;
|
|
71
|
+
courseId: string;
|
|
72
|
+
title: string;
|
|
73
|
+
summary: string;
|
|
74
|
+
position: number;
|
|
75
|
+
visible: number;
|
|
76
|
+
createdAt: string;
|
|
77
|
+
}
|
|
78
|
+
export interface ActivitiesTable {
|
|
79
|
+
id: string;
|
|
80
|
+
courseId: string;
|
|
81
|
+
sectionId: string;
|
|
82
|
+
type: ActivityType;
|
|
83
|
+
title: string;
|
|
84
|
+
description: string;
|
|
85
|
+
position: number;
|
|
86
|
+
visible: number;
|
|
87
|
+
/** JSON, shape depends on `type`. */
|
|
88
|
+
settings: string;
|
|
89
|
+
dueAt: string | null;
|
|
90
|
+
maxGrade: number | null;
|
|
91
|
+
completion: CompletionMode;
|
|
92
|
+
createdBy: string | null;
|
|
93
|
+
createdAt: string;
|
|
94
|
+
updatedAt: string;
|
|
95
|
+
}
|
|
96
|
+
export interface CompletionsTable {
|
|
97
|
+
activityId: string;
|
|
98
|
+
userId: string;
|
|
99
|
+
courseId: string;
|
|
100
|
+
completedAt: string;
|
|
101
|
+
}
|
|
102
|
+
export interface FilesTable {
|
|
103
|
+
id: string;
|
|
104
|
+
ownerId: string | null;
|
|
105
|
+
courseId: string | null;
|
|
106
|
+
context: 'course' | 'activity' | 'submission' | 'avatar' | 'post';
|
|
107
|
+
name: string;
|
|
108
|
+
mime: string;
|
|
109
|
+
size: number;
|
|
110
|
+
storageKey: string;
|
|
111
|
+
createdAt: string;
|
|
112
|
+
}
|
|
113
|
+
export interface SubmissionsTable {
|
|
114
|
+
id: string;
|
|
115
|
+
activityId: string;
|
|
116
|
+
courseId: string;
|
|
117
|
+
userId: string;
|
|
118
|
+
text: string | null;
|
|
119
|
+
/** JSON array of file ids. */
|
|
120
|
+
fileIds: string;
|
|
121
|
+
submittedAt: string;
|
|
122
|
+
createdAt: string;
|
|
123
|
+
updatedAt: string;
|
|
124
|
+
}
|
|
125
|
+
export interface GradesTable {
|
|
126
|
+
activityId: string;
|
|
127
|
+
userId: string;
|
|
128
|
+
courseId: string;
|
|
129
|
+
score: number | null;
|
|
130
|
+
feedback: string | null;
|
|
131
|
+
gradedBy: string | null;
|
|
132
|
+
gradedAt: string | null;
|
|
133
|
+
updatedAt: string;
|
|
134
|
+
}
|
|
135
|
+
export interface QuestionsTable {
|
|
136
|
+
id: string;
|
|
137
|
+
activityId: string;
|
|
138
|
+
type: QuestionType;
|
|
139
|
+
prompt: string;
|
|
140
|
+
points: number;
|
|
141
|
+
/** JSON array of { id, text, correct }. */
|
|
142
|
+
options: string;
|
|
143
|
+
/** JSON array of strings. */
|
|
144
|
+
acceptedAnswers: string;
|
|
145
|
+
tolerance: number | null;
|
|
146
|
+
explanation: string | null;
|
|
147
|
+
position: number;
|
|
148
|
+
}
|
|
149
|
+
export interface QuizAttemptsTable {
|
|
150
|
+
id: string;
|
|
151
|
+
activityId: string;
|
|
152
|
+
courseId: string;
|
|
153
|
+
userId: string;
|
|
154
|
+
attemptNumber: number;
|
|
155
|
+
status: 'in_progress' | 'finished';
|
|
156
|
+
/** JSON array of question ids. */
|
|
157
|
+
questionOrder: string;
|
|
158
|
+
/** JSON object keyed by question id. */
|
|
159
|
+
answers: string;
|
|
160
|
+
/** JSON object keyed by question id, set when finished. */
|
|
161
|
+
results: string | null;
|
|
162
|
+
score: number | null;
|
|
163
|
+
maxScore: number;
|
|
164
|
+
startedAt: string;
|
|
165
|
+
deadlineAt: string | null;
|
|
166
|
+
finishedAt: string | null;
|
|
167
|
+
}
|
|
168
|
+
export interface DiscussionsTable {
|
|
169
|
+
id: string;
|
|
170
|
+
activityId: string;
|
|
171
|
+
courseId: string;
|
|
172
|
+
userId: string;
|
|
173
|
+
title: string;
|
|
174
|
+
pinned: number;
|
|
175
|
+
locked: number;
|
|
176
|
+
replyCount: number;
|
|
177
|
+
lastPostAt: string;
|
|
178
|
+
createdAt: string;
|
|
179
|
+
}
|
|
180
|
+
export interface PostsTable {
|
|
181
|
+
id: string;
|
|
182
|
+
discussionId: string;
|
|
183
|
+
courseId: string;
|
|
184
|
+
userId: string;
|
|
185
|
+
parentId: string | null;
|
|
186
|
+
body: string;
|
|
187
|
+
createdAt: string;
|
|
188
|
+
updatedAt: string;
|
|
189
|
+
}
|
|
190
|
+
export interface AnnouncementsTable {
|
|
191
|
+
id: string;
|
|
192
|
+
courseId: string;
|
|
193
|
+
userId: string;
|
|
194
|
+
title: string;
|
|
195
|
+
body: string;
|
|
196
|
+
createdAt: string;
|
|
197
|
+
}
|
|
198
|
+
export interface NotificationsTable {
|
|
199
|
+
id: string;
|
|
200
|
+
userId: string;
|
|
201
|
+
type: string;
|
|
202
|
+
title: string;
|
|
203
|
+
body: string;
|
|
204
|
+
link: string | null;
|
|
205
|
+
readAt: string | null;
|
|
206
|
+
createdAt: string;
|
|
207
|
+
}
|
|
208
|
+
export interface CalendarEventsTable {
|
|
209
|
+
id: string;
|
|
210
|
+
courseId: string | null;
|
|
211
|
+
userId: string | null;
|
|
212
|
+
title: string;
|
|
213
|
+
description: string | null;
|
|
214
|
+
startsAt: string;
|
|
215
|
+
endsAt: string | null;
|
|
216
|
+
createdBy: string;
|
|
217
|
+
createdAt: string;
|
|
218
|
+
}
|
|
219
|
+
export interface Database {
|
|
220
|
+
settings: SettingsTable;
|
|
221
|
+
users: UsersTable;
|
|
222
|
+
sessions: SessionsTable;
|
|
223
|
+
categories: CategoriesTable;
|
|
224
|
+
courses: CoursesTable;
|
|
225
|
+
enrolments: EnrolmentsTable;
|
|
226
|
+
sections: SectionsTable;
|
|
227
|
+
activities: ActivitiesTable;
|
|
228
|
+
completions: CompletionsTable;
|
|
229
|
+
files: FilesTable;
|
|
230
|
+
submissions: SubmissionsTable;
|
|
231
|
+
grades: GradesTable;
|
|
232
|
+
questions: QuestionsTable;
|
|
233
|
+
quizAttempts: QuizAttemptsTable;
|
|
234
|
+
discussions: DiscussionsTable;
|
|
235
|
+
posts: PostsTable;
|
|
236
|
+
announcements: AnnouncementsTable;
|
|
237
|
+
notifications: NotificationsTable;
|
|
238
|
+
calendarEvents: CalendarEventsTable;
|
|
239
|
+
}
|
|
240
|
+
export type UserRow = Selectable<UsersTable>;
|
|
241
|
+
export type SessionRow = Selectable<SessionsTable>;
|
|
242
|
+
export type CourseRow = Selectable<CoursesTable>;
|
|
243
|
+
export type EnrolmentRow = Selectable<EnrolmentsTable>;
|
|
244
|
+
export type SectionRow = Selectable<SectionsTable>;
|
|
245
|
+
export type ActivityRow = Selectable<ActivitiesTable>;
|
|
246
|
+
export type FileRow = Selectable<FilesTable>;
|
|
247
|
+
export type SubmissionRow = Selectable<SubmissionsTable>;
|
|
248
|
+
export type GradeRow = Selectable<GradesTable>;
|
|
249
|
+
export type QuestionRow = Selectable<QuestionsTable>;
|
|
250
|
+
export type QuizAttemptRow = Selectable<QuizAttemptsTable>;
|
|
251
|
+
export type DiscussionRow = Selectable<DiscussionsTable>;
|
|
252
|
+
export type PostRow = Selectable<PostsTable>;
|
|
253
|
+
export type NewActivity = Insertable<ActivitiesTable>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coursekit: an open-source learning management system for Node.js.
|
|
3
|
+
*
|
|
4
|
+
* ```ts
|
|
5
|
+
* import { createCoursekit } from 'coursekit-lms';
|
|
6
|
+
*
|
|
7
|
+
* const lms = await createCoursekit({ databaseUrl: 'sqlite://./data/lms.db' });
|
|
8
|
+
* lms.events.on('grade.updated', (e) => console.log('graded', e));
|
|
9
|
+
* await lms.listen(3000);
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
import type { IncomingMessage, Server, ServerResponse } from 'node:http';
|
|
13
|
+
import type { Hono } from 'hono';
|
|
14
|
+
import { type CoursekitOptions, type ResolvedConfig } from './config.js';
|
|
15
|
+
import type { AppEnv } from './context.js';
|
|
16
|
+
import { type DB, type DatabaseKind } from './db/index.js';
|
|
17
|
+
import type { UserRow } from './db/schema.js';
|
|
18
|
+
import { EventBus } from './lib/events.js';
|
|
19
|
+
import { type FileStorage } from './lib/storage.js';
|
|
20
|
+
import { type SeedDemoOptions, type SeedDemoResult } from './seed/demo.js';
|
|
21
|
+
import { type CreateUserInput } from './services/users.js';
|
|
22
|
+
export interface CreateCoursekitOptions extends CoursekitOptions {
|
|
23
|
+
/** Custom file storage (S3, R2, ...). Defaults to `<dataDir>/uploads` on disk. */
|
|
24
|
+
storage?: FileStorage;
|
|
25
|
+
}
|
|
26
|
+
export interface Coursekit {
|
|
27
|
+
/** The Hono app. Mount it in another Hono app with `app.route('/', lms.app)`. */
|
|
28
|
+
app: Hono<AppEnv>;
|
|
29
|
+
/** Web-standard fetch handler (Bun, Deno, Cloudflare-style runtimes, tests). */
|
|
30
|
+
fetch: (request: Request) => Response | Promise<Response>;
|
|
31
|
+
/** Node `(req, res)` handler for `http.createServer`, Express or Fastify (mount at the root path). */
|
|
32
|
+
handler: (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
33
|
+
db: DB;
|
|
34
|
+
dbKind: DatabaseKind;
|
|
35
|
+
events: EventBus;
|
|
36
|
+
storage: FileStorage;
|
|
37
|
+
config: ResolvedConfig;
|
|
38
|
+
version: string;
|
|
39
|
+
/** Start an HTTP server. Resolves once it is listening. */
|
|
40
|
+
listen(port?: number, host?: string): Promise<{
|
|
41
|
+
server: Server;
|
|
42
|
+
port: number;
|
|
43
|
+
url: string;
|
|
44
|
+
}>;
|
|
45
|
+
migrate(): Promise<void>;
|
|
46
|
+
createUser(input: CreateUserInput): Promise<UserRow>;
|
|
47
|
+
seedDemo(options?: SeedDemoOptions): Promise<SeedDemoResult>;
|
|
48
|
+
close(): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
export declare function createCoursekit(options?: CreateCoursekitOptions): Promise<Coursekit>;
|
|
51
|
+
export { resolveConfig, type CoursekitOptions, type ResolvedConfig } from './config.js';
|
|
52
|
+
export { createApp } from './app.js';
|
|
53
|
+
export { EventBus, type CoursekitEvents, type EventName } from './lib/events.js';
|
|
54
|
+
export { createLocalStorage, type FileStorage } from './lib/storage.js';
|
|
55
|
+
export { activityTypes, type ActivityTypeDefinition } from './services/activity-types.js';
|
|
56
|
+
export type { Database } from './db/schema.js';
|
|
57
|
+
export type * from '../shared/types.js';
|
|
58
|
+
export { COURSE_CAPABILITIES, ROLE_CAPABILITIES, getCourseCapabilities, type CourseCapability } from '../shared/permissions.js';
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { ActivityType, CourseRole, SiteRole } from '../../shared/types.js';
|
|
2
|
+
/** Events emitted by Coursekit. Subscribe with `coursekit.events.on(...)` to integrate with other systems. */
|
|
3
|
+
export interface CoursekitEvents {
|
|
4
|
+
'user.created': {
|
|
5
|
+
userId: string;
|
|
6
|
+
email: string;
|
|
7
|
+
role: SiteRole;
|
|
8
|
+
};
|
|
9
|
+
'user.login': {
|
|
10
|
+
userId: string;
|
|
11
|
+
};
|
|
12
|
+
'course.created': {
|
|
13
|
+
courseId: string;
|
|
14
|
+
userId: string;
|
|
15
|
+
};
|
|
16
|
+
'course.updated': {
|
|
17
|
+
courseId: string;
|
|
18
|
+
};
|
|
19
|
+
'course.deleted': {
|
|
20
|
+
courseId: string;
|
|
21
|
+
};
|
|
22
|
+
'enrolment.created': {
|
|
23
|
+
courseId: string;
|
|
24
|
+
userId: string;
|
|
25
|
+
role: CourseRole;
|
|
26
|
+
};
|
|
27
|
+
'enrolment.deleted': {
|
|
28
|
+
courseId: string;
|
|
29
|
+
userId: string;
|
|
30
|
+
};
|
|
31
|
+
'activity.created': {
|
|
32
|
+
activityId: string;
|
|
33
|
+
courseId: string;
|
|
34
|
+
type: ActivityType;
|
|
35
|
+
};
|
|
36
|
+
'activity.completed': {
|
|
37
|
+
activityId: string;
|
|
38
|
+
courseId: string;
|
|
39
|
+
userId: string;
|
|
40
|
+
};
|
|
41
|
+
'submission.submitted': {
|
|
42
|
+
activityId: string;
|
|
43
|
+
courseId: string;
|
|
44
|
+
userId: string;
|
|
45
|
+
submissionId: string;
|
|
46
|
+
};
|
|
47
|
+
'grade.updated': {
|
|
48
|
+
activityId: string;
|
|
49
|
+
courseId: string;
|
|
50
|
+
userId: string;
|
|
51
|
+
score: number | null;
|
|
52
|
+
gradedBy: string | null;
|
|
53
|
+
};
|
|
54
|
+
'quiz.attempt.finished': {
|
|
55
|
+
attemptId: string;
|
|
56
|
+
activityId: string;
|
|
57
|
+
courseId: string;
|
|
58
|
+
userId: string;
|
|
59
|
+
score: number;
|
|
60
|
+
maxScore: number;
|
|
61
|
+
};
|
|
62
|
+
'forum.post.created': {
|
|
63
|
+
postId: string;
|
|
64
|
+
discussionId: string;
|
|
65
|
+
courseId: string;
|
|
66
|
+
userId: string;
|
|
67
|
+
};
|
|
68
|
+
'announcement.created': {
|
|
69
|
+
announcementId: string;
|
|
70
|
+
courseId: string;
|
|
71
|
+
userId: string;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export type EventName = keyof CoursekitEvents;
|
|
75
|
+
type Handler<T> = (payload: T) => void | Promise<void>;
|
|
76
|
+
type AnyHandler = <K extends EventName>(event: K, payload: CoursekitEvents[K]) => void | Promise<void>;
|
|
77
|
+
export declare class EventBus {
|
|
78
|
+
#private;
|
|
79
|
+
/** Subscribe to an event. Returns an unsubscribe function. */
|
|
80
|
+
on<K extends EventName>(event: K, handler: Handler<CoursekitEvents[K]>): () => void;
|
|
81
|
+
/** Subscribe to every event, e.g. to forward them to a webhook. */
|
|
82
|
+
onAny(handler: AnyHandler): () => void;
|
|
83
|
+
/** Handlers run asynchronously and never break the request that emitted the event. */
|
|
84
|
+
emit<K extends EventName>(event: K, payload: CoursekitEvents[K]): void;
|
|
85
|
+
}
|
|
86
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import type { z } from 'zod';
|
|
3
|
+
export interface ErrorIssue {
|
|
4
|
+
path: string;
|
|
5
|
+
message: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class ApiError extends Error {
|
|
8
|
+
readonly status: number;
|
|
9
|
+
readonly code: string;
|
|
10
|
+
readonly issues?: ErrorIssue[];
|
|
11
|
+
constructor(status: number, message: string, code?: string, issues?: ErrorIssue[]);
|
|
12
|
+
}
|
|
13
|
+
export declare const badRequest: (message: string, issues?: ErrorIssue[]) => ApiError;
|
|
14
|
+
export declare const unauthorized: (message?: string) => ApiError;
|
|
15
|
+
export declare const forbidden: (message?: string) => ApiError;
|
|
16
|
+
export declare const notFound: (what?: string) => ApiError;
|
|
17
|
+
export declare const conflict: (message: string) => ApiError;
|
|
18
|
+
export declare function parse<S extends z.ZodType>(schema: S, data: unknown): z.output<S>;
|
|
19
|
+
/** Parses and validates a JSON request body. */
|
|
20
|
+
export declare function readBody<S extends z.ZodType>(c: Context, schema: S): Promise<z.output<S>>;
|
|
21
|
+
export declare function readQuery<S extends z.ZodType>(c: Context, schema: S): z.output<S>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const nameSchema: z.ZodString;
|
|
3
|
+
export declare const emailSchema: z.ZodEmail;
|
|
4
|
+
export declare const passwordSchema: z.ZodString;
|
|
5
|
+
export declare const siteRoleSchema: z.ZodEnum<{
|
|
6
|
+
admin: "admin";
|
|
7
|
+
instructor: "instructor";
|
|
8
|
+
student: "student";
|
|
9
|
+
}>;
|
|
10
|
+
export declare const courseRoleSchema: z.ZodEnum<{
|
|
11
|
+
assistant: "assistant";
|
|
12
|
+
student: "student";
|
|
13
|
+
teacher: "teacher";
|
|
14
|
+
}>;
|
|
15
|
+
/** Any date string `Date` understands; stored as a normalized ISO timestamp. */
|
|
16
|
+
export declare const isoDateSchema: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
17
|
+
export declare const markdownSchema: (max?: number) => z.ZodString;
|
|
18
|
+
export declare const pageSchema: {
|
|
19
|
+
page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
20
|
+
pageSize: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
21
|
+
};
|
|
22
|
+
/** Avatar and cover images must be uploaded files or https URLs. */
|
|
23
|
+
export declare const imageUrlSchema: z.ZodString;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where uploaded files live. The default writes to the local disk; implement this
|
|
3
|
+
* interface to store files in S3, R2, GCS and so on.
|
|
4
|
+
*/
|
|
5
|
+
export interface FileStorage {
|
|
6
|
+
put(key: string, data: Uint8Array, mime: string): Promise<void>;
|
|
7
|
+
get(key: string): Promise<ReadableStream<Uint8Array> | null>;
|
|
8
|
+
delete(key: string): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export declare function createLocalStorage(root: string): FileStorage;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Random, URL-safe identifier (80 bits by default). */
|
|
2
|
+
export declare function newId(length?: number): string;
|
|
3
|
+
export declare function randomToken(bytes?: number): string;
|
|
4
|
+
export declare function sha256(value: string): string;
|
|
5
|
+
export declare function now(): string;
|
|
6
|
+
export declare function addDays(date: Date | string, days: number): Date;
|
|
7
|
+
export declare function slugify(input: string, fallback?: string): string;
|
|
8
|
+
export declare function parseJson<T>(value: string | null | undefined, fallback: T): T;
|
|
9
|
+
export declare function toBool(value: number | boolean | null | undefined): boolean;
|
|
10
|
+
/** Postgres returns bigint/numeric aggregates as strings; SQLite returns numbers. */
|
|
11
|
+
export declare function num(value: unknown): number;
|
|
12
|
+
export declare function round(value: number, digits?: number): number;
|
|
13
|
+
export declare function excerpt(markdown: string, length?: number): string;
|
|
14
|
+
/**
|
|
15
|
+
* Pattern for a portable, case-insensitive "contains" search: compare against lower(column).
|
|
16
|
+
* (SQLite has no default LIKE escape character, so wildcards in the query are left as-is.)
|
|
17
|
+
*/
|
|
18
|
+
export declare function likePattern(q: string): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file sits two levels below the package root in source (src/server) and, once bundled,
|
|
3
|
+
* every entry point sits two levels below it too (dist/server, dist/cli).
|
|
4
|
+
*/
|
|
5
|
+
export declare const packageRoot: string;
|
|
6
|
+
export declare function packageVersion(): string;
|
|
7
|
+
/** The npm package name (the installed command is always `coursekit`). */
|
|
8
|
+
export declare function packageName(): string;
|
|
9
|
+
/** Location of the prebuilt web UI, or null when it has not been built (e.g. in development). */
|
|
10
|
+
export declare function defaultWebDir(): string | null;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import { type AppDeps, type AppEnv } from '../context.js';
|
|
3
|
+
import type { ActivityRow } from '../db/schema.js';
|
|
4
|
+
export declare function activityMeta(a: ActivityRow, counts: Map<string, number>): string | null;
|
|
5
|
+
export declare function courseRoutes(deps: AppDeps): Hono<AppEnv, import("hono/types").BlankSchema, "/">;
|