@goscribe/server 1.2.0 → 1.3.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 (48) hide show
  1. package/check-difficulty.cjs +14 -0
  2. package/check-questions.cjs +14 -0
  3. package/db-summary.cjs +22 -0
  4. package/mcq-test.cjs +36 -0
  5. package/package.json +9 -2
  6. package/prisma/migrations/20260413143206_init/migration.sql +873 -0
  7. package/prisma/schema.prisma +471 -324
  8. package/src/context.ts +4 -1
  9. package/src/lib/activity_human_description.test.ts +28 -0
  10. package/src/lib/activity_human_description.ts +239 -0
  11. package/src/lib/activity_log_service.test.ts +37 -0
  12. package/src/lib/activity_log_service.ts +353 -0
  13. package/src/lib/ai-session.ts +79 -51
  14. package/src/lib/email.ts +213 -29
  15. package/src/lib/env.ts +23 -6
  16. package/src/lib/inference.ts +2 -2
  17. package/src/lib/notification-service.test.ts +106 -0
  18. package/src/lib/notification-service.ts +677 -0
  19. package/src/lib/prisma.ts +6 -1
  20. package/src/lib/pusher.ts +86 -2
  21. package/src/lib/stripe.ts +39 -0
  22. package/src/lib/subscription_service.ts +722 -0
  23. package/src/lib/usage_service.ts +74 -0
  24. package/src/lib/worksheet-generation.test.ts +31 -0
  25. package/src/lib/worksheet-generation.ts +139 -0
  26. package/src/routers/_app.ts +9 -0
  27. package/src/routers/admin.ts +710 -0
  28. package/src/routers/annotations.ts +41 -0
  29. package/src/routers/auth.ts +338 -28
  30. package/src/routers/copilot.ts +719 -0
  31. package/src/routers/flashcards.ts +201 -68
  32. package/src/routers/members.ts +280 -80
  33. package/src/routers/notifications.ts +142 -0
  34. package/src/routers/payment.ts +448 -0
  35. package/src/routers/podcast.ts +112 -83
  36. package/src/routers/studyguide.ts +12 -0
  37. package/src/routers/worksheets.ts +289 -66
  38. package/src/routers/workspace.ts +329 -122
  39. package/src/scripts/purge-deleted-users.ts +167 -0
  40. package/src/server.ts +137 -11
  41. package/src/services/flashcard-progress.service.ts +49 -37
  42. package/src/trpc.ts +184 -5
  43. package/test-generate.js +30 -0
  44. package/test-ratio.cjs +9 -0
  45. package/zod-test.cjs +22 -0
  46. package/prisma/migrations/20250826124819_add_worksheet_difficulty_and_estimated_time/migration.sql +0 -213
  47. package/prisma/migrations/20250826133236_add_worksheet_question_progress/migration.sql +0 -31
  48. package/prisma/seed.mjs +0 -135
@@ -0,0 +1,106 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import PusherService from './pusher.js';
4
+ import { NotificationType, createNotification } from './notification-service.js';
5
+
6
+ type FakeNotification = {
7
+ id: string;
8
+ userId: string;
9
+ type: string;
10
+ title: string;
11
+ body: string;
12
+ content?: string;
13
+ sourceId?: string;
14
+ createdAt: Date;
15
+ read: boolean;
16
+ };
17
+
18
+ function createFakeDb() {
19
+ const store: FakeNotification[] = [];
20
+
21
+ const db = {
22
+ notification: {
23
+ async findFirst(args: any) {
24
+ const where = args?.where ?? {};
25
+ return (
26
+ store.find((item) => {
27
+ if (where.userId && item.userId !== where.userId) return false;
28
+ if (where.type && item.type !== where.type) return false;
29
+ if (where.sourceId && item.sourceId !== where.sourceId) return false;
30
+ return true;
31
+ }) ?? null
32
+ );
33
+ },
34
+ async create(args: any) {
35
+ const data = args.data;
36
+ const item: FakeNotification = {
37
+ id: `n_${store.length + 1}`,
38
+ userId: data.userId,
39
+ type: data.type,
40
+ title: data.title,
41
+ body: data.body,
42
+ content: data.content,
43
+ sourceId: data.sourceId,
44
+ createdAt: new Date(),
45
+ read: false,
46
+ };
47
+ store.push(item);
48
+ return item;
49
+ },
50
+ async count(args: any) {
51
+ const where = args?.where ?? {};
52
+ return store.filter((item) => {
53
+ if (where.userId && item.userId !== where.userId) return false;
54
+ if (where.read !== undefined && item.read !== where.read) return false;
55
+ return true;
56
+ }).length;
57
+ },
58
+ },
59
+ };
60
+
61
+ return { db, store };
62
+ }
63
+
64
+ test('createNotification deduplicates by sourceId', async () => {
65
+ const { db, store } = createFakeDb();
66
+ const originalEmit = PusherService.emitNotificationNew;
67
+ PusherService.emitNotificationNew = async () => {};
68
+
69
+ await createNotification(db, {
70
+ userId: 'u1',
71
+ type: NotificationType.PAYMENT_SUCCEEDED,
72
+ title: 'Payment successful',
73
+ body: 'Paid',
74
+ sourceId: 'source-1',
75
+ });
76
+ await createNotification(db, {
77
+ userId: 'u1',
78
+ type: NotificationType.PAYMENT_SUCCEEDED,
79
+ title: 'Payment successful',
80
+ body: 'Paid',
81
+ sourceId: 'source-1',
82
+ });
83
+
84
+ assert.equal(store.length, 1);
85
+ PusherService.emitNotificationNew = originalEmit;
86
+ });
87
+
88
+ test('createNotification emits unread count payload', async () => {
89
+ const { db } = createFakeDb();
90
+ const originalEmit = PusherService.emitNotificationNew;
91
+ let capturedUnread = -1;
92
+
93
+ PusherService.emitNotificationNew = async (_userId, payload) => {
94
+ capturedUnread = payload.unreadCount;
95
+ };
96
+
97
+ await createNotification(db, {
98
+ userId: 'u1',
99
+ type: NotificationType.GENERAL,
100
+ title: 'Hello',
101
+ body: 'World',
102
+ });
103
+
104
+ assert.equal(capturedUnread, 1);
105
+ PusherService.emitNotificationNew = originalEmit;
106
+ });