@goscribe/server 1.3.4 → 1.6.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/.env.example +12 -0
- package/.vscode/settings.json +3 -0
- package/REFACTOR_NOTES.md +60 -0
- package/TESTING_PROMPT.md +225 -0
- package/dist/context.d.ts +14 -1
- package/dist/context.js +23 -2
- package/dist/controllers/admin.controller.d.ts +715 -0
- package/dist/controllers/admin.controller.js +9 -0
- package/dist/controllers/annotations.controller.d.ts +439 -0
- package/dist/controllers/annotations.controller.js +9 -0
- package/dist/controllers/app-router.controller.d.ts +3011 -0
- package/dist/controllers/app-router.controller.js +38 -0
- package/dist/controllers/app-router.controller.test.d.ts +1 -0
- package/dist/controllers/app-router.controller.test.js +36 -0
- package/dist/controllers/auth.controller.d.ts +323 -0
- package/dist/controllers/auth.controller.js +9 -0
- package/dist/controllers/base.controller.d.ts +4 -0
- package/dist/controllers/base.controller.js +5 -0
- package/dist/controllers/chat.controller.d.ts +341 -0
- package/dist/controllers/chat.controller.js +9 -0
- package/dist/controllers/copilot.controller.d.ts +397 -0
- package/dist/controllers/copilot.controller.js +9 -0
- package/dist/controllers/flashcards.controller.d.ts +651 -0
- package/dist/controllers/flashcards.controller.js +9 -0
- package/dist/controllers/members.controller.d.ts +339 -0
- package/dist/controllers/members.controller.js +9 -0
- package/dist/controllers/notifications.controller.d.ts +199 -0
- package/dist/controllers/notifications.controller.js +9 -0
- package/dist/controllers/payment.controller.d.ts +181 -0
- package/dist/controllers/payment.controller.js +9 -0
- package/dist/controllers/podcast.controller.d.ts +575 -0
- package/dist/controllers/podcast.controller.js +9 -0
- package/dist/controllers/router-module.controller.d.ts +5 -0
- package/dist/controllers/router-module.controller.js +6 -0
- package/dist/controllers/studyguide.controller.d.ts +73 -0
- package/dist/controllers/studyguide.controller.js +9 -0
- package/dist/controllers/worksheets.controller.d.ts +829 -0
- package/dist/controllers/worksheets.controller.js +9 -0
- package/dist/controllers/workspace.controller.d.ts +1207 -0
- package/dist/controllers/workspace.controller.js +9 -0
- package/dist/lib/activity_human_description.test.js +16 -15
- package/dist/lib/activity_log_service.test.js +28 -23
- package/dist/lib/ai/config.d.ts +20 -0
- package/dist/lib/ai/config.js +31 -0
- package/dist/lib/ai/embedding-client.d.ts +8 -0
- package/dist/lib/ai/embedding-client.js +30 -0
- package/dist/lib/ai/index.d.ts +48 -0
- package/dist/lib/ai/index.js +29 -0
- package/dist/lib/ai/inference-backend/client.d.ts +28 -0
- package/dist/lib/ai/inference-backend/client.js +301 -0
- package/dist/lib/ai/inference-backend/mocks.d.ts +12 -0
- package/dist/lib/ai/inference-backend/mocks.js +133 -0
- package/dist/lib/ai/inference-backend/types.d.ts +44 -0
- package/dist/lib/ai/inference-backend/types.js +1 -0
- package/dist/lib/ai/json-parse.d.ts +2 -0
- package/dist/lib/ai/json-parse.js +34 -0
- package/dist/lib/ai/llm-client.d.ts +7 -0
- package/dist/lib/ai/llm-client.js +36 -0
- package/dist/lib/ai/mock.d.ts +2 -0
- package/dist/lib/ai/mock.js +10 -0
- package/dist/lib/ai/types.d.ts +9 -0
- package/dist/lib/ai/types.js +1 -0
- package/dist/lib/chunking.d.ts +19 -0
- package/dist/lib/chunking.js +47 -0
- package/dist/lib/curated-kb-seed.d.ts +12 -0
- package/dist/lib/curated-kb-seed.js +155 -0
- package/dist/lib/email.js +67 -108
- package/dist/lib/embeddings.d.ts +2 -0
- package/dist/lib/embeddings.js +1 -0
- package/dist/lib/ensure-curated-kb-catalog.d.ts +6 -0
- package/dist/lib/ensure-curated-kb-catalog.js +53 -0
- package/dist/lib/env.d.ts +1 -5
- package/dist/lib/env.js +2 -7
- package/dist/lib/inference.d.ts +1 -8
- package/dist/lib/inference.js +1 -19
- package/dist/lib/kb-meta.d.ts +8 -0
- package/dist/lib/kb-meta.js +77 -0
- package/dist/lib/note-text.d.ts +1 -0
- package/dist/lib/note-text.js +47 -0
- package/dist/lib/notification-service.test.js +37 -36
- package/dist/lib/pdf.d.ts +11 -0
- package/dist/lib/pdf.js +11 -0
- package/dist/lib/usage_service.d.ts +2 -1
- package/dist/lib/usage_service.js +30 -12
- package/dist/lib/worksheet-generation.js +4 -4
- package/dist/lib/worksheet-generation.test.js +32 -17
- package/dist/lib/workspace-kb.d.ts +5 -0
- package/dist/lib/workspace-kb.js +7 -0
- package/dist/models/controller-context.model.d.ts +8 -0
- package/dist/models/controller-context.model.js +1 -0
- package/dist/repositories/artifact.repository.d.ts +60 -0
- package/dist/repositories/artifact.repository.js +40 -0
- package/dist/repositories/base.repository.d.ts +14 -0
- package/dist/repositories/base.repository.js +14 -0
- package/dist/repositories/invitation.repository.d.ts +94 -0
- package/dist/repositories/invitation.repository.js +44 -0
- package/dist/repositories/notification.repository.d.ts +72 -0
- package/dist/repositories/notification.repository.js +44 -0
- package/dist/repositories/router-module.repository.d.ts +10 -0
- package/dist/repositories/router-module.repository.js +14 -0
- package/dist/repositories/user.repository.d.ts +74 -0
- package/dist/repositories/user.repository.js +37 -0
- package/dist/repositories/workspace-member.repository.d.ts +31 -0
- package/dist/repositories/workspace-member.repository.js +31 -0
- package/dist/repositories/workspace.repository.d.ts +97 -0
- package/dist/repositories/workspace.repository.js +79 -0
- package/dist/routers/_app.d.ts +566 -111
- package/dist/routers/_app.js +4 -0
- package/dist/routers/admin.d.ts +0 -4
- package/dist/routers/admin.js +21 -549
- package/dist/routers/annotations.js +12 -170
- package/dist/routers/artifactVersions.d.ts +65 -0
- package/dist/routers/artifactVersions.js +14 -0
- package/dist/routers/auth.d.ts +0 -6
- package/dist/routers/auth.js +37 -422
- package/dist/routers/chat.js +15 -229
- package/dist/routers/copilot.d.ts +14 -13
- package/dist/routers/copilot.js +13 -532
- package/dist/routers/flashcards.d.ts +17 -6
- package/dist/routers/flashcards.js +23 -349
- package/dist/routers/knowledgeBase.d.ts +421 -0
- package/dist/routers/knowledgeBase.js +118 -0
- package/dist/routers/members.d.ts +0 -41
- package/dist/routers/members.js +22 -710
- package/dist/routers/notes.d.ts +94 -0
- package/dist/routers/notes.js +37 -0
- package/dist/routers/notifications.js +7 -109
- package/dist/routers/payment.d.ts +2 -12
- package/dist/routers/payment.js +11 -393
- package/dist/routers/podcast.d.ts +1 -1
- package/dist/routers/podcast.js +11 -784
- package/dist/routers/studyguide.js +3 -129
- package/dist/routers/worksheets.d.ts +29 -14
- package/dist/routers/worksheets.js +49 -628
- package/dist/routers/workspace.d.ts +27 -71
- package/dist/routers/workspace.js +29 -922
- package/dist/scripts/purge-deleted-users.js +2 -2
- package/dist/server.js +10 -3
- package/dist/services/activity/activity-human-description.service.d.ts +13 -0
- package/dist/services/activity/activity-human-description.service.js +221 -0
- package/dist/services/activity/activity-human-description.service.test.d.ts +1 -0
- package/dist/services/activity/activity-human-description.service.test.js +16 -0
- package/dist/services/activity/activity-log.service.d.ts +87 -0
- package/dist/services/activity/activity-log.service.js +276 -0
- package/dist/services/activity/activity-log.service.test.d.ts +1 -0
- package/dist/services/activity/activity-log.service.test.js +27 -0
- package/dist/services/activity-human-description.service.d.ts +13 -0
- package/dist/services/activity-human-description.service.js +221 -0
- package/dist/services/activity-human-description.service.test.d.ts +1 -0
- package/dist/services/activity-human-description.service.test.js +16 -0
- package/dist/services/activity-log.service.d.ts +87 -0
- package/dist/services/activity-log.service.js +276 -0
- package/dist/services/activity-log.service.test.d.ts +1 -0
- package/dist/services/activity-log.service.test.js +27 -0
- package/dist/services/admin/admin.service.d.ts +270 -0
- package/dist/services/admin/admin.service.js +476 -0
- package/dist/services/admin.service.d.ts +270 -0
- package/dist/services/admin.service.js +476 -0
- package/dist/services/ai/ai-session.service.d.ts +5 -0
- package/dist/services/ai/ai-session.service.js +4 -0
- package/dist/services/ai-session.service.d.ts +60 -0
- package/dist/services/ai-session.service.js +561 -0
- package/dist/services/annotation.service.d.ts +177 -0
- package/dist/services/annotation.service.js +154 -0
- package/dist/services/artifact-notification.service.d.ts +14 -0
- package/dist/services/artifact-notification.service.js +20 -0
- package/dist/services/artifact-version.service.d.ts +38 -0
- package/dist/services/artifact-version.service.js +129 -0
- package/dist/services/artifacts/annotation.service.d.ts +177 -0
- package/dist/services/artifacts/annotation.service.js +154 -0
- package/dist/services/artifacts/artifact-version.service.d.ts +38 -0
- package/dist/services/artifacts/artifact-version.service.js +129 -0
- package/dist/services/artifacts/chat.service.d.ts +127 -0
- package/dist/services/artifacts/chat.service.js +182 -0
- package/dist/services/artifacts/study-guide.service.d.ts +18 -0
- package/dist/services/artifacts/study-guide.service.js +65 -0
- package/dist/services/auth/auth.service.d.ts +94 -0
- package/dist/services/auth/auth.service.js +368 -0
- package/dist/services/auth.service.d.ts +94 -0
- package/dist/services/auth.service.js +368 -0
- package/dist/services/base.service.d.ts +14 -0
- package/dist/services/base.service.js +14 -0
- package/dist/services/billing/payment.service.d.ts +44 -0
- package/dist/services/billing/payment.service.js +365 -0
- package/dist/services/billing/subscription.service.d.ts +37 -0
- package/dist/services/billing/subscription.service.js +654 -0
- package/dist/services/billing/usage.service.d.ts +47 -0
- package/dist/services/billing/usage.service.js +149 -0
- package/dist/services/chat.service.d.ts +127 -0
- package/dist/services/chat.service.js +182 -0
- package/dist/services/content/copilot.service.d.ts +113 -0
- package/dist/services/content/copilot.service.js +439 -0
- package/dist/services/content/flashcard-progress.service.d.ts +159 -0
- package/dist/services/content/flashcard-progress.service.js +432 -0
- package/dist/services/content/flashcard.service.d.ts +184 -0
- package/dist/services/content/flashcard.service.js +339 -0
- package/dist/services/content/media-analysis.service.d.ts +23 -0
- package/dist/services/content/media-analysis.service.js +404 -0
- package/dist/services/content/podcast.service.d.ts +267 -0
- package/dist/services/content/podcast.service.js +653 -0
- package/dist/services/content/worksheet-content.service.d.ts +37 -0
- package/dist/services/content/worksheet-content.service.js +84 -0
- package/dist/services/content/worksheet-content.service.test.d.ts +1 -0
- package/dist/services/content/worksheet-content.service.test.js +69 -0
- package/dist/services/content/worksheet-generation.service.d.ts +91 -0
- package/dist/services/content/worksheet-generation.service.js +95 -0
- package/dist/services/content/worksheet-generation.service.test.d.ts +1 -0
- package/dist/services/content/worksheet-generation.service.test.js +20 -0
- package/dist/services/content/worksheet.service.d.ts +347 -0
- package/dist/services/content/worksheet.service.js +599 -0
- package/dist/services/copilot.service.d.ts +116 -0
- package/dist/services/copilot.service.js +447 -0
- package/dist/services/flashcard-progress.service.d.ts +2 -2
- package/dist/services/flashcard-progress.service.js +3 -2
- package/dist/services/flashcard.service.d.ts +140 -0
- package/dist/services/flashcard.service.js +325 -0
- package/dist/services/invitation.service.d.ts +66 -0
- package/dist/services/invitation.service.js +348 -0
- package/dist/services/knowledge/knowledge-base.service.d.ts +316 -0
- package/dist/services/knowledge/knowledge-base.service.js +544 -0
- package/dist/services/knowledge-base.service.d.ts +316 -0
- package/dist/services/knowledge-base.service.js +536 -0
- package/dist/services/media-analysis.service.d.ts +23 -0
- package/dist/services/media-analysis.service.js +384 -0
- package/dist/services/member.service.d.ts +36 -0
- package/dist/services/member.service.js +193 -0
- package/dist/services/members/invitation.service.d.ts +66 -0
- package/dist/services/members/invitation.service.js +348 -0
- package/dist/services/members/member.service.d.ts +36 -0
- package/dist/services/members/member.service.js +193 -0
- package/dist/services/note.service.d.ts +55 -0
- package/dist/services/note.service.js +111 -0
- package/dist/services/notification.service.d.ts +214 -0
- package/dist/services/notification.service.js +550 -0
- package/dist/services/notification.service.test.d.ts +1 -0
- package/dist/services/notification.service.test.js +87 -0
- package/dist/services/notifications/notification.service.d.ts +214 -0
- package/dist/services/notifications/notification.service.js +550 -0
- package/dist/services/notifications/notification.service.test.d.ts +1 -0
- package/dist/services/notifications/notification.service.test.js +87 -0
- package/dist/services/payment.service.d.ts +55 -0
- package/dist/services/payment.service.js +368 -0
- package/dist/services/podcast.service.d.ts +267 -0
- package/dist/services/podcast.service.js +654 -0
- package/dist/services/router-module.service.d.ts +7 -0
- package/dist/services/router-module.service.js +10 -0
- package/dist/services/study-guide.service.d.ts +18 -0
- package/dist/services/study-guide.service.js +65 -0
- package/dist/services/subscription.service.d.ts +37 -0
- package/dist/services/subscription.service.js +654 -0
- package/dist/services/usage-limit-policy.service.d.ts +12 -0
- package/dist/services/usage-limit-policy.service.js +22 -0
- package/dist/services/usage-limit-policy.service.test.d.ts +1 -0
- package/dist/services/usage-limit-policy.service.test.js +46 -0
- package/dist/services/usage.service.d.ts +27 -0
- package/dist/services/usage.service.js +77 -0
- package/dist/services/worksheet-content.service.d.ts +42 -0
- package/dist/services/worksheet-content.service.js +84 -0
- package/dist/services/worksheet-content.service.test.d.ts +1 -0
- package/dist/services/worksheet-content.service.test.js +69 -0
- package/dist/services/worksheet-generation.service.d.ts +91 -0
- package/dist/services/worksheet-generation.service.js +95 -0
- package/dist/services/worksheet-generation.service.test.d.ts +1 -0
- package/dist/services/worksheet-generation.service.test.js +20 -0
- package/dist/services/worksheet.service.d.ts +385 -0
- package/dist/services/worksheet.service.js +596 -0
- package/dist/services/workspace/workspace-analytics.service.d.ts +24 -0
- package/dist/services/workspace/workspace-analytics.service.js +95 -0
- package/dist/services/workspace/workspace-kb.service.d.ts +40 -0
- package/dist/services/workspace/workspace-kb.service.js +184 -0
- package/dist/services/workspace/workspace.service.d.ts +263 -0
- package/dist/services/workspace/workspace.service.js +401 -0
- package/dist/services/workspace-analytics.service.d.ts +24 -0
- package/dist/services/workspace-analytics.service.js +95 -0
- package/dist/services/workspace-kb.service.d.ts +40 -0
- package/dist/services/workspace-kb.service.js +184 -0
- package/dist/services/workspace-progress.service.d.ts +27 -0
- package/dist/services/workspace-progress.service.js +56 -0
- package/dist/services/workspace-progress.service.test.d.ts +1 -0
- package/dist/services/workspace-progress.service.test.js +49 -0
- package/dist/services/workspace.service.d.ts +307 -0
- package/dist/services/workspace.service.js +390 -0
- package/dist/trpc.d.ts +12 -4
- package/dist/trpc.js +7 -13
- package/package.json +5 -6
- package/prisma/migrations/20260509000001_add_knowledge_base/migration.sql +99 -0
- package/prisma/migrations/20260509000002_curate_knowledge_base/migration.sql +52 -0
- package/prisma/migrations/20260522000000_add_notes/migration.sql +27 -0
- package/prisma/migrations/20260524000000_remove_notes/migration.sql +3 -0
- package/prisma/schema.prisma +150 -48
- package/prisma/seed.mjs +67 -0
- package/scripts/debug/README.md +4 -0
- package/src/README.md +63 -0
- package/src/context.ts +33 -3
- package/src/lib/ai/config.ts +34 -0
- package/src/lib/ai/embedding-client.ts +47 -0
- package/src/lib/ai/index.ts +65 -0
- package/src/lib/ai/inference-backend/client.ts +479 -0
- package/src/lib/ai/inference-backend/mocks.ts +171 -0
- package/src/lib/ai/inference-backend/types.ts +50 -0
- package/src/lib/ai/json-parse.ts +35 -0
- package/src/lib/ai/llm-client.ts +54 -0
- package/src/lib/ai/mock.ts +12 -0
- package/src/lib/ai/types.ts +11 -0
- package/src/lib/chunking.ts +81 -0
- package/src/lib/curated-kb-seed.ts +164 -0
- package/src/lib/email.ts +77 -115
- package/src/lib/embeddings.ts +9 -0
- package/src/lib/ensure-curated-kb-catalog.ts +60 -0
- package/src/lib/env.ts +2 -7
- package/src/lib/inference.ts +1 -21
- package/src/lib/kb-meta.ts +81 -0
- package/src/lib/pdf.ts +23 -0
- package/src/lib/workspace-kb.ts +7 -0
- package/src/repositories/artifact.repository.ts +55 -0
- package/src/repositories/base.repository.ts +19 -0
- package/src/repositories/invitation.repository.ts +53 -0
- package/src/repositories/notification.repository.ts +53 -0
- package/src/repositories/user.repository.ts +44 -0
- package/src/repositories/workspace-member.repository.ts +38 -0
- package/src/repositories/workspace.repository.ts +89 -0
- package/src/routers/_app.ts +4 -0
- package/src/routers/admin.ts +124 -692
- package/src/routers/annotations.ts +25 -203
- package/src/routers/artifactVersions.ts +32 -0
- package/src/routers/auth.ts +82 -520
- package/src/routers/chat.ts +42 -245
- package/src/routers/copilot.ts +41 -666
- package/src/routers/flashcards.ts +108 -404
- package/src/routers/knowledgeBase.ts +216 -0
- package/src/routers/members.ts +60 -782
- package/src/routers/notifications.ts +15 -117
- package/src/routers/payment.ts +37 -446
- package/src/routers/podcast.ts +36 -898
- package/src/routers/studyguide.ts +5 -144
- package/src/routers/worksheets.ts +171 -735
- package/src/routers/workspace.ts +141 -1108
- package/src/scripts/purge-deleted-users.ts +2 -2
- package/src/server.ts +10 -3
- package/src/{lib/activity_human_description.test.ts → services/activity/activity-human-description.service.test.ts} +1 -1
- package/src/{lib/activity_log_service.test.ts → services/activity/activity-log.service.test.ts} +1 -1
- package/src/{lib/activity_log_service.ts → services/activity/activity-log.service.ts} +2 -2
- package/src/services/admin/admin.service.ts +612 -0
- package/src/services/ai/ai-session.service.ts +5 -0
- package/src/services/artifacts/annotation.service.ts +189 -0
- package/src/services/artifacts/artifact-version.service.ts +151 -0
- package/src/services/artifacts/chat.service.ts +197 -0
- package/src/services/artifacts/study-guide.service.ts +72 -0
- package/src/services/auth/auth.service.ts +473 -0
- package/src/services/base.service.ts +19 -0
- package/src/services/billing/payment.service.ts +433 -0
- package/src/{lib/subscription_service.ts → services/billing/subscription.service.ts} +5 -5
- package/src/services/billing/usage.service.ts +207 -0
- package/src/services/content/copilot.service.ts +587 -0
- package/src/services/{flashcard-progress.service.ts → content/flashcard-progress.service.ts} +18 -12
- package/src/services/content/flashcard.service.ts +417 -0
- package/src/services/content/media-analysis.service.ts +561 -0
- package/src/services/content/podcast.service.ts +777 -0
- package/src/services/content/worksheet-content.service.test.ts +83 -0
- package/src/services/content/worksheet-content.service.ts +117 -0
- package/src/{lib/worksheet-generation.test.ts → services/content/worksheet-generation.service.test.ts} +3 -3
- package/src/services/content/worksheet.service.ts +751 -0
- package/src/services/knowledge/knowledge-base.service.ts +705 -0
- package/src/services/members/invitation.service.ts +427 -0
- package/src/services/members/member.service.ts +241 -0
- package/src/{lib/notification-service.test.ts → services/notifications/notification.service.test.ts} +2 -2
- package/src/{lib/notification-service.ts → services/notifications/notification.service.ts} +102 -1
- package/src/services/workspace/workspace-analytics.service.ts +107 -0
- package/src/services/workspace/workspace-kb.service.ts +273 -0
- package/src/services/workspace/workspace.service.ts +488 -0
- package/src/trpc.ts +7 -15
- package/src/lib/ai-session.ts +0 -704
- package/src/lib/usage_service.ts +0 -74
- package/src/lib/workspace-access.ts +0 -13
- /package/{check-difficulty.cjs → scripts/debug/check-difficulty.cjs} +0 -0
- /package/{check-questions.cjs → scripts/debug/check-questions.cjs} +0 -0
- /package/{db-summary.cjs → scripts/debug/db-summary.cjs} +0 -0
- /package/{mcq-test.cjs → scripts/debug/mcq-test.cjs} +0 -0
- /package/{test-generate.js → scripts/debug/test-generate.js} +0 -0
- /package/{test-ratio.cjs → scripts/debug/test-ratio.cjs} +0 -0
- /package/{zod-test.cjs → scripts/debug/zod-test.cjs} +0 -0
- /package/src/{lib/activity_human_description.ts → services/activity/activity-human-description.service.ts} +0 -0
- /package/src/{lib/worksheet-generation.ts → services/content/worksheet-generation.service.ts} +0 -0
package/.env.example
CHANGED
|
@@ -18,6 +18,18 @@ INFERENCE_API_URL=http://localhost:5000
|
|
|
18
18
|
INFERENCE_API_KEY=your-inference-api-key
|
|
19
19
|
INFERENCE_BASE_URL=https://api.cohere.ai/compatibility/v1
|
|
20
20
|
|
|
21
|
+
# Embeddings (Knowledge Base / RAG).
|
|
22
|
+
# Falls back to INFERENCE_* values if these are unset. Default model dim is 1536
|
|
23
|
+
# (text-embedding-3-small). If you change EMBEDDING_DIM you must also update
|
|
24
|
+
# the vector(...) column type in the Knowledge Base migration.
|
|
25
|
+
EMBEDDING_API_KEY=
|
|
26
|
+
EMBEDDING_BASE_URL=
|
|
27
|
+
EMBEDDING_MODEL=text-embedding-3-small
|
|
28
|
+
EMBEDDING_DIM=1536
|
|
29
|
+
|
|
30
|
+
# Bucket used for KB document uploads (defaults to SUPABASE_BUCKET / 'media').
|
|
31
|
+
SUPABASE_KB_BUCKET=media
|
|
32
|
+
|
|
21
33
|
# Supabase Storage
|
|
22
34
|
SUPABASE_URL=https://your-project.supabase.co
|
|
23
35
|
SUPABASE_SERVICE_ROLE_KEY=your-supabase-service-role-key
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Refactor notes
|
|
2
|
+
|
|
3
|
+
Captured during the router → service → repository refactor. These are
|
|
4
|
+
follow-up items that were **intentionally left unchanged** so the refactor
|
|
5
|
+
stays behavior-preserving.
|
|
6
|
+
|
|
7
|
+
## Inconsistent workspace-access semantics
|
|
8
|
+
|
|
9
|
+
Today the codebase uses three different patterns to decide whether a user
|
|
10
|
+
can "see" a workspace:
|
|
11
|
+
|
|
12
|
+
1. **Member-inclusive** — `workspaceAccessFilter(userId)` (now
|
|
13
|
+
`workspaceAccessWhere` in `src/repositories/workspace.repository.ts`).
|
|
14
|
+
`OR: [{ ownerId }, { members: { some: { userId } } }]`. Used by:
|
|
15
|
+
`worksheets.ts`, `studyguide.ts`, `copilot.ts`, `podcast.ts` (mostly),
|
|
16
|
+
`flashcards.ts` (mostly).
|
|
17
|
+
2. **Owner-only** — inline `{ ownerId: userId }`. Used by:
|
|
18
|
+
`workspace.list`, `workspace.getTree`, `workspace.create`,
|
|
19
|
+
`workspace.uploadFiles`, `workspace.uploadAndAnalyzeMedia`,
|
|
20
|
+
`flashcards.listSets` (unlike the rest of flashcards), some
|
|
21
|
+
`podcast.*` paths.
|
|
22
|
+
3. **`sharedWith`-based** — `sharedWith: { some: { id } }`. Used by parts
|
|
23
|
+
of `workspace.getStats`, storage counters.
|
|
24
|
+
|
|
25
|
+
The repository layer now exposes **both** `findByIdAccessible`/
|
|
26
|
+
`findByIdOwned` and `WorkspaceRepository.accessibleWhere`/`.ownedWhere`
|
|
27
|
+
so each call site can keep its current semantics. Unifying these is a
|
|
28
|
+
follow-up that deserves its own PR and review.
|
|
29
|
+
|
|
30
|
+
## Missing authorization checks in `chat.ts`
|
|
31
|
+
|
|
32
|
+
`chat.ts` procedures (`getChannels`, `postMessage`, `editMessage`,
|
|
33
|
+
`deleteMessage`, etc.) require only authentication — they do not check
|
|
34
|
+
that the caller belongs to the target workspace or channel. The Phase 4
|
|
35
|
+
extraction of `ChatService` preserves this behavior; a follow-up should
|
|
36
|
+
gate these procedures on `WorkspaceRepository.findByIdAccessible`.
|
|
37
|
+
|
|
38
|
+
## `auth.updateProfile` is a `publicProcedure` that requires a session
|
|
39
|
+
|
|
40
|
+
`auth.updateProfile` (and a few siblings) is wired as
|
|
41
|
+
`publicProcedure` but reads `ctx.session.user.id`. In practice it throws
|
|
42
|
+
if called unauthenticated, but the middleware stack doesn't guarantee it.
|
|
43
|
+
Should move to `authedProcedure` — not done here because it would change
|
|
44
|
+
observable error codes.
|
|
45
|
+
|
|
46
|
+
## `checkUsageLimit` for `studyguide.*` has an empty branch
|
|
47
|
+
|
|
48
|
+
In `src/trpc.ts`, the `checkUsageLimit` middleware has a
|
|
49
|
+
`studyguide.` branch with only commented reasoning and no enforcement.
|
|
50
|
+
Flagged for follow-up once the study-guide limit semantics are settled.
|
|
51
|
+
|
|
52
|
+
## Pre-existing failing test
|
|
53
|
+
|
|
54
|
+
`src/services/worksheet-generation.service.test.ts` contains
|
|
55
|
+
`mergeWorksheetGenerationConfig: override beats preset and legacy`, which
|
|
56
|
+
asserts that `configOverride` wins over `legacy`. The implementation in
|
|
57
|
+
`worksheet-generation.service.ts` (unchanged by this refactor) places
|
|
58
|
+
`legacy` AFTER `configOverride` by design, so the test fails on `main`
|
|
59
|
+
and fails after the refactor as well. Left for the user (both files
|
|
60
|
+
were already dirty in the working tree when the refactor began).
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# Testing prompt for the refactored server
|
|
2
|
+
|
|
3
|
+
Hand this file to a fresh agent/session as the starting prompt. Everything
|
|
4
|
+
below is ready to paste or reference directly.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Context
|
|
9
|
+
|
|
10
|
+
I just finished a big router → service → repository refactor of this tRPC
|
|
11
|
+
server. All business logic now lives in `src/services/*.service.ts`
|
|
12
|
+
(backed by `src/repositories/*.repository.ts`). Routers in `src/routers/`
|
|
13
|
+
are thin shells. Full convention is documented in
|
|
14
|
+
[`src/README.md`](src/README.md) and leftover follow-ups in
|
|
15
|
+
[`REFACTOR_NOTES.md`](REFACTOR_NOTES.md).
|
|
16
|
+
|
|
17
|
+
The refactor is behavior-preserving and `tsc --noEmit` is clean. Tests
|
|
18
|
+
currently run via Node's built-in test runner (`tsx --test`):
|
|
19
|
+
|
|
20
|
+
- `npm test` globs `src/**/*.test.ts`.
|
|
21
|
+
- Existing tests: 5 files, 18 tests, 17 pass (one pre-existing failure
|
|
22
|
+
flagged in `REFACTOR_NOTES.md` — don't try to fix it).
|
|
23
|
+
|
|
24
|
+
I want you to **add unit tests for the new services and repositories**.
|
|
25
|
+
Keep the existing test framework (`node:test` + `node:assert/strict` via
|
|
26
|
+
`tsx --test`). Do NOT switch to Vitest/Jest.
|
|
27
|
+
|
|
28
|
+
## What to test (priority order)
|
|
29
|
+
|
|
30
|
+
Pick priorities from the top. Each bullet is one file; stop when you feel
|
|
31
|
+
you've hit the high-value ones or you're running low on context.
|
|
32
|
+
|
|
33
|
+
### P0 — pure logic, no mocking needed
|
|
34
|
+
|
|
35
|
+
These services are either pure functions or have tight logic pockets that
|
|
36
|
+
pay back well in tests:
|
|
37
|
+
|
|
38
|
+
1. **`src/services/worksheet-content.service.ts`** — already has a test
|
|
39
|
+
file. Extend it to cover the new `WorksheetContentService` class
|
|
40
|
+
wrapper (`mergeProgress`, `parseGenerationContent`, `parseQuestionMeta`
|
|
41
|
+
delegations).
|
|
42
|
+
2. **`src/services/flashcard-progress.service.ts`** — `calculateSM2`,
|
|
43
|
+
`inferConfidence`, `confidenceToQuality` are pure and
|
|
44
|
+
decision-table-shaped. Add `flashcard-progress.service.test.ts`
|
|
45
|
+
covering:
|
|
46
|
+
- SM-2 first-correct interval depends on `consecutiveIncorrect` /
|
|
47
|
+
`totalIncorrect` thresholds (1d, 3d, 1d).
|
|
48
|
+
- SM-2 on `quality < 3` resets interval/reps and gives a +4h delay
|
|
49
|
+
only when `consecutiveIncorrect === 0 && totalIncorrect > 0`.
|
|
50
|
+
- `inferConfidence` returns `'hard'` when `!isCorrect`, regardless of
|
|
51
|
+
other params.
|
|
52
|
+
- `confidenceToQuality` mapping (`easy→5`, `medium→4`, `hard→3`).
|
|
53
|
+
3. **`src/services/worksheet-generation.service.ts`** — tests already
|
|
54
|
+
exist but one is failing (the "override beats legacy" test). **Don't
|
|
55
|
+
fix the failing test.** Add more normalization cases to
|
|
56
|
+
`normalizeWorksheetProblemForDb`: MCQ with numeric answer string,
|
|
57
|
+
MCQ with text-match answer, TEXT with and without `mark_scheme`,
|
|
58
|
+
`forceMcq=true` coercion.
|
|
59
|
+
|
|
60
|
+
### P1 — services that only need a fake `db`
|
|
61
|
+
|
|
62
|
+
These services are easy to test with a hand-rolled fake `PrismaClient`
|
|
63
|
+
(see pattern in
|
|
64
|
+
[`src/services/notification.service.test.ts`](src/services/notification.service.test.ts)).
|
|
65
|
+
|
|
66
|
+
4. **`src/services/workspace-analytics.service.ts`** — pure aggregation
|
|
67
|
+
of Prisma results; mock the 5 `db.*.findMany/count` calls and assert
|
|
68
|
+
the streak, weekly activity, and accuracy math.
|
|
69
|
+
- Streak = 1 when only today is in the set.
|
|
70
|
+
- Streak stays 0 when most-recent study day is 2+ days ago.
|
|
71
|
+
- `weeklyActivity` has length 7, ordered oldest → today.
|
|
72
|
+
- `accuracy` rounds correctly with non-zero `completedQuestions`.
|
|
73
|
+
5. **`src/repositories/workspace.repository.ts`** — test
|
|
74
|
+
`workspaceAccessWhere(userId)` and `workspaceOwnerWhere(userId)`
|
|
75
|
+
return the expected Prisma `where` shape. Test the class's
|
|
76
|
+
`findByIdAccessible` / `findByIdOwned` call through to the fake
|
|
77
|
+
`db.workspace.findFirst` with the right `where`.
|
|
78
|
+
6. **`src/services/chat.service.ts`** — small surface; test
|
|
79
|
+
`editMessage` throws `FORBIDDEN` when `chat.userId !== userId`,
|
|
80
|
+
throws `NOT_FOUND` on missing chat, and success path calls
|
|
81
|
+
`PusherService.emitChannelEvent`. Stub `PusherService.*` the same
|
|
82
|
+
way `notification.service.test.ts` stubs `PusherService.emitNotificationNew`.
|
|
83
|
+
7. **`src/services/annotation.service.ts`** — `deleteHighlight` and
|
|
84
|
+
`deleteComment` ownership checks (FORBIDDEN vs NOT_FOUND).
|
|
85
|
+
`addComment` side effects: recipients exclude the author,
|
|
86
|
+
notification isn't sent when artifact version lookup returns null.
|
|
87
|
+
|
|
88
|
+
### P2 — services worth integration-style tests
|
|
89
|
+
|
|
90
|
+
These are orchestration-heavy. Unit tests are lower value unless you're
|
|
91
|
+
willing to mock Stripe / AI session. Skip unless time permits:
|
|
92
|
+
|
|
93
|
+
- `src/services/auth.service.ts` — `login` credential failure paths
|
|
94
|
+
(wrong password, deleted user, missing user).
|
|
95
|
+
- `src/services/invitation.service.ts` — `acceptInvite` idempotency
|
|
96
|
+
(P2002 duplicate membership returns the already-a-member shape),
|
|
97
|
+
email-mismatch path.
|
|
98
|
+
- `src/services/admin.service.ts` — `listUsers` pagination math,
|
|
99
|
+
`deletePlan` deactivation when active subs exist.
|
|
100
|
+
- `src/services/payment.service.ts` — `reuseCheckoutUrlIfSessionStillOpen`
|
|
101
|
+
branch logic (requires a fake Stripe client).
|
|
102
|
+
|
|
103
|
+
### P3 — skip
|
|
104
|
+
|
|
105
|
+
`src/services/media-analysis.service.ts`, `podcast.service.ts`,
|
|
106
|
+
`worksheet.service.ts#generateFromPrompt`, `copilot.service.ts` — all
|
|
107
|
+
multi-step pipelines with external side effects. Not worth
|
|
108
|
+
unit-testing; they belong to integration/E2E tests with a real or
|
|
109
|
+
containerized Prisma + mocked AI. Don't bother here.
|
|
110
|
+
|
|
111
|
+
## Testing conventions to follow
|
|
112
|
+
|
|
113
|
+
### Framework
|
|
114
|
+
|
|
115
|
+
- `node:test` + `node:assert/strict`. See
|
|
116
|
+
[`src/lib/worksheet-generation.test.ts`](src/services/worksheet-generation.service.test.ts)
|
|
117
|
+
and
|
|
118
|
+
[`src/services/notification.service.test.ts`](src/services/notification.service.test.ts)
|
|
119
|
+
for the exact shape.
|
|
120
|
+
- Each test file lives next to the source (`foo.service.ts` ↔
|
|
121
|
+
`foo.service.test.ts`). `npm test` already globs them.
|
|
122
|
+
- Use `import { test } from 'node:test'` + `import assert from
|
|
123
|
+
'node:assert/strict'`. No `describe`/`it` wrappers, just
|
|
124
|
+
`test('name', () => {...})`.
|
|
125
|
+
|
|
126
|
+
### Faking Prisma
|
|
127
|
+
|
|
128
|
+
Copy the pattern from
|
|
129
|
+
[`src/services/notification.service.test.ts`](src/services/notification.service.test.ts).
|
|
130
|
+
Build a minimal fake: `{ modelName: { findFirst: async () => …, create:
|
|
131
|
+
async () => …, count: async () => … } }` and cast it with `as any` when
|
|
132
|
+
passing into the service constructor:
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
const svc = new WorkspaceAnalyticsService(fakeDb as any);
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Only stub the methods your test actually touches. Keep fakes inline in
|
|
139
|
+
the test file — don't create a shared fixtures module yet.
|
|
140
|
+
|
|
141
|
+
### Stubbing Pusher / email / Stripe
|
|
142
|
+
|
|
143
|
+
Follow the notification-service pattern: monkey-patch the static method
|
|
144
|
+
for the duration of the test and restore it at the end.
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
const original = PusherService.emitNotificationReadState;
|
|
148
|
+
PusherService.emitNotificationReadState = async () => {};
|
|
149
|
+
try {
|
|
150
|
+
// …act, assert…
|
|
151
|
+
} finally {
|
|
152
|
+
PusherService.emitNotificationReadState = original;
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
For Stripe, inject a fake client by re-exporting `stripe` from
|
|
157
|
+
`src/lib/stripe.ts` as a `let` (it already is) and overwriting it per
|
|
158
|
+
test. Or, preferred: test against the service after refactoring it to
|
|
159
|
+
accept a Stripe client in the constructor (only do this if it's a
|
|
160
|
+
one-line change — don't go refactoring again).
|
|
161
|
+
|
|
162
|
+
### Import paths
|
|
163
|
+
|
|
164
|
+
- `tsx` resolves `.js` specifiers; follow existing style (e.g.
|
|
165
|
+
`import … from './foo.service.js'` even though the file is `.ts`).
|
|
166
|
+
- Prefer relative imports; there are no path aliases.
|
|
167
|
+
|
|
168
|
+
## What NOT to do
|
|
169
|
+
|
|
170
|
+
1. **Don't fix the pre-existing failing test** in
|
|
171
|
+
`worksheet-generation.service.test.ts` (the "override beats preset
|
|
172
|
+
and legacy" one). It's flagged in `REFACTOR_NOTES.md` as the user's
|
|
173
|
+
in-progress work.
|
|
174
|
+
2. **Don't spin up a real database.** No `@prisma/client` mocking
|
|
175
|
+
libraries. Hand-rolled fakes only.
|
|
176
|
+
3. **Don't switch test frameworks**, don't add `describe`/`it`, don't
|
|
177
|
+
pull in `vitest` or `jest`.
|
|
178
|
+
4. **Don't test routers.** They're thin wrappers now; any behavior
|
|
179
|
+
there is covered by testing the underlying service.
|
|
180
|
+
5. **Don't change service/repository code** unless a test reveals an
|
|
181
|
+
actual bug. Tests are the goal; refactoring-while-testing is out of
|
|
182
|
+
scope.
|
|
183
|
+
6. **Don't test P3 items.** They need integration tests, not units.
|
|
184
|
+
|
|
185
|
+
## Acceptance criteria
|
|
186
|
+
|
|
187
|
+
When you're done:
|
|
188
|
+
|
|
189
|
+
- `npm test` passes (except the one pre-existing failure, which should
|
|
190
|
+
remain exactly as-is — still 1 fail, but every new test you add
|
|
191
|
+
passes).
|
|
192
|
+
- `npx tsc --noEmit` is clean.
|
|
193
|
+
- Every new test file ends in `.service.test.ts` or `.repository.test.ts`
|
|
194
|
+
and lives next to the source file.
|
|
195
|
+
- Each new test has a clear `test('verb: scenario → expected', …)` name.
|
|
196
|
+
- No new runtime dependencies in `package.json`. (Dev-deps only if
|
|
197
|
+
truly necessary, but you shouldn't need any.)
|
|
198
|
+
|
|
199
|
+
## Starter: which files to create
|
|
200
|
+
|
|
201
|
+
Create these test files, in this order, stopping when context runs low:
|
|
202
|
+
|
|
203
|
+
1. `src/services/flashcard-progress.service.test.ts` — **P0, easy win**
|
|
204
|
+
2. `src/services/workspace-analytics.service.test.ts` — **P1, high value**
|
|
205
|
+
3. `src/repositories/workspace.repository.test.ts`
|
|
206
|
+
4. `src/services/chat.service.test.ts`
|
|
207
|
+
5. `src/services/annotation.service.test.ts`
|
|
208
|
+
|
|
209
|
+
Extend these existing files:
|
|
210
|
+
|
|
211
|
+
6. `src/services/worksheet-content.service.test.ts` — add
|
|
212
|
+
`WorksheetContentService` class wrapper tests.
|
|
213
|
+
7. `src/services/worksheet-generation.service.test.ts` — add more
|
|
214
|
+
`normalizeWorksheetProblemForDb` cases (don't touch the failing
|
|
215
|
+
test).
|
|
216
|
+
|
|
217
|
+
Report back with:
|
|
218
|
+
|
|
219
|
+
- Number of test files added/extended.
|
|
220
|
+
- Total test count delta (`before → after`).
|
|
221
|
+
- Any bugs you found along the way — log them in
|
|
222
|
+
`REFACTOR_NOTES.md` instead of fixing silently.
|
|
223
|
+
|
|
224
|
+
Good luck. Go wide, not deep — better to cover 7 services shallowly than
|
|
225
|
+
1 service exhaustively at this stage.
|
package/dist/context.d.ts
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
import type { CreateExpressContextOptions } from "@trpc/server/adapters/express";
|
|
2
2
|
import { prisma } from "./lib/prisma.js";
|
|
3
3
|
import cookie from "cookie";
|
|
4
|
+
export type SessionUser = {
|
|
5
|
+
id: string;
|
|
6
|
+
emailVerified: boolean;
|
|
7
|
+
isSystemAdmin: boolean;
|
|
8
|
+
};
|
|
4
9
|
export declare function createContext({ req, res }: CreateExpressContextOptions): Promise<{
|
|
5
10
|
db: import("@prisma/client").PrismaClient<import("@prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
6
|
-
session:
|
|
11
|
+
session: null;
|
|
12
|
+
req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
13
|
+
res: import("express").Response<any, Record<string, any>>;
|
|
14
|
+
cookies: cookie.Cookies;
|
|
15
|
+
} | {
|
|
16
|
+
db: import("@prisma/client").PrismaClient<import("@prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client/runtime/library").DefaultArgs>;
|
|
17
|
+
session: {
|
|
18
|
+
user: SessionUser;
|
|
19
|
+
};
|
|
7
20
|
req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
8
21
|
res: import("express").Response<any, Record<string, any>>;
|
|
9
22
|
cookies: cookie.Cookies;
|
package/dist/context.js
CHANGED
|
@@ -3,10 +3,31 @@ import { verifyCustomAuthCookie } from "./lib/auth.js";
|
|
|
3
3
|
import cookie from "cookie";
|
|
4
4
|
export async function createContext({ req, res }) {
|
|
5
5
|
const cookies = cookie.parse(req.headers.cookie ?? "");
|
|
6
|
-
// Only use custom auth cookie
|
|
7
6
|
const custom = verifyCustomAuthCookie(cookies["auth_token"]);
|
|
8
7
|
if (custom) {
|
|
9
|
-
|
|
8
|
+
const user = await prisma.user.findUnique({
|
|
9
|
+
where: { id: custom.userId },
|
|
10
|
+
select: {
|
|
11
|
+
id: true,
|
|
12
|
+
emailVerified: true,
|
|
13
|
+
role: { select: { name: true } },
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
if (!user) {
|
|
17
|
+
return { db: prisma, session: null, req, res, cookies };
|
|
18
|
+
}
|
|
19
|
+
const sessionUser = {
|
|
20
|
+
id: user.id,
|
|
21
|
+
emailVerified: !!user.emailVerified,
|
|
22
|
+
isSystemAdmin: user.role?.name === "System Admin",
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
db: prisma,
|
|
26
|
+
session: { user: sessionUser },
|
|
27
|
+
req,
|
|
28
|
+
res,
|
|
29
|
+
cookies,
|
|
30
|
+
};
|
|
10
31
|
}
|
|
11
32
|
return { db: prisma, session: null, req, res, cookies };
|
|
12
33
|
}
|