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.
- package/CHANGELOG.md +76 -0
- package/README.md +127 -26
- package/dist/cli/index.js +7139 -1633
- package/dist/cli/index.js.map +1 -1
- package/dist/server/index.js +7128 -1655
- package/dist/server/index.js.map +1 -1
- package/dist/types/server/config.d.ts +4 -0
- package/dist/types/server/db/migrations/002_email.d.ts +8 -0
- package/dist/types/server/db/migrations/003_groups_cohorts.d.ts +7 -0
- package/dist/types/server/db/migrations/004_completion_badges.d.ts +8 -0
- package/dist/types/server/db/migrations/005_question_bank.d.ts +11 -0
- package/dist/types/server/db/migrations/006_grade_categories.d.ts +11 -0
- package/dist/types/server/db/schema-completion.d.ts +79 -0
- package/dist/types/server/db/schema.d.ts +165 -5
- package/dist/types/server/index.d.ts +7 -0
- package/dist/types/server/lib/events.d.ts +105 -0
- package/dist/types/server/routes/badges.d.ts +4 -0
- package/dist/types/server/routes/certificates.d.ts +3 -0
- package/dist/types/server/routes/cohorts.d.ts +6 -0
- package/dist/types/server/routes/completion.d.ts +4 -0
- package/dist/types/server/routes/email.d.ts +13 -0
- package/dist/types/server/routes/grade-categories.d.ts +4 -0
- package/dist/types/server/routes/groups.d.ts +4 -0
- package/dist/types/server/routes/question-bank.d.ts +4 -0
- package/dist/types/server/seed/demo-completion.d.ts +2 -0
- package/dist/types/server/seed/demo-email.d.ts +2 -0
- package/dist/types/server/seed/demo-grade-categories.d.ts +6 -0
- package/dist/types/server/seed/demo-groups.d.ts +6 -0
- package/dist/types/server/seed/demo-question-bank.d.ts +20 -0
- package/dist/types/server/services/badges.d.ts +39 -0
- package/dist/types/server/services/certificates.d.ts +42 -0
- package/dist/types/server/services/cohorts.d.ts +64 -0
- package/dist/types/server/services/completion.d.ts +63 -0
- package/dist/types/server/services/course-total.d.ts +107 -0
- package/dist/types/server/services/email/config.d.ts +55 -0
- package/dist/types/server/services/email/digests.d.ts +57 -0
- package/dist/types/server/services/email/outbox.d.ts +61 -0
- package/dist/types/server/services/email/preferences.d.ts +25 -0
- package/dist/types/server/services/email/service.d.ts +116 -0
- package/dist/types/server/services/email/templates.d.ts +74 -0
- package/dist/types/server/services/email/tokens.d.ts +11 -0
- package/dist/types/server/services/email/transport.d.ts +29 -0
- package/dist/types/server/services/enrolments.d.ts +32 -0
- package/dist/types/server/services/grade-categories.d.ts +31 -0
- package/dist/types/server/services/gradebook.d.ts +18 -0
- package/dist/types/server/services/groups.d.ts +90 -0
- package/dist/types/server/services/notify.d.ts +4 -1
- package/dist/types/server/services/question-bank.d.ts +53 -0
- package/dist/types/server/services/question-types.d.ts +146 -0
- package/dist/types/server/services/quiz-slots.d.ts +33 -0
- package/dist/types/server/services/quiz.d.ts +45 -14
- package/dist/types/shared/completion.d.ts +214 -0
- package/dist/types/shared/email.d.ts +117 -0
- package/dist/types/shared/grades.d.ts +18 -0
- package/dist/types/shared/groups.d.ts +17 -0
- package/dist/types/shared/permissions.d.ts +1 -1
- package/dist/types/shared/types.d.ts +268 -2
- package/dist/web/assets/{ActivityEditor-BVSZUV8l.js → ActivityEditor-BNG3aTQa.js} +2 -2
- package/dist/web/assets/ActivityPage-i0XHYD2Q.js +1 -0
- package/dist/web/assets/AdminBadgesPage-DvpxIg1P.js +1 -0
- package/dist/web/assets/AdminCohortsPage-B5PWBkjp.js +3 -0
- package/dist/web/assets/AdminCoursesPage-Dm1ECbS-.js +1 -0
- package/dist/web/assets/AdminEmailPage-D3E_Db1_.js +1 -0
- package/dist/web/assets/AdminLayout-BVeduyCQ.js +1 -0
- package/dist/web/assets/{AdminOverviewPage-DnTrdGbr.js → AdminOverviewPage-BaCKvhgr.js} +1 -1
- package/dist/web/assets/{AdminSettingsPage-B82cX8xU.js → AdminSettingsPage-B5Ag5K15.js} +1 -1
- package/dist/web/assets/AdminUsersPage-BVCG65EK.js +1 -0
- package/dist/web/assets/{AnnouncementsPage-BKW30k0Z.js → AnnouncementsPage-C0OAzyvW.js} +1 -1
- package/dist/web/assets/BadgePage-B3Ecudas.js +1 -0
- package/dist/web/assets/CalendarPage-CEks5F4m.js +1 -0
- package/dist/web/assets/{CatalogPage-BiMgSSBR.js → CatalogPage-e7lVtwUN.js} +1 -1
- package/dist/web/assets/CertificatePage-_eSGt8R-.js +9 -0
- package/dist/web/assets/CompletionPage-Dxp-ulA_.js +1 -0
- package/dist/web/assets/CourseBadgesPage-Vi3P1Lnc.js +1 -0
- package/dist/web/assets/CourseContentPage-IFlhVsO5.js +1 -0
- package/dist/web/assets/CourseLayout-BqwXol8L.js +1 -0
- package/dist/web/assets/CourseSettingsPage-BIagLirb.js +1 -0
- package/dist/web/assets/CreateCoursePage-BBcdiTtz.js +1 -0
- package/dist/web/assets/{DiscussionPage-CWwVpFQV.js → DiscussionPage-C23QoCSw.js} +1 -1
- package/dist/web/assets/GradebookSetupPage-a5GH4xIk.js +1 -0
- package/dist/web/assets/GradesPage-CY6MtJxs.js +1 -0
- package/dist/web/assets/GroupsPage-DS3HFeC4.js +1 -0
- package/dist/web/assets/{MyCoursesPage-Dd-Oaygv.js → MyCoursesPage-Ckj-1SCA.js} +1 -1
- package/dist/web/assets/{NotFoundPage-BRquC7-l.js → NotFoundPage-BmwVsGAy.js} +1 -1
- package/dist/web/assets/NotificationsPage-DBRM37F1.js +1 -0
- package/dist/web/assets/ParticipantsPage-DV4Mjfxo.js +1 -0
- package/dist/web/assets/ProfilePage-BqG55_02.js +1 -0
- package/dist/web/assets/QuestionAnswer-CJIoWSz2.js +1 -0
- package/dist/web/assets/QuestionBankPage-BkI44c4K.js +1 -0
- package/dist/web/assets/QuizAttemptPage-DQVfbLKI.js +1 -0
- package/dist/web/assets/QuizEditorPage-muk-KVG1.js +1 -0
- package/dist/web/assets/SubmissionsPage-Dx97JOzE.js +1 -0
- package/dist/web/assets/UnsubscribePage-BPLiTiaG.js +1 -0
- package/dist/web/assets/VerifyCertificatePage-Cw9iXN3C.js +1 -0
- package/dist/web/assets/achievements-DaIfUTKU.js +1 -0
- package/dist/web/assets/{arrow-up-LHDup5m4.js → arrow-up-lI30bvj5.js} +1 -1
- package/dist/web/assets/badge-art-QPo-pYql.js +1 -0
- package/dist/web/assets/badge-card-ByT0wR6q.js +1 -0
- package/dist/web/assets/badge-dialog-p2zTk4h0.js +1 -0
- package/dist/web/assets/{ban-D3Vsxg_g.js → ban-DEiI8npI.js} +1 -1
- package/dist/web/assets/bank-S3XEFPfe.js +3 -0
- package/dist/web/assets/bell-off-Bo2RE0kn.js +1 -0
- package/dist/web/assets/calendar-range-Cfg-P4Md.js +1 -0
- package/dist/web/assets/certificate-sheet-DzW0lfzR.js +2 -0
- package/dist/web/assets/chevron-left-Bu6IJANV.js +1 -0
- package/dist/web/assets/circle-dashed-D34ZjnSx.js +1 -0
- package/dist/web/assets/clock-DPBmdKAi.js +1 -0
- package/dist/web/assets/cohorts-DL0Dsxva.js +1 -0
- package/dist/web/assets/completion-2z7I-ypT.js +1 -0
- package/dist/web/assets/contact-NCWQa7wc.js +1 -0
- package/dist/web/assets/{context-BLVW7NB7.js → context-D8W_QqNi.js} +1 -1
- package/dist/web/assets/{copy-Bxxjq6zo.js → copy-B5IKRMFo.js} +1 -1
- package/dist/web/assets/download-BrtK5sVk.js +1 -0
- package/dist/web/assets/{ellipsis-c2POIN-Y.js → ellipsis-BDmYLoyn.js} +1 -1
- package/dist/web/assets/email-BZ3kGs-R.js +1 -0
- package/dist/web/assets/flag-DOzXVys0.js +1 -0
- package/dist/web/assets/folder-input-M2p_UJZX.js +1 -0
- package/dist/web/assets/{library-3WG9oLCb.js → folder-tree-B-DoLXMB.js} +1 -1
- package/dist/web/assets/frame-DZh5g5b3.js +1 -0
- package/dist/web/assets/globe-DDTr53UY.js +1 -0
- package/dist/web/assets/grades-ogaD0MDO.js +1 -0
- package/dist/web/assets/groups-CrYV_AFp.js +1 -0
- package/dist/web/assets/{hooks-BBARn-DA.js → hooks-EFhyJ5yU.js} +1 -1
- package/dist/web/assets/hourglass-BKca6Cje.js +1 -0
- package/dist/web/assets/inbox-x1U4YU-c.js +1 -0
- package/dist/web/assets/index-BdPmMS6n.css +2 -0
- package/dist/web/assets/index-CEZdqKdi.js +50 -0
- package/dist/web/assets/{key-round-B_KI-brR.js → key-round-fzvV-etw.js} +1 -1
- package/dist/web/assets/library-Bcm33ouq.js +1 -0
- package/dist/web/assets/lightbulb-CjSpJ1_v.js +1 -0
- package/dist/web/assets/{lock-BjbqwA_0.js → lock-C2edVDOc.js} +1 -1
- package/dist/web/assets/mail-CQ9yiBph.js +1 -0
- package/dist/web/assets/mail-x-B6oBqlcw.js +1 -0
- package/dist/web/assets/{markdown-ykrkPMbn.js → markdown-HNlXovsL.js} +3 -3
- package/dist/web/assets/message-square-text-wvO9_guT.js +1 -0
- package/dist/web/assets/{misc-DvgDEI3I.js → misc-CyGhN6HT.js} +1 -1
- package/dist/web/assets/{pencil-p0GQmIMo.js → pencil-DFUpj3YP.js} +1 -1
- package/dist/web/assets/{pin-DlYC3uec.js → pin-DNUQ6-WX.js} +1 -1
- package/dist/web/assets/revoke-dialog-DjBKaFTV.js +1 -0
- package/dist/web/assets/rotate-ccw-yBj9Ri49.js +1 -0
- package/dist/web/assets/scroll-text-RmPlZi3F.js +1 -0
- package/dist/web/assets/{send-mxSHcdcD.js → send-BnVkFV8w.js} +1 -1
- package/dist/web/assets/{settings-DRKWzSHN.js → settings-BxdCrDf8.js} +1 -1
- package/dist/web/assets/shield-x-RpNHS0o8.js +1 -0
- package/dist/web/assets/shuffle-C1aB_4dp.js +1 -0
- package/dist/web/assets/target-G9Q_WQLB.js +1 -0
- package/dist/web/assets/trophy-BFFngFEh.js +1 -0
- package/dist/web/assets/user-minus-CkOPT3ak.js +1 -0
- package/dist/web/assets/users-round-CNhv0Whm.js +1 -0
- package/dist/web/index.html +4 -4
- package/package.json +6 -1
- package/dist/web/assets/ActivityPage-DPmSV_mU.js +0 -1
- package/dist/web/assets/AdminCoursesPage-uaSHNtzf.js +0 -1
- package/dist/web/assets/AdminLayout-DqoShZGn.js +0 -1
- package/dist/web/assets/AdminUsersPage-3d2F9AEl.js +0 -1
- package/dist/web/assets/CalendarPage-CLRWyTNT.js +0 -1
- package/dist/web/assets/CourseContentPage-BIDH0UbG.js +0 -1
- package/dist/web/assets/CourseLayout-ql01LEmj.js +0 -1
- package/dist/web/assets/CourseSettingsPage-CReoPqOa.js +0 -1
- package/dist/web/assets/CreateCoursePage-DFCHlq5M.js +0 -1
- package/dist/web/assets/GradesPage-Bu5vphcG.js +0 -1
- package/dist/web/assets/NotificationsPage-LJvqb6Dj.js +0 -1
- package/dist/web/assets/ParticipantsPage-wFxiphna.js +0 -1
- package/dist/web/assets/ProfilePage-CzfhacAX.js +0 -1
- package/dist/web/assets/QuizAttemptPage-CEAV6wAL.js +0 -1
- package/dist/web/assets/QuizEditorPage-DS_czQVM.js +0 -3
- package/dist/web/assets/SubmissionsPage-CQjcx09G.js +0 -1
- package/dist/web/assets/chevron-left-D6IMQD6N.js +0 -1
- package/dist/web/assets/frame-CGabirLa.js +0 -1
- package/dist/web/assets/index-B29bTBiJ.js +0 -50
- package/dist/web/assets/index-WxCvsbJq.css +0 -2
- package/dist/web/assets/message-square-text-fe24gbEU.js +0 -1
- package/dist/web/assets/trophy-Cch2iF1m.js +0 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type Certificate, type CertificateRef, type CertificateSummary, type CertificateVerification } from '../../shared/completion.js';
|
|
2
|
+
import type { PublicUser } from '../../shared/types.js';
|
|
3
|
+
import type { DB } from '../db/types.js';
|
|
4
|
+
import type { CertificateRow, CourseCompletionSettingsRow } from '../db/schema-completion.js';
|
|
5
|
+
import type { CourseRow } from '../db/schema.js';
|
|
6
|
+
/** 12 random Crockford base32 characters (60 bits): short enough to type, too many to guess. */
|
|
7
|
+
export declare function newCertificateCode(): string;
|
|
8
|
+
export declare function toCertificateRef(row: Pick<CertificateRow, 'id' | 'code' | 'revokedAt'>): CertificateRef;
|
|
9
|
+
/**
|
|
10
|
+
* Issues certificates for people who completed `course`, with a snapshot of their name, the course
|
|
11
|
+
* title and the current template. At most one certificate per person and course: existing ones are
|
|
12
|
+
* left alone (including revoked ones). Returns the certificates that were created.
|
|
13
|
+
*/
|
|
14
|
+
export declare function issueCertificates(db: DB, course: CourseRow, settings: CourseCompletionSettingsRow, recipients: Array<{
|
|
15
|
+
userId: string;
|
|
16
|
+
completedAt: string;
|
|
17
|
+
}>, issuedAt: string): Promise<CertificateRow[]>;
|
|
18
|
+
/** Certificates for everyone who completed the course before certificates were turned on. */
|
|
19
|
+
export declare function issueMissingCertificates(db: DB, course: CourseRow, settings: CourseCompletionSettingsRow, issuedAt: string): Promise<{
|
|
20
|
+
body: string;
|
|
21
|
+
code: string;
|
|
22
|
+
completedAt: string;
|
|
23
|
+
courseId: string | null;
|
|
24
|
+
courseTitle: string;
|
|
25
|
+
id: string;
|
|
26
|
+
issuedAt: string;
|
|
27
|
+
recipientName: string;
|
|
28
|
+
revokeReason: string | null;
|
|
29
|
+
revokedAt: string | null;
|
|
30
|
+
revokedBy: string | null;
|
|
31
|
+
signatureName: string;
|
|
32
|
+
signatureTitle: string;
|
|
33
|
+
siteName: string;
|
|
34
|
+
title: string;
|
|
35
|
+
userId: string;
|
|
36
|
+
}[]>;
|
|
37
|
+
export declare function toCertificateSummary(row: CertificateRow, course: CourseRow | null | undefined, recipient: PublicUser): CertificateSummary;
|
|
38
|
+
export declare function toCertificate(row: CertificateRow, course: CourseRow | null | undefined, recipient: PublicUser, canManage: boolean): Certificate;
|
|
39
|
+
/** The public view of a certificate: name, course, date and validity, nothing else. */
|
|
40
|
+
export declare function toVerification(row: CertificateRow): CertificateVerification;
|
|
41
|
+
/** Certificates with their courses and recipients, loaded without a query per certificate. */
|
|
42
|
+
export declare function summarizeCertificates(db: DB, rows: CertificateRow[]): Promise<CertificateSummary[]>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { CohortCandidate, CohortDetail, CohortLink, CohortMember, CohortMembersAdded, CohortOption, CohortSummary, CourseRole, Paginated } from '../../shared/types.js';
|
|
2
|
+
import type { AppDeps } from '../context.js';
|
|
3
|
+
import type { CohortCourseRow, CohortRow, CourseRow, UserRow } from '../db/schema.js';
|
|
4
|
+
import type { DB } from '../db/types.js';
|
|
5
|
+
type Deps = Pick<AppDeps, 'db' | 'events'>;
|
|
6
|
+
type Actor = Pick<UserRow, 'id' | 'name'>;
|
|
7
|
+
export declare function loadCohort(db: DB, cohortId: string): Promise<CohortRow>;
|
|
8
|
+
export declare function listCohorts(db: DB, query: {
|
|
9
|
+
q?: string | undefined;
|
|
10
|
+
page: number;
|
|
11
|
+
pageSize: number;
|
|
12
|
+
}): Promise<Paginated<CohortSummary>>;
|
|
13
|
+
export declare function cohortDetail(db: DB, cohort: CohortRow): Promise<CohortDetail>;
|
|
14
|
+
export declare function createCohort(deps: Deps, input: {
|
|
15
|
+
name: string;
|
|
16
|
+
description: string;
|
|
17
|
+
}): Promise<CohortRow>;
|
|
18
|
+
export declare function updateCohort(deps: Deps, cohort: CohortRow, input: {
|
|
19
|
+
name?: string | undefined;
|
|
20
|
+
description?: string | undefined;
|
|
21
|
+
}): Promise<{
|
|
22
|
+
name: string;
|
|
23
|
+
description: string;
|
|
24
|
+
updatedAt: string;
|
|
25
|
+
createdAt: string;
|
|
26
|
+
id: string;
|
|
27
|
+
}>;
|
|
28
|
+
/** Deletes the cohort and its course links. Enrolments made through it are kept. */
|
|
29
|
+
export declare function deleteCohort(deps: Deps, cohort: CohortRow): Promise<void>;
|
|
30
|
+
export declare function listCohortMembers(db: DB, cohortId: string, query: {
|
|
31
|
+
q?: string | undefined;
|
|
32
|
+
page: number;
|
|
33
|
+
pageSize: number;
|
|
34
|
+
}): Promise<Paginated<CohortMember>>;
|
|
35
|
+
/** People matching a name or email search, marked when they are already in the cohort. */
|
|
36
|
+
export declare function searchCohortCandidates(db: DB, cohortId: string, q: string): Promise<CohortCandidate[]>;
|
|
37
|
+
/**
|
|
38
|
+
* Adds people to a cohort by id or email and enrols the new members in every course the cohort is linked to,
|
|
39
|
+
* through the same enrolment code path as "Enrol people" (notifications and `enrolment.created` events).
|
|
40
|
+
* Memberships and enrolments are written in one transaction.
|
|
41
|
+
*/
|
|
42
|
+
export declare function addCohortMembers(deps: Deps, cohort: CohortRow, input: {
|
|
43
|
+
userIds: string[];
|
|
44
|
+
emails: string[];
|
|
45
|
+
}, actor: Actor): Promise<CohortMembersAdded>;
|
|
46
|
+
/** Removes someone from a cohort. Their course enrolments are kept. */
|
|
47
|
+
export declare function removeCohortMember(deps: Deps, cohort: CohortRow, userId: string): Promise<void>;
|
|
48
|
+
export declare function courseCohortLinks(db: DB, courseId: string): Promise<CohortLink[]>;
|
|
49
|
+
/** Cohorts that aren't linked to the course yet. */
|
|
50
|
+
export declare function availableCohorts(db: DB, courseId: string): Promise<CohortOption[]>;
|
|
51
|
+
export declare function loadCohortLink(db: DB, courseId: string, linkId: string): Promise<CohortCourseRow>;
|
|
52
|
+
/**
|
|
53
|
+
* Links a cohort to a course: every current member is enrolled with `role` (people already enrolled keep their
|
|
54
|
+
* enrolment as it is), and members who join the cohort later are enrolled when they are added.
|
|
55
|
+
*/
|
|
56
|
+
export declare function linkCohort(deps: Deps, course: CourseRow, cohort: CohortRow, role: CourseRole, actor: Actor): Promise<{
|
|
57
|
+
link: CohortLink;
|
|
58
|
+
enrolled: number;
|
|
59
|
+
}>;
|
|
60
|
+
/** Enrols any member of a linked cohort who isn't in the course (for example after a teacher removed them). */
|
|
61
|
+
export declare function syncCohortLink(deps: Deps, course: CourseRow, link: CohortCourseRow, actor: Actor): Promise<number>;
|
|
62
|
+
/** Unlinks a cohort from a course. Everyone it enrolled stays enrolled. */
|
|
63
|
+
export declare function unlinkCohort(deps: Deps, link: CohortCourseRow): Promise<void>;
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type CompletionActivityOption, type CompletionReport, type CourseCompletionSettings, type CourseCompletionStatus, type SaveCompletionSettingsResult } from '../../shared/completion.js';
|
|
2
|
+
import type { AppDeps } from '../context.js';
|
|
3
|
+
import type { DB } from '../db/types.js';
|
|
4
|
+
import type { CourseCompletionSettingsRow } from '../db/schema-completion.js';
|
|
5
|
+
import type { CourseRow } from '../db/schema.js';
|
|
6
|
+
import type { EventBus } from '../lib/events.js';
|
|
7
|
+
type Deps = Pick<AppDeps, 'db' | 'events'>;
|
|
8
|
+
export declare function toCompletionSettings(row: CourseCompletionSettingsRow | undefined): CourseCompletionSettings;
|
|
9
|
+
export declare function loadCompletionSettings(db: DB, courseId: string): Promise<CourseCompletionSettingsRow | undefined>;
|
|
10
|
+
/** Every activity in course order, and whether it counts towards completion (visible, tracking completion). */
|
|
11
|
+
export declare function completionActivities(db: DB, courseId: string): Promise<CompletionActivityOption[]>;
|
|
12
|
+
/** The activities a student must complete: all tracked ones, or the selected ones that are tracked. */
|
|
13
|
+
export declare function requiredActivities(settings: CourseCompletionSettings, activities: CompletionActivityOption[]): CompletionActivityOption[];
|
|
14
|
+
export interface CompleteOptions {
|
|
15
|
+
/** Completion time, for imports and demo data. Defaults to now. */
|
|
16
|
+
at?: string;
|
|
17
|
+
/** Send notifications and emit events (default true). */
|
|
18
|
+
announce?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Records that `userIds` completed the course, once each, together with their certificates and
|
|
22
|
+
* automatic badges (one transaction). Returns the users who completed it now.
|
|
23
|
+
*/
|
|
24
|
+
export declare function completeCourse(deps: Deps, course: CourseRow, settings: CourseCompletionSettingsRow, userIds: string[], options?: CompleteOptions): Promise<string[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Checks the course's completion criteria for its active students (or only `userIds`) and records
|
|
27
|
+
* completion for everyone who now meets them. Completion is permanent: people who completed the course
|
|
28
|
+
* keep their completion when the criteria change later. Returns the users who completed it now.
|
|
29
|
+
*/
|
|
30
|
+
export declare function evaluateCompletion(deps: Deps, courseId: string, userIds?: string[], options?: CompleteOptions): Promise<string[]>;
|
|
31
|
+
export interface CompletionSettingsInput {
|
|
32
|
+
enabled: boolean;
|
|
33
|
+
mode: 'all' | 'selected';
|
|
34
|
+
activityIds: string[];
|
|
35
|
+
minGrade: number | null;
|
|
36
|
+
certificate: {
|
|
37
|
+
enabled: boolean;
|
|
38
|
+
title: string;
|
|
39
|
+
body: string;
|
|
40
|
+
signatureName: string;
|
|
41
|
+
signatureTitle: string;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** Saves the settings, then completes everyone who now qualifies and issues missing certificates. */
|
|
45
|
+
export declare function saveCompletionSettings(deps: Deps, course: CourseRow, input: CompletionSettingsInput, userId: string): Promise<SaveCompletionSettingsResult>;
|
|
46
|
+
/** One student's view: the criteria checklist and whether (and when) they completed the course. */
|
|
47
|
+
export declare function completionStatus(db: DB, courseId: string, userId: string): Promise<CourseCompletionStatus>;
|
|
48
|
+
/** The teacher's view: every active student's progress towards completion. */
|
|
49
|
+
export declare function completionReport(db: DB, courseId: string): Promise<CompletionReport>;
|
|
50
|
+
export interface CompletionEngine {
|
|
51
|
+
/** Resolves once every queued completion check has finished. */
|
|
52
|
+
idle(): Promise<void>;
|
|
53
|
+
/** Finishes queued work and stops listening for events. */
|
|
54
|
+
stop(): Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
/** The running engine for a Coursekit instance's event bus (tests use it to wait for background checks). */
|
|
57
|
+
export declare function completionEngineFor(events: EventBus): CompletionEngine | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Evaluates completion in the background when activities are completed or grades change. Checks are
|
|
60
|
+
* queued and run one at a time, and events for the same course are batched into one check.
|
|
61
|
+
*/
|
|
62
|
+
export declare function startCompletionEngine(deps: Deps): CompletionEngine;
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Course totals: the one place that decides how grades add up. The gradebook, the CSV export,
|
|
3
|
+
* the student's grades page and other features (such as course completion) all use it.
|
|
4
|
+
*
|
|
5
|
+
* Definitions, for one student:
|
|
6
|
+
*
|
|
7
|
+
* - An item is a graded activity (max grade m) in exactly one category. Unassigned items sit in the
|
|
8
|
+
* course's default category. Only graded items count: an item with no score is left out entirely,
|
|
9
|
+
* neither zero nor part of the points possible.
|
|
10
|
+
* - Each counted item has a weight within its category, e: its points (e = m) unless the teacher set
|
|
11
|
+
* an item weight w (e = w). Item weights are only used by weighted aggregation; natural aggregation
|
|
12
|
+
* always counts points. So weights 1 and 3 make two items worth 25% and 75% of their category,
|
|
13
|
+
* whatever their points. An item with weight 0, or with a weight and a max grade of 0, doesn't count.
|
|
14
|
+
* - Drop the lowest N (per category, in both aggregations): among the category's graded items with
|
|
15
|
+
* e > 0 and m > 0, the N with the lowest percentage (score / m) are left out. Ties drop the item
|
|
16
|
+
* with the larger e first (that helps the student most), then the one earlier in the course. At
|
|
17
|
+
* least one graded item always counts, so N is capped at (graded items - 1). Ungraded items are
|
|
18
|
+
* never dropped.
|
|
19
|
+
* - Category subtotal = Σ (score / m × e) / Σ e × 100 over its counted items, which is
|
|
20
|
+
* Σ score / Σ m × 100 when the items count by points. Null when Σ e is 0 (nothing graded yet, or
|
|
21
|
+
* an empty category).
|
|
22
|
+
*
|
|
23
|
+
* Course total:
|
|
24
|
+
*
|
|
25
|
+
* - natural (default, 0.1.x behaviour): Σ score / Σ m × 100 over every counted item in the course,
|
|
26
|
+
* summed in course order. Without drop rules this is exactly what 0.1.x computed, to the last bit
|
|
27
|
+
* (an item with a max grade of 0 adds its score and no points possible, as before). Category and
|
|
28
|
+
* item weights are not used.
|
|
29
|
+
* - weighted: Σ (weight_c × subtotal_c) / Σ weight_c over the categories that have a subtotal and a
|
|
30
|
+
* weight above 0. Categories without grades yet are skipped and the remaining weights are scaled up
|
|
31
|
+
* to 100% (normalised), which also covers weights that don't add up to 100: 20/20 behaves like
|
|
32
|
+
* 50/50. A category with weight 0 never counts. When no category counts, the total is null.
|
|
33
|
+
*
|
|
34
|
+
* `earned` and `possible` are always plain points (Σ score, Σ m) of the counted items. They make up
|
|
35
|
+
* the natural total; in weighted courses they are for information only. A category's `share` is the
|
|
36
|
+
* part of the course total it carries right now: its normalised weight (weighted) or its share of
|
|
37
|
+
* the points possible (natural).
|
|
38
|
+
*
|
|
39
|
+
* Totals are kept unrounded here; callers round for display (2 decimals). Scores above the max grade
|
|
40
|
+
* (possible after lowering an assignment's max grade) are not capped, as in 0.1.x.
|
|
41
|
+
*/
|
|
42
|
+
import type { ActivityType, GradeAggregation, GradeCategory } from '../../shared/types.js';
|
|
43
|
+
import type { DB } from '../db/types.js';
|
|
44
|
+
export declare const DEFAULT_CATEGORY_NAME = "Uncategorised";
|
|
45
|
+
export interface GradeItemInfo {
|
|
46
|
+
activityId: string;
|
|
47
|
+
title: string;
|
|
48
|
+
type: ActivityType;
|
|
49
|
+
maxGrade: number;
|
|
50
|
+
dueAt: string | null;
|
|
51
|
+
/** The activity and its section are both visible to students. */
|
|
52
|
+
visible: boolean;
|
|
53
|
+
sectionTitle: string;
|
|
54
|
+
/** Always one of the setup's categories (the default category's id is the course id). */
|
|
55
|
+
categoryId: string;
|
|
56
|
+
/** Weight within the category; null = by points (the max grade). */
|
|
57
|
+
weight: number | null;
|
|
58
|
+
}
|
|
59
|
+
export interface GradeSetup {
|
|
60
|
+
courseId: string;
|
|
61
|
+
aggregation: GradeAggregation;
|
|
62
|
+
/** In display order; always includes the default category. */
|
|
63
|
+
categories: GradeCategory[];
|
|
64
|
+
/** Graded activities in course order. */
|
|
65
|
+
items: GradeItemInfo[];
|
|
66
|
+
}
|
|
67
|
+
export interface CategoryTotal {
|
|
68
|
+
/** Unrounded subtotal (0-100), or null when nothing counts yet. */
|
|
69
|
+
percentage: number | null;
|
|
70
|
+
/** Points of the counted items (after drop-lowest). */
|
|
71
|
+
earned: number;
|
|
72
|
+
possible: number;
|
|
73
|
+
share: number | null;
|
|
74
|
+
}
|
|
75
|
+
export interface CourseGrade {
|
|
76
|
+
/** Unrounded course total (0-100), or null when nothing counts yet. */
|
|
77
|
+
percentage: number | null;
|
|
78
|
+
/** Points of the counted items (after drop-lowest); the natural total is earned / possible. */
|
|
79
|
+
earned: number;
|
|
80
|
+
possible: number;
|
|
81
|
+
/** Subtotals keyed by category id (every category of the setup). */
|
|
82
|
+
categories: Map<string, CategoryTotal>;
|
|
83
|
+
/** Activity ids left out by drop-lowest. */
|
|
84
|
+
dropped: Set<string>;
|
|
85
|
+
}
|
|
86
|
+
/** Scores by activity id. Missing and null both mean "not graded". */
|
|
87
|
+
export type Scores = ReadonlyMap<string, number | null | undefined>;
|
|
88
|
+
/** Loads a course's categories, aggregation and graded activities. Hidden activities are only included on request (staff). */
|
|
89
|
+
export declare function loadGradeSetup(db: DB, courseId: string, options?: {
|
|
90
|
+
includeHidden?: boolean;
|
|
91
|
+
}): Promise<GradeSetup>;
|
|
92
|
+
/** Computes one student's subtotals and course total. Pure: see the definitions at the top of this file. */
|
|
93
|
+
export declare function computeCourseGrade(setup: GradeSetup, scores: Scores): CourseGrade;
|
|
94
|
+
/** Scores by user, then by activity, for some (or all) users of a course. */
|
|
95
|
+
export declare function loadScores(db: DB, courseId: string, userIds?: readonly string[]): Promise<Map<string, Map<string, number>>>;
|
|
96
|
+
/**
|
|
97
|
+
* Full breakdown (subtotals, dropped items) for each user, as staff see it: hidden activities count.
|
|
98
|
+
* Pass `includeHidden: false` for the totals a student sees on their own grades page.
|
|
99
|
+
*/
|
|
100
|
+
export declare function courseGrades(db: DB, courseId: string, userIds: readonly string[], options?: {
|
|
101
|
+
includeHidden?: boolean;
|
|
102
|
+
}): Promise<Map<string, CourseGrade>>;
|
|
103
|
+
/**
|
|
104
|
+
* Each user's course total as a percentage (0-100, rounded to 2 decimals), or null when nothing is
|
|
105
|
+
* graded yet. This is the total in the gradebook and the CSV export (hidden activities included).
|
|
106
|
+
*/
|
|
107
|
+
export declare function courseTotals(db: DB, courseId: string, userIds: string[]): Promise<Map<string, number | null>>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Email delivery options: `createCoursekit({ email })` and the COURSEKIT_* environment variables.
|
|
3
|
+
* Nothing here refers to nodemailer, so the public type declarations work without it installed.
|
|
4
|
+
*/
|
|
5
|
+
export type EmailTransportName = 'smtp' | 'log' | 'none';
|
|
6
|
+
/** One email, as handed to a transport. */
|
|
7
|
+
export interface EmailMessage {
|
|
8
|
+
/** Outbox id. It stays the same across retries, so it works as an idempotency key. */
|
|
9
|
+
id: string;
|
|
10
|
+
from: string;
|
|
11
|
+
to: string;
|
|
12
|
+
subject: string;
|
|
13
|
+
html: string;
|
|
14
|
+
text: string;
|
|
15
|
+
/** Extra headers, e.g. List-Unsubscribe. */
|
|
16
|
+
headers: Record<string, string>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Delivers email through any provider (Resend, Postmark, SES, ...). Throw to report a failure: the message
|
|
20
|
+
* is retried with backoff, unless the error has `permanent: true` or an SMTP-style `responseCode` of 500-599.
|
|
21
|
+
*/
|
|
22
|
+
export interface EmailTransport {
|
|
23
|
+
send(message: EmailMessage): unknown;
|
|
24
|
+
/** Shown on the admin page, e.g. "Resend". */
|
|
25
|
+
name?: string | undefined;
|
|
26
|
+
}
|
|
27
|
+
export interface EmailOptions {
|
|
28
|
+
/**
|
|
29
|
+
* 'smtp' (needs `smtpUrl`), 'log' (prints emails and saves them to `<dataDir>/emails`), 'none', or your own
|
|
30
|
+
* `{ send(message) }` transport. Defaults to $COURSEKIT_MAIL_TRANSPORT, else 'smtp' when an SMTP URL is set,
|
|
31
|
+
* else 'none' (email off).
|
|
32
|
+
*/
|
|
33
|
+
transport?: EmailTransportName | EmailTransport | undefined;
|
|
34
|
+
/** smtp://user:password@host:587 or smtps://user:password@host:465. Defaults to $COURSEKIT_SMTP_URL. */
|
|
35
|
+
smtpUrl?: string | undefined;
|
|
36
|
+
/** Sender, e.g. "Acme Academy <learn@acme.example>". Defaults to $COURSEKIT_MAIL_FROM. */
|
|
37
|
+
from?: string | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Deliver queued email and send digests in the background of this process. Defaults to true
|
|
40
|
+
* ($COURSEKIT_MAIL_WORKER=false turns it off, e.g. when `coursekit send-digests` runs from cron).
|
|
41
|
+
*/
|
|
42
|
+
worker?: boolean | undefined;
|
|
43
|
+
}
|
|
44
|
+
export interface ResolvedEmailConfig {
|
|
45
|
+
transport: EmailTransportName | 'custom';
|
|
46
|
+
custom: EmailTransport | null;
|
|
47
|
+
smtpUrl: string | null;
|
|
48
|
+
from: string | null;
|
|
49
|
+
worker: boolean;
|
|
50
|
+
}
|
|
51
|
+
/** The bare address of "Name <a@b>" or "a@b", or null when there is none. */
|
|
52
|
+
export declare function addressOf(value: string): string | null;
|
|
53
|
+
export declare function resolveEmailConfig(options?: EmailOptions, env?: NodeJS.ProcessEnv): ResolvedEmailConfig;
|
|
54
|
+
/** "smtp.example.com:587" or "smtp.example.com:465 (TLS)", never the credentials. */
|
|
55
|
+
export declare function describeSmtpUrl(smtpUrl: string): string;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Daily and weekly digests. Each digest summarises the notifications a person received since their last
|
|
3
|
+
* digest (and that weren't already emailed one by one); nothing is sent when there are none.
|
|
4
|
+
*
|
|
5
|
+
* Digests go out at the site's digest hour in its time zone. A "slot" is the most recent such moment; a
|
|
6
|
+
* person is due when their last digest is older than the slot. Slots stay open for DIGEST_GRACE_MS so a
|
|
7
|
+
* server that was down at the digest hour catches up, but digests never go out at random times of day
|
|
8
|
+
* (unless forced, e.g. by `coursekit send-digests --force` from a cron job at another hour).
|
|
9
|
+
*/
|
|
10
|
+
import { type EmailSiteSettings } from '../../../shared/email.js';
|
|
11
|
+
import type { DB } from '../../db/types.js';
|
|
12
|
+
import { type EmailBrand, type EmailLinks } from './templates.js';
|
|
13
|
+
export type DigestPeriod = 'daily' | 'weekly';
|
|
14
|
+
export declare const DIGEST_GRACE_MS: number;
|
|
15
|
+
interface ZonedParts {
|
|
16
|
+
year: number;
|
|
17
|
+
month: number;
|
|
18
|
+
day: number;
|
|
19
|
+
hour: number;
|
|
20
|
+
minute: number;
|
|
21
|
+
second: number;
|
|
22
|
+
weekday: number;
|
|
23
|
+
}
|
|
24
|
+
export declare function zonedParts(date: Date, timeZone: string): ZonedParts;
|
|
25
|
+
/** The instant when the wall clock in `timeZone` shows the given local date and hour (day may overflow). */
|
|
26
|
+
export declare function zonedTimeToUtc(year: number, month: number, day: number, hour: number, timeZone: string): Date;
|
|
27
|
+
export interface DigestSchedule {
|
|
28
|
+
/** Most recent daily slot (at or before now). */
|
|
29
|
+
daily: Date;
|
|
30
|
+
weekly: Date;
|
|
31
|
+
nextDaily: Date;
|
|
32
|
+
nextWeekly: Date;
|
|
33
|
+
}
|
|
34
|
+
export declare function digestSchedule(now: Date, settings: Pick<EmailSiteSettings, 'digestHour' | 'digestWeekday' | 'timezone'>): DigestSchedule;
|
|
35
|
+
export interface DigestContext {
|
|
36
|
+
brand: EmailBrand;
|
|
37
|
+
base: string | null;
|
|
38
|
+
settings: EmailSiteSettings;
|
|
39
|
+
/** Links for a person, including their signed unsubscribe link. */
|
|
40
|
+
linksFor(userId: string): EmailLinks;
|
|
41
|
+
}
|
|
42
|
+
export interface DigestRunResult {
|
|
43
|
+
/** Daily digests queued. */
|
|
44
|
+
daily: number;
|
|
45
|
+
/** Weekly digests queued. */
|
|
46
|
+
weekly: number;
|
|
47
|
+
/** People who were due but had nothing new, so got no email. */
|
|
48
|
+
skipped: number;
|
|
49
|
+
}
|
|
50
|
+
/** Queues every digest that is due at `now`. Safe to run from several processes at once. */
|
|
51
|
+
export declare function queueDueDigests(db: DB, ctx: DigestContext, options: {
|
|
52
|
+
now: Date;
|
|
53
|
+
force?: boolean | undefined;
|
|
54
|
+
batchSize?: number;
|
|
55
|
+
maxUsers?: number;
|
|
56
|
+
}): Promise<DigestRunResult>;
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { EmailMessageStatus } from '../../../shared/email.js';
|
|
2
|
+
import type { EmailOutboxRow, EmailOutboxTable } from '../../db/schema.js';
|
|
3
|
+
import type { DB } from '../../db/types.js';
|
|
4
|
+
export type EmailKind = EmailOutboxTable['kind'];
|
|
5
|
+
export declare const DEFAULT_MAX_ATTEMPTS = 8;
|
|
6
|
+
/** Longer than any send is allowed to take (see SEND_TIMEOUT_MS in the service). */
|
|
7
|
+
export declare const LOCK_MS: number;
|
|
8
|
+
/** Kept for the admin page's counts, then deleted. */
|
|
9
|
+
export declare const OUTBOX_RETENTION_DAYS = 30;
|
|
10
|
+
/** Queued messages older than this are stale: they are marked failed instead of sent. */
|
|
11
|
+
export declare const EXPIRE_DAYS = 7;
|
|
12
|
+
/** Backoff before the next try after `attempt` failed tries, with ±20% jitter so retries spread out. */
|
|
13
|
+
export declare function retryDelayMs(attempt: number, random?: () => number): number;
|
|
14
|
+
/** Errors not worth retrying: `permanent: true`, or an SMTP 5xx reply other than an authentication failure. */
|
|
15
|
+
export declare function isPermanentError(err: unknown): boolean;
|
|
16
|
+
export declare function errorText(err: unknown): string;
|
|
17
|
+
export interface NewEmail {
|
|
18
|
+
kind: EmailKind;
|
|
19
|
+
userId: string | null;
|
|
20
|
+
notificationId: string | null;
|
|
21
|
+
to: string;
|
|
22
|
+
subject: string;
|
|
23
|
+
html: string;
|
|
24
|
+
text: string;
|
|
25
|
+
headers: Record<string, string>;
|
|
26
|
+
maxAttempts?: number;
|
|
27
|
+
}
|
|
28
|
+
export declare function enqueueEmails(db: DB, emails: NewEmail[], now: Date): Promise<string[]>;
|
|
29
|
+
/** Claims up to `limit` due messages for this run. Each claim counts as an attempt. */
|
|
30
|
+
export declare function claimDueEmails(db: DB, now: Date, limit: number): Promise<{
|
|
31
|
+
lockId: string;
|
|
32
|
+
rows: EmailOutboxRow[];
|
|
33
|
+
}>;
|
|
34
|
+
export declare function markSent(db: DB, id: string, lockId: string, now: Date): Promise<void>;
|
|
35
|
+
/** Records a failed try: schedules a retry with backoff, or gives up. */
|
|
36
|
+
export declare function markFailed(db: DB, row: Pick<EmailOutboxRow, 'id' | 'attempts' | 'maxAttempts'>, lockId: string, err: unknown, now: Date): Promise<{
|
|
37
|
+
willRetry: boolean;
|
|
38
|
+
error: string;
|
|
39
|
+
}>;
|
|
40
|
+
/** Hands claimed-but-unsent messages back without counting the attempt (e.g. when the server is down). */
|
|
41
|
+
export declare function releaseClaim(db: DB, lockId: string, ids: string[], now: Date): Promise<void>;
|
|
42
|
+
export declare function retryFailedEmails(db: DB, now: Date): Promise<number>;
|
|
43
|
+
/**
|
|
44
|
+
* Deletes delivered and failed messages after OUTBOX_RETENTION_DAYS, and gives up on messages still queued
|
|
45
|
+
* after EXPIRE_DAYS (e.g. while the transport could not start), so a long outage can't flood inboxes later.
|
|
46
|
+
*/
|
|
47
|
+
export declare function pruneOutbox(db: DB, now: Date): Promise<{
|
|
48
|
+
deleted: number;
|
|
49
|
+
expired: number;
|
|
50
|
+
}>;
|
|
51
|
+
export interface OutboxStats {
|
|
52
|
+
counts: Record<EmailMessageStatus, number>;
|
|
53
|
+
lastSentAt: string | null;
|
|
54
|
+
lastError: {
|
|
55
|
+
message: string;
|
|
56
|
+
at: string;
|
|
57
|
+
to: string;
|
|
58
|
+
status: EmailMessageStatus;
|
|
59
|
+
} | null;
|
|
60
|
+
}
|
|
61
|
+
export declare function outboxStats(db: DB): Promise<OutboxStats>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Site-wide email settings and each person's delivery preferences. */
|
|
2
|
+
import { type EmailCategoryId, type EmailFrequency, type EmailSiteSettings } from '../../../shared/email.js';
|
|
3
|
+
import type { DB } from '../../db/types.js';
|
|
4
|
+
export declare function isValidTimeZone(timeZone: string): boolean;
|
|
5
|
+
export declare function serverTimeZone(): string;
|
|
6
|
+
export declare function defaultEmailSettings(): EmailSiteSettings;
|
|
7
|
+
export declare function getEmailSettings(db: DB): Promise<EmailSiteSettings>;
|
|
8
|
+
export declare function updateEmailSettings(db: DB, patch: Partial<EmailSiteSettings>): Promise<EmailSiteSettings>;
|
|
9
|
+
/** Known category ids from stored JSON, without duplicates. */
|
|
10
|
+
export declare function parseCategories(json: string | null | undefined): EmailCategoryId[];
|
|
11
|
+
export interface StoredPreference {
|
|
12
|
+
/** null: follows the site default. */
|
|
13
|
+
frequency: EmailFrequency | null;
|
|
14
|
+
disabledCategories: EmailCategoryId[];
|
|
15
|
+
lastDigestAt: string | null;
|
|
16
|
+
}
|
|
17
|
+
export declare function loadPreference(db: DB, userId: string): Promise<StoredPreference | null>;
|
|
18
|
+
/**
|
|
19
|
+
* Saves a person's choices. Changing how often they're emailed restarts the digest window, so the first
|
|
20
|
+
* digest after switching only covers what arrived after the switch.
|
|
21
|
+
*/
|
|
22
|
+
export declare function savePreference(db: DB, userId: string, patch: {
|
|
23
|
+
frequency?: EmailFrequency | undefined;
|
|
24
|
+
disabledCategories?: EmailCategoryId[] | undefined;
|
|
25
|
+
}, settings: EmailSiteSettings, now: Date): Promise<StoredPreference>;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The email service of one Coursekit instance: queues notification emails, runs the background worker
|
|
3
|
+
* that delivers the outbox and sends digests, and backs the admin page.
|
|
4
|
+
*/
|
|
5
|
+
import { type EmailAdminStatus, type EmailCategoryId, type EmailSiteSettings } from '../../../shared/email.js';
|
|
6
|
+
import type { ResolvedConfig } from '../../config.js';
|
|
7
|
+
import type { DB } from '../../db/types.js';
|
|
8
|
+
import type { EventBus } from '../../lib/events.js';
|
|
9
|
+
import { type DigestRunResult } from './digests.js';
|
|
10
|
+
import { type Sender } from './transport.js';
|
|
11
|
+
import { type EmailBrand, type EmailLinks } from './templates.js';
|
|
12
|
+
export type { DigestRunResult } from './digests.js';
|
|
13
|
+
export interface OutboxRunResult {
|
|
14
|
+
/** Messages delivered. */
|
|
15
|
+
sent: number;
|
|
16
|
+
/** Messages that failed for good. */
|
|
17
|
+
failed: number;
|
|
18
|
+
/** Messages that failed and will be tried again later. */
|
|
19
|
+
retrying: number;
|
|
20
|
+
}
|
|
21
|
+
/** `coursekit.email`: programmatic control over outgoing email. */
|
|
22
|
+
export interface CoursekitEmail {
|
|
23
|
+
/** True when a transport is configured. Everything else is a no-op while email is off. */
|
|
24
|
+
readonly enabled: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Queues the daily and weekly digests that are due (at the site's digest hour, or now with `force`),
|
|
27
|
+
* skipping people with nothing new. Safe to call from several processes or a cron job.
|
|
28
|
+
*/
|
|
29
|
+
sendDigests(options?: {
|
|
30
|
+
now?: Date | undefined;
|
|
31
|
+
force?: boolean | undefined;
|
|
32
|
+
}): Promise<DigestRunResult>;
|
|
33
|
+
/** Delivers queued email now, including retries whose backoff has passed. */
|
|
34
|
+
processOutbox(options?: {
|
|
35
|
+
now?: Date | undefined;
|
|
36
|
+
}): Promise<OutboxRunResult>;
|
|
37
|
+
/** Queues a test message, e.g. to check SMTP settings. Resolves with the outbox id. */
|
|
38
|
+
sendTestEmail(to: string): Promise<{
|
|
39
|
+
id: string;
|
|
40
|
+
}>;
|
|
41
|
+
/** Starts the background worker (it starts by itself unless `email.worker` is false). */
|
|
42
|
+
startWorker(): void;
|
|
43
|
+
/** Stops the background worker, waiting briefly for a delivery in progress. */
|
|
44
|
+
stopWorker(): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
export interface EmailServiceDeps {
|
|
47
|
+
db: DB;
|
|
48
|
+
config: ResolvedConfig;
|
|
49
|
+
events: EventBus;
|
|
50
|
+
}
|
|
51
|
+
export declare const SEND_TIMEOUT_MS: number;
|
|
52
|
+
/** What every email needs to render: branding, links and the signing secret. */
|
|
53
|
+
export interface RenderContext {
|
|
54
|
+
brand: EmailBrand;
|
|
55
|
+
base: string | null;
|
|
56
|
+
from: string;
|
|
57
|
+
settings: EmailSiteSettings;
|
|
58
|
+
linksFor(userId: string | null, category?: EmailCategoryId | null): EmailLinks;
|
|
59
|
+
}
|
|
60
|
+
/** The From header: the configured sender, named after the site when it has no name of its own. */
|
|
61
|
+
export declare function fromHeader(configured: string | null, siteName: string, base: string | null): {
|
|
62
|
+
from: string;
|
|
63
|
+
isDefault: boolean;
|
|
64
|
+
};
|
|
65
|
+
export declare class EmailService implements CoursekitEmail {
|
|
66
|
+
#private;
|
|
67
|
+
readonly enabled: boolean;
|
|
68
|
+
readonly sender: Sender | null;
|
|
69
|
+
/** Why the transport can't send, e.g. nodemailer is missing. */
|
|
70
|
+
transportError: string | null;
|
|
71
|
+
constructor(deps: EmailServiceDeps, sender?: Sender | null);
|
|
72
|
+
get workerRunning(): boolean;
|
|
73
|
+
get db(): DB;
|
|
74
|
+
/** Branding, links and secret for rendering, read through `db` (pass a transaction to stay inside it). */
|
|
75
|
+
renderContext(db?: DB): Promise<RenderContext>;
|
|
76
|
+
startWorker(): void;
|
|
77
|
+
stopWorker(): Promise<void>;
|
|
78
|
+
/** Delivers soon instead of at the next poll, e.g. right after something was queued. */
|
|
79
|
+
wake(): void;
|
|
80
|
+
close(): Promise<void>;
|
|
81
|
+
/** One worker pass: digests (once a minute), delivery, and an hourly clean-up of old messages. */
|
|
82
|
+
runOnce(now?: Date): Promise<void>;
|
|
83
|
+
processOutbox(options?: {
|
|
84
|
+
now?: Date | undefined;
|
|
85
|
+
}): Promise<OutboxRunResult>;
|
|
86
|
+
sendDigests(options?: {
|
|
87
|
+
now?: Date | undefined;
|
|
88
|
+
force?: boolean | undefined;
|
|
89
|
+
}): Promise<DigestRunResult>;
|
|
90
|
+
sendTestEmail(to: string): Promise<{
|
|
91
|
+
id: string;
|
|
92
|
+
}>;
|
|
93
|
+
status(now?: Date): Promise<EmailAdminStatus>;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Creates the email service for a Coursekit instance and registers it with the database handle, which is
|
|
97
|
+
* how notify() finds it. Starts the background worker when email is configured and the worker is enabled.
|
|
98
|
+
*/
|
|
99
|
+
export declare function createEmailService(deps: EmailServiceDeps, options?: {
|
|
100
|
+
startWorker?: boolean;
|
|
101
|
+
}): EmailService;
|
|
102
|
+
export declare function emailServiceFor(db: DB): EmailService | undefined;
|
|
103
|
+
export interface NotificationForEmail {
|
|
104
|
+
id: string;
|
|
105
|
+
userId: string;
|
|
106
|
+
type: string;
|
|
107
|
+
title: string;
|
|
108
|
+
body: string;
|
|
109
|
+
link: string | null;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Queues an email for each notification whose recipient wants one immediately and hasn't switched its
|
|
113
|
+
* category off. Called by notify(); a no-op while email is off. Never throws: a notification must not
|
|
114
|
+
* fail because of email. (Pass the instance's own `db`: inside a transaction there is no email service.)
|
|
115
|
+
*/
|
|
116
|
+
export declare function queueNotificationEmails(db: DB, notifications: NotificationForEmail[], now?: Date): Promise<number>;
|