oneie 2.0.2 → 2.0.5
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/AGENTS.md +245 -0
- package/CLAUDE.md +725 -0
- package/LICENSE.md +84 -0
- package/README.md +489 -931
- package/folders.yaml +78 -17
- package/one/.obsidian/app.json +1 -0
- package/one/.obsidian/appearance.json +1 -0
- package/one/.obsidian/core-plugins.json +33 -0
- package/one/.obsidian/workspace.json +211 -0
- package/one/connections/a2a.md +551 -0
- package/one/connections/acp.md +761 -0
- package/one/connections/acps.md +731 -0
- package/one/connections/agentkit.md +349 -0
- package/one/connections/agui.md +767 -0
- package/one/connections/any-backend.md +1702 -0
- package/one/connections/ap2.md +998 -0
- package/one/connections/api-docs.md +1891 -0
- package/one/connections/api.md +2190 -0
- package/one/connections/architecture-diagram.md +94 -0
- package/one/connections/communications.md +449 -0
- package/one/connections/connections.md +339 -0
- package/one/connections/copilotkit.md +1559 -0
- package/one/connections/cryptonetworks.md +781 -0
- package/one/connections/documentation.md +1120 -0
- package/one/connections/effect.md +279 -0
- package/one/connections/elizaos.md +1290 -0
- package/one/connections/inference.md +58 -0
- package/one/connections/kyc.md +632 -0
- package/one/connections/mcp.md +842 -0
- package/one/connections/membership.md +1152 -0
- package/one/connections/middleware.md +1067 -0
- package/one/connections/multitenant.md +1341 -0
- package/one/connections/n8n.md +1015 -0
- package/one/connections/patterns.md +89 -0
- package/one/connections/protocols.md +279 -0
- package/one/connections/relationships.md +107 -0
- package/one/connections/schema.md +587 -0
- package/one/connections/service-layer.md +550 -0
- package/one/connections/structure.md +0 -0
- package/one/connections/vectors.md +207 -0
- package/one/connections/wordpress.md +1302 -0
- package/one/connections/workflow-copy.md +905 -0
- package/one/connections/workflow-examples.md +741 -0
- package/one/connections/workflow.md +905 -0
- package/one/connections/workflows/delegation.md +885 -0
- package/one/connections/workflows/frontend.md +1037 -0
- package/one/connections/workflows/strategy.md +903 -0
- package/one/connections/workflows/tasks.md +698 -0
- package/one/connections/x402.md +1249 -0
- package/one/events/CASCADE-2-BACKEND-AGNOSTIC.md +412 -0
- package/one/events/FEATURE-2-4-COMPLETE.md +302 -0
- package/one/events/FEATURE_2_3_COMPLETE.md +575 -0
- package/one/events/GROUPS-MIGRATION.md +625 -0
- package/one/events/INSTALL-TESTS.md +293 -0
- package/one/events/INTEGRATION-ARCHITECTURE.md +561 -0
- package/one/events/INTEGRATION-CHECKLIST.md +1234 -0
- package/one/events/INTEGRATION-ORCHESTRATION.md +2623 -0
- package/one/events/INTEGRATION-SUMMARY.md +653 -0
- package/one/events/MIGRATION-REPORT.md +435 -0
- package/one/events/MIGRATION.md +69 -0
- package/one/events/README-archived.md +519 -0
- package/one/events/TEST-SUMMARY.md +393 -0
- package/one/events/TESTS-QUICK-REF.md +262 -0
- package/one/events/events.md +545 -0
- package/one/groups/groups.md +543 -0
- package/one/groups/one.md +599 -0
- package/one/groups/revenue.md +673 -0
- package/one/groups/strategy.md +869 -0
- package/one/groups/vision.md +98 -0
- package/one/knowledge/CLOUDFLARE_ENV_SETUP.md +49 -0
- package/one/knowledge/ai-platform.md +305 -0
- package/one/knowledge/architecture-any-backend.md +1366 -0
- package/one/knowledge/architecture-diagram.md +94 -0
- package/one/knowledge/architecture-frontend.md +930 -0
- package/one/knowledge/architecture.md +2077 -0
- package/one/knowledge/crypto.md +960 -0
- package/one/knowledge/docs/flow.md +0 -0
- package/one/knowledge/dsl.md +1660 -0
- package/one/knowledge/files.md +2471 -0
- package/one/knowledge/frontend.md +1038 -0
- package/one/knowledge/hono.md +2109 -0
- package/one/knowledge/implementation-examples.md +2536 -0
- package/one/knowledge/inference-score.md +159 -0
- package/one/knowledge/knowledge.md +642 -0
- package/one/knowledge/language.md +980 -0
- package/one/knowledge/lessons-learned.md +70 -0
- package/one/knowledge/ontology-6-dimensions.md +0 -0
- package/one/knowledge/ontology-documentation.md +356 -0
- package/one/knowledge/ontology-engineering-specification.md +1292 -0
- package/one/knowledge/ontology-engineering.md +1652 -0
- package/one/knowledge/ontology-frontend-copy-2.md +1492 -0
- package/one/knowledge/ontology-frontend-copy.md +753 -0
- package/one/knowledge/ontology-frontend-specifications.md +2188 -0
- package/one/knowledge/ontology-frontend.md +2427 -0
- package/one/knowledge/ontology-minimal.yaml +299 -0
- package/one/knowledge/ontology.md +2830 -0
- package/one/knowledge/ontology.md.backup +2822 -0
- package/one/knowledge/ontology.yaml +1165 -0
- package/one/knowledge/patterns/backend/convex-mutation-pattern.md +100 -0
- package/one/knowledge/patterns/backend/convex-query-pattern.md +88 -0
- package/one/knowledge/patterns/backend/mutation-template.md +231 -0
- package/one/knowledge/patterns/backend/query-template.md +267 -0
- package/one/knowledge/patterns/backend/service-template.md +237 -0
- package/one/knowledge/patterns/design/component-architecture.md +399 -0
- package/one/knowledge/patterns/design/test-driven-design-pattern.md +162 -0
- package/one/knowledge/patterns/design/wireframe-template.md +216 -0
- package/one/knowledge/patterns/frontend/component-template.md +195 -0
- package/one/knowledge/patterns/frontend/form-template.md +276 -0
- package/one/knowledge/patterns/frontend/page-template.md +178 -0
- package/one/knowledge/patterns/frontend/react-component-pattern.md +128 -0
- package/one/knowledge/patterns/test/acceptance-criteria-template.md +378 -0
- package/one/knowledge/patterns/test/technical-test-template.md +544 -0
- package/one/knowledge/patterns/test/test-driven-pattern.md +140 -0
- package/one/knowledge/patterns/test/user-flow-template.md +254 -0
- package/one/knowledge/provider-creation-guide.md +1064 -0
- package/one/knowledge/quality-loop.md +401 -0
- package/one/knowledge/readme.md +131 -0
- package/one/knowledge/rules.md +626 -0
- package/one/knowledge/score.md +67 -0
- package/one/knowledge/specifications.md +855 -0
- package/one/knowledge/tags.md +130 -0
- package/one/knowledge/todo.md +251 -0
- package/one/license.md +84 -0
- package/one/people/anthony-o-connell.md +440 -0
- package/one/people/people.md +567 -0
- package/one/things/CHECKLIST.md +356 -0
- package/one/things/ONE.md +510 -0
- package/one/things/agents/agent-backend.md +1401 -0
- package/one/things/agents/agent-builder.md +955 -0
- package/one/things/agents/agent-clean.md +709 -0
- package/one/things/agents/agent-clone.md +1341 -0
- package/one/things/agents/agent-designer.md +2177 -0
- package/one/things/agents/agent-director.md +1508 -0
- package/one/things/agents/agent-documenter.md +1049 -0
- package/one/things/agents/agent-frontend.md +1119 -0
- package/one/things/agents/agent-integrator.md +1192 -0
- package/one/things/agents/agent-problem-solver.md +1379 -0
- package/one/things/agents/agent-quality.md +1353 -0
- package/one/things/agents/agent-sales.md +986 -0
- package/one/things/cascade/cascade.yaml +464 -0
- package/one/things/cascade/docs/examples/1-1-agent-prompts/design.md +470 -0
- package/one/things/cascade/docs/examples/1-1-agent-prompts/tests.md +264 -0
- package/one/things/cascade/docs/examples/1-1-agent-prompts.md +486 -0
- package/one/things/cascade/docs/examples/1-2-yaml-orchestrator/design.md +497 -0
- package/one/things/cascade/docs/examples/1-2-yaml-orchestrator/tests.md +227 -0
- package/one/things/cascade/docs/examples/1-2-yaml-orchestrator.md +516 -0
- package/one/things/cascade/docs/examples/1-3-event-coordination/design.md +544 -0
- package/one/things/cascade/docs/examples/1-3-event-coordination/tests.md +223 -0
- package/one/things/cascade/docs/examples/1-3-event-coordination.md +508 -0
- package/one/things/cascade/docs/examples/1-4-knowledge-management/design.md +609 -0
- package/one/things/cascade/docs/examples/1-4-knowledge-management/tests.md +195 -0
- package/one/things/cascade/docs/examples/1-4-knowledge-management.md +577 -0
- package/one/things/cascade/docs/examples/1-5-quality-loops/design.md +797 -0
- package/one/things/cascade/docs/examples/1-5-quality-loops/tests.md +212 -0
- package/one/things/cascade/docs/examples/1-5-quality-loops.md +641 -0
- package/one/things/cascade/docs/examples/1-6-numbering-structure/design.md +610 -0
- package/one/things/cascade/docs/examples/1-6-numbering-structure/tests.md +213 -0
- package/one/things/cascade/docs/examples/1-6-numbering-structure.md +575 -0
- package/one/things/cascade/docs/examples/readme.md +222 -0
- package/one/things/cascade/docs/getting-started.md +515 -0
- package/one/things/cascade/docs/workflow.md +1372 -0
- package/one/things/cascade/readme.md +336 -0
- package/one/things/cascade/templates/feature-template.md +267 -0
- package/one/things/claude/agents/advocacy-activation-manager.md +685 -0
- package/one/things/claude/agents/advocacy-campaign-designer.md +663 -0
- package/one/things/claude/agents/analyst.md +483 -0
- package/one/things/claude/agents/architect.md +480 -0
- package/one/things/claude/agents/brand-identity-specialist.md +513 -0
- package/one/things/claude/agents/bstp-token-strategist.md +667 -0
- package/one/things/claude/agents/builder-repo.md +489 -0
- package/one/things/claude/agents/bullstamp-community-builder.md +574 -0
- package/one/things/claude/agents/bullstamp-marketing-orchestrator.md +506 -0
- package/one/things/claude/agents/bulltilt-platform-growth.md +567 -0
- package/one/things/claude/agents/company-bullstamp-character.md +587 -0
- package/one/things/claude/agents/company-bullstamp-community.md +292 -0
- package/one/things/claude/agents/company-bullstamp-marketing.md +292 -0
- package/one/things/claude/agents/company-bullstamp-token.md +292 -0
- package/one/things/claude/agents/company-bulltilt-growth.md +292 -0
- package/one/things/claude/agents/content-bibliography-formatter.md +381 -0
- package/one/things/claude/agents/content-calendar-planner.md +448 -0
- package/one/things/claude/agents/content-chapter-formatter.md +488 -0
- package/one/things/claude/agents/content-formatter.md +546 -0
- package/one/things/claude/agents/content-hook-specialist.md +462 -0
- package/one/things/claude/agents/content-image-formatter.md +535 -0
- package/one/things/claude/agents/content-introduction-formatter.md +485 -0
- package/one/things/claude/agents/content-multiplication-engine.md +556 -0
- package/one/things/claude/agents/content-playbook-writer.md +448 -0
- package/one/things/claude/agents/content-team-manager.md +622 -0
- package/one/things/claude/agents/content-toc-formatter.md +522 -0
- package/one/things/claude/agents/convex-backend-specialist.md +2561 -0
- package/one/things/claude/agents/core-manager.md +582 -0
- package/one/things/claude/agents/core-master.md +403 -0
- package/one/things/claude/agents/cross-functional-manager.md +471 -0
- package/one/things/claude/agents/crypto-airdrop-strategist.md +602 -0
- package/one/things/claude/agents/crypto-analytics-educator.md +553 -0
- package/one/things/claude/agents/crypto-architecture-specialist.md +466 -0
- package/one/things/claude/agents/crypto-community-analyst.md +298 -0
- package/one/things/claude/agents/crypto-community-psychologist.md +509 -0
- package/one/things/claude/agents/crypto-dex-optimization-expert.md +538 -0
- package/one/things/claude/agents/crypto-dex-optimizer.md +292 -0
- package/one/things/claude/agents/crypto-diamond-formation-specialist.md +513 -0
- package/one/things/claude/agents/crypto-diamond-hands.md +292 -0
- package/one/things/claude/agents/crypto-ecosystem-expansion-manager.md +554 -0
- package/one/things/claude/agents/crypto-engagement-specialist.md +540 -0
- package/one/things/claude/agents/crypto-market-researcher.md +292 -0
- package/one/things/claude/agents/crypto-marketing-orchestrator.md +523 -0
- package/one/things/claude/agents/crypto-network-effect-amplifier.md +569 -0
- package/one/things/claude/agents/crypto-optimization-analyst.md +554 -0
- package/one/things/claude/agents/crypto-strategic-synthesizer.md +517 -0
- package/one/things/claude/agents/crypto-team-manager.md +387 -0
- package/one/things/claude/agents/crypto-token-analyst.md +278 -0
- package/one/things/claude/agents/crypto-viral-content-creator.md +546 -0
- package/one/things/claude/agents/crypto-wallet-identification-expert.md +517 -0
- package/one/things/claude/agents/crypto-wallet-identifier.md +292 -0
- package/one/things/claude/agents/customer-journey-designer.md +481 -0
- package/one/things/claude/agents/customer-success-manager.md +581 -0
- package/one/things/claude/agents/dev.md +413 -0
- package/one/things/claude/agents/documenter.md +546 -0
- package/one/things/claude/agents/elevate-marketing-orchestrator.md +410 -0
- package/one/things/claude/agents/engagement-specialist.md +509 -0
- package/one/things/claude/agents/engineering-architect.md +387 -0
- package/one/things/claude/agents/engineering-business-analyst.md +537 -0
- package/one/things/claude/agents/engineering-developer.md +387 -0
- package/one/things/claude/agents/engineering-director.md +282 -0
- package/one/things/claude/agents/engineering-ingestor.md +649 -0
- package/one/things/claude/agents/engineering-product-manager.md +537 -0
- package/one/things/claude/agents/engineering-product-owner.md +537 -0
- package/one/things/claude/agents/engineering-project-coordinator.md +537 -0
- package/one/things/claude/agents/engineering-quality-assurance.md +393 -0
- package/one/things/claude/agents/engineering-team-manager.md +512 -0
- package/one/things/claude/agents/engineering-user-experience.md +387 -0
- package/one/things/claude/agents/framework-elevate-manager.md +294 -0
- package/one/things/claude/agents/improver.md +763 -0
- package/one/things/claude/agents/intelligence-team-manager.md +385 -0
- package/one/things/claude/agents/lead-capture-expert.md +466 -0
- package/one/things/claude/agents/lead-magnet-creator.md +453 -0
- package/one/things/claude/agents/market-research-analyst.md +412 -0
- package/one/things/claude/agents/marketing-brand-identity.md +314 -0
- package/one/things/claude/agents/marketing-content-hooks.md +450 -0
- package/one/things/claude/agents/marketing-content-multiplier.md +326 -0
- package/one/things/claude/agents/marketing-content-poster.md +361 -0
- package/one/things/claude/agents/marketing-customer-journey.md +326 -0
- package/one/things/claude/agents/marketing-director.md +397 -0
- package/one/things/claude/agents/marketing-engagement.md +326 -0
- package/one/things/claude/agents/marketing-lead-capture.md +326 -0
- package/one/things/claude/agents/marketing-lead-magnet.md +326 -0
- package/one/things/claude/agents/marketing-network-effects.md +326 -0
- package/one/things/claude/agents/marketing-nurture-campaigns.md +326 -0
- package/one/things/claude/agents/marketing-share-optimizer.md +326 -0
- package/one/things/claude/agents/marketing-team-manager.md +446 -0
- package/one/things/claude/agents/marketing-viral-growth.md +201 -0
- package/one/things/claude/agents/mission-commander.md +373 -0
- package/one/things/claude/agents/network-effect-analyst.md +587 -0
- package/one/things/claude/agents/nextjs-15-specialist.md +1547 -0
- package/one/things/claude/agents/npx.md +890 -0
- package/one/things/claude/agents/nurture-campaign-manager.md +531 -0
- package/one/things/claude/agents/one-master.md +355 -0
- package/one/things/claude/agents/one-orchestrator.md +315 -0
- package/one/things/claude/agents/one.md +601 -0
- package/one/things/claude/agents/playbook-generator.md +503 -0
- package/one/things/claude/agents/pm.md +326 -0
- package/one/things/claude/agents/po.md +345 -0
- package/one/things/claude/agents/qa.md +336 -0
- package/one/things/claude/agents/research-foundation-analyst.md +307 -0
- package/one/things/claude/agents/research-intelligence-gatherer.md +408 -0
- package/one/things/claude/agents/research-market-analyst.md +307 -0
- package/one/things/claude/agents/research-team-manager.md +482 -0
- package/one/things/claude/agents/sales-environment-optimizer.md +494 -0
- package/one/things/claude/agents/sales-team-manager.md +400 -0
- package/one/things/claude/agents/sales-upsell-strategist.md +307 -0
- package/one/things/claude/agents/service-advocacy-campaigns.md +307 -0
- package/one/things/claude/agents/service-advocacy-manager.md +307 -0
- package/one/things/claude/agents/service-success-manager.md +307 -0
- package/one/things/claude/agents/service-team-manager.md +400 -0
- package/one/things/claude/agents/shadcn-ui-design-system-specialist.md +2302 -0
- package/one/things/claude/agents/share-optimization-specialist.md +551 -0
- package/one/things/claude/agents/sm.md +327 -0
- package/one/things/claude/agents/story-teller.md +473 -0
- package/one/things/claude/agents/task-master.md +596 -0
- package/one/things/claude/agents/tauri-cross-platform-specialist.md +1827 -0
- package/one/things/claude/agents/tester.md +556 -0
- package/one/things/claude/agents/the-bull-character-manager.md +580 -0
- package/one/things/claude/agents/tools-playbook-generator.md +489 -0
- package/one/things/claude/agents/turbo-repo-builder.md +316 -0
- package/one/things/claude/agents/upsell-strategist.md +480 -0
- package/one/things/claude/agents/ux-expert.md +335 -0
- package/one/things/claude/agents/viral-growth-orchestrator.md +497 -0
- package/one/things/claude/claude-code-hooks-development.json +21 -0
- package/one/things/claude/claude-code-hooks-production.json +21 -0
- package/one/things/claude/claude-code-hooks.json +25 -0
- package/one/things/claude/commands/agent.md +104 -0
- package/one/things/claude/commands/cascade-status.md +128 -0
- package/one/things/claude/commands/ingest.md +290 -0
- package/one/things/claude/commands/ingestor.md +136 -0
- package/one/things/claude/commands/mission.md +83 -0
- package/one/things/claude/commands/npx.md +133 -0
- package/one/things/claude/commands/one.md +440 -0
- package/one/things/claude/commands/quality-check.md +204 -0
- package/one/things/claude/commands/smart-route.md +220 -0
- package/one/things/claude/commands/start.md +121 -0
- package/one/things/claude/commands/story.md +83 -0
- package/one/things/claude/commands/task.md +173 -0
- package/one/things/claude/hook-bypass.json +32 -0
- package/one/things/claude/hooks/agent-hook-config.json +427 -0
- package/one/things/claude/hooks/agent-hook-manager.js +525 -0
- package/one/things/claude/hooks/agent-load-balancer.js +271 -0
- package/one/things/claude/hooks/agent-request-interceptor.js +70 -0
- package/one/things/claude/hooks/build-hook.sh +156 -0
- package/one/things/claude/hooks/cascade-feedback.js +297 -0
- package/one/things/claude/hooks/cascade-integration-hooks.js +648 -0
- package/one/things/claude/hooks/cleanup-hook.sh +201 -0
- package/one/things/claude/hooks/continuous-improvement-monitor.js +510 -0
- package/one/things/claude/hooks/file-organization-engine.js +427 -0
- package/one/things/claude/hooks/file-organization-hook.sh +80 -0
- package/one/things/claude/hooks/file-organization-monitor.js +269 -0
- package/one/things/claude/hooks/format-hook.sh +43 -0
- package/one/things/claude/hooks/hook-bypass.sh +293 -0
- package/one/things/claude/hooks/hook-config-manager.js +202 -0
- package/one/things/claude/hooks/hook-debouncer.sh +62 -0
- package/one/things/claude/hooks/hook-logger.sh +89 -0
- package/one/things/claude/hooks/hook-orchestrator.js +662 -0
- package/one/things/claude/hooks/hook-performance-report.js +120 -0
- package/one/things/claude/hooks/lint-hook.sh +140 -0
- package/one/things/claude/hooks/mcp-cascade-integration.js +816 -0
- package/one/things/claude/hooks/memory-optimizer.js +510 -0
- package/one/things/claude/hooks/notification-hook.sh +204 -0
- package/one/things/claude/hooks/ontology-compliance.js +394 -0
- package/one/things/claude/hooks/ontology-hook-manager.js +316 -0
- package/one/things/claude/hooks/ontology-validation-engine.js +317 -0
- package/one/things/claude/hooks/ontology-validation-hook.sh +86 -0
- package/one/things/claude/hooks/performance-metrics.json +25 -0
- package/one/things/claude/hooks/performance-monitoring-hook.js +422 -0
- package/one/things/claude/hooks/quality-scoring-engine.js +834 -0
- package/one/things/claude/hooks/security-hook.sh +256 -0
- package/one/things/claude/hooks/simple-load-balancer.js +238 -0
- package/one/things/claude/hooks/startup-optimizer.js +625 -0
- package/one/things/claude/hooks/story-scoring-system.js +445 -0
- package/one/things/claude/hooks/story-validation-engine.js +473 -0
- package/one/things/claude/hooks/story-validation-hook-enhanced.sh +210 -0
- package/one/things/claude/hooks/story-validation-hook.sh +145 -0
- package/one/things/claude/hooks/structure-synchronizer.js +194 -0
- package/one/things/claude/hooks/sub-agent-output-validator.js +647 -0
- package/one/things/claude/hooks/sub-agent-validation-hook.js +343 -0
- package/one/things/claude/hooks/test-hook.sh +145 -0
- package/one/things/claude/hooks/test-story-validation.sh +170 -0
- package/one/things/claude/hooks/trinity-validation-system.js +392 -0
- package/one/things/claude/settings-local.json +86 -0
- package/one/things/cli/cli-code.md +652 -0
- package/one/things/cli/cli-compiler-code.md +652 -0
- package/one/things/cli/cli.md +1068 -0
- package/one/things/components/card-shadcn.md +929 -0
- package/one/things/components/card.md +1050 -0
- package/one/things/components.md +1669 -0
- package/one/things/componets.md +4 -0
- package/one/things/creator-diagram.md +166 -0
- package/one/things/examples/children/lemonade-stand.md +366 -0
- package/one/things/examples/enterprise/crm-saas.md +1429 -0
- package/one/things/features/1-1-agent-prompts/design.md +470 -0
- package/one/things/features/1-1-agent-prompts/tests.md +264 -0
- package/one/things/features/1-1-agent-prompts.md +486 -0
- package/one/things/features/1-2-yaml-orchestrator/design.md +497 -0
- package/one/things/features/1-2-yaml-orchestrator/tests.md +227 -0
- package/one/things/features/1-2-yaml-orchestrator.md +516 -0
- package/one/things/features/1-3-event-coordination/design.md +544 -0
- package/one/things/features/1-3-event-coordination/tests.md +223 -0
- package/one/things/features/1-3-event-coordination.md +508 -0
- package/one/things/features/1-4-knowledge-management/design.md +609 -0
- package/one/things/features/1-4-knowledge-management/tests.md +195 -0
- package/one/things/features/1-4-knowledge-management.md +577 -0
- package/one/things/features/1-5-quality-loops/design.md +797 -0
- package/one/things/features/1-5-quality-loops/tests.md +212 -0
- package/one/things/features/1-5-quality-loops.md +641 -0
- package/one/things/features/1-6-numbering-structure/design.md +610 -0
- package/one/things/features/1-6-numbering-structure/tests.md +213 -0
- package/one/things/features/1-6-numbering-structure.md +575 -0
- package/one/things/features/2-1-dataprovider-interface.md +2358 -0
- package/one/things/features/2-2-config-system.md +3075 -0
- package/one/things/features/2-3-effectts-services.md +1498 -0
- package/one/things/features/2-4-react-hooks.md +2120 -0
- package/one/things/features/2-5-auth-migration.md +2046 -0
- package/one/things/features/2-6-dashboard-migration.md +1985 -0
- package/one/things/features/2-7-alternative-providers.md +2505 -0
- package/one/things/features/2-7-implementation-report.md +680 -0
- package/one/things/features/2-cli.md +1235 -0
- package/one/things/features/2-design.md +1738 -0
- package/one/things/features/2-tests.md +520 -0
- package/one/things/features/AUTH_HOOKS_IMPLEMENTATION.md +521 -0
- package/one/things/features/DECOUPLING.md +272 -0
- package/one/things/features/DEPLOYMENT.md +452 -0
- package/one/things/features/IMPLEMENTATION_SUMMARY.md +316 -0
- package/one/things/features/dataprovider-interface/1-tests.md +1522 -0
- package/one/things/features/improve.md +843 -0
- package/one/things/features/remove-convex-deps.md +45 -0
- package/one/things/features/top-features.md +79 -0
- package/one/things/features/use-one-backend.md +1180 -0
- package/one/things/ideas/1-create-workflow.md +189 -0
- package/one/things/ideas/2-backend-agnostic-frontend.md +384 -0
- package/one/things/plans/1-create-workflow-status.md +555 -0
- package/one/things/plans/1-create-workflow.md +713 -0
- package/one/things/plans/2-backend-agnostic-frontend.md +543 -0
- package/one/things/plans/3-groups.md +502 -0
- package/one/things/plans/app.md +761 -0
- package/one/things/plans/backend-agnostic-frontend.md +323 -0
- package/one/things/plans/better-auth-any-backend-revised.md +1065 -0
- package/one/things/plans/better-auth-any-backend.md +1852 -0
- package/one/things/plans/better-auth-available-features.md +235 -0
- package/one/things/plans/big-plan.md +38 -0
- package/one/things/plans/convex-better-auth.md +1109 -0
- package/one/things/plans/convex-on-off.md +389 -0
- package/one/things/plans/deploy-to-cloudflare.md +581 -0
- package/one/things/plans/desktop.md +1121 -0
- package/one/things/plans/effect-components.md +1669 -0
- package/one/things/plans/effect.md +973 -0
- package/one/things/plans/email.md +953 -0
- package/one/things/plans/enhance-auth.md +1669 -0
- package/one/things/plans/install-components.md +198 -0
- package/one/things/plans/landing.md +728 -0
- package/one/things/plans/layout.md +205 -0
- package/one/things/plans/mail-backend.md +1308 -0
- package/one/things/plans/mail.md +2624 -0
- package/one/things/plans/next-features.md +83 -0
- package/one/things/plans/one.md +658 -0
- package/one/things/plans/ontology-6-dimensions.md +2216 -0
- package/one/things/plans/ontology-driven-strategy.md +866 -0
- package/one/things/plans/ontology-ui-approach.md +357 -0
- package/one/things/plans/open-agent.md +785 -0
- package/one/things/plans/organizations-to-groups.md +705 -0
- package/one/things/plans/performace.md +90 -0
- package/one/things/plans/release.md +432 -0
- package/one/things/plans/releases.md +809 -0
- package/one/things/plans/repos.md +76 -0
- package/one/things/plans/separate-copy-2.md +1293 -0
- package/one/things/plans/separate-copy-3.md +2458 -0
- package/one/things/plans/separate-copy.md +1293 -0
- package/one/things/plans/separate.md +1983 -0
- package/one/things/plans/shadcn-integration-summary.md +450 -0
- package/one/things/plans/sidebar.md +172 -0
- package/one/things/plans/small-fixes.md +5 -0
- package/one/things/plans/test-backend-connection.md +476 -0
- package/one/things/plans/workflow-files.md +1196 -0
- package/one/things/plans/workflow.md +1372 -0
- package/one/things/products/cascade-landing-page.md +737 -0
- package/one/things/products/cascade.md +1518 -0
- package/one/things/products/context-engineering.md +1427 -0
- package/one/things/products/onthology.md +0 -0
- package/one/things/products/ontology-ui-shadcn.md +1280 -0
- package/one/things/products/ontology-ui.md +1387 -0
- package/one/things/products/ontology.md +717 -0
- package/one/things/products/sdk.md +557 -0
- package/one/things/promptkit.md +903 -0
- package/one/things/service-providers-new.md +982 -0
- package/one/things/service-providers.md +1092 -0
- package/one/things/system.md +600 -0
- package/one/things/tests/2-1-dataprovider-interface.md +1144 -0
- package/one/things/tests/2-1-test-analysis.md +496 -0
- package/one/things/things.md +349 -0
- package/one/things/todo.md +1248 -0
- package/one/things/vision/elegant-interface.md +214 -0
- package/package.json +5 -2
|
@@ -0,0 +1,1308 @@
|
|
|
1
|
+
# Mail Backend Implementation Plan
|
|
2
|
+
|
|
3
|
+
**Goal:** Add complete email functionality to `mail.astro` using Resend, Convex, and Effect.ts to create a fully functional email client.
|
|
4
|
+
|
|
5
|
+
**Current State:** `mail.astro` exists with shadcn/ui Mail interface using mock data from `src/data/mail-data.ts`
|
|
6
|
+
|
|
7
|
+
**Target State:** Production email client with real Resend integration, database storage, and full CRUD operations.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Architecture Overview
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
┌─────────────────────────────────────────────────────────┐
|
|
15
|
+
│ FRONTEND (mail.astro) │
|
|
16
|
+
│ - MailLayout component (client:load) │
|
|
17
|
+
│ - Jotai state: selected, folder, search, tab │
|
|
18
|
+
│ - Convex hooks: useQuery, useMutation │
|
|
19
|
+
└──────────────────┬──────────────────────────────────────┘
|
|
20
|
+
│
|
|
21
|
+
↓ (Real-time queries & mutations)
|
|
22
|
+
┌─────────────────────────────────────────────────────────┐
|
|
23
|
+
│ MIDDLEWARE (Convex + Effect.ts) │
|
|
24
|
+
│ - Queries: list, get, search (read operations) │
|
|
25
|
+
│ - Mutations: send, archive, delete (write operations) │
|
|
26
|
+
│ - Services: EmailService (Effect.ts business logic) │
|
|
27
|
+
└──────────────────┬──────────────────────────────────────┘
|
|
28
|
+
│
|
|
29
|
+
↓ (Async actions via scheduler)
|
|
30
|
+
┌─────────────────────────────────────────────────────────┐
|
|
31
|
+
│ ACTIONS (Resend API) │
|
|
32
|
+
│ - sendEmailAction: Actually sends via Resend │
|
|
33
|
+
│ - processWebhookAction: Handles delivery events │
|
|
34
|
+
└──────────────────┬──────────────────────────────────────┘
|
|
35
|
+
│
|
|
36
|
+
↓ (HTTP webhooks)
|
|
37
|
+
┌─────────────────────────────────────────────────────────┐
|
|
38
|
+
│ RESEND SERVICE │
|
|
39
|
+
│ - Email delivery │
|
|
40
|
+
│ - Tracking (opens, clicks, bounces) │
|
|
41
|
+
│ - Webhooks (status updates) │
|
|
42
|
+
└─────────────────────────────────────────────────────────┘
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Phase 1: Database Schema & Ontology Mapping
|
|
48
|
+
|
|
49
|
+
### 1.1 Things (Entities)
|
|
50
|
+
|
|
51
|
+
**Email Entity:**
|
|
52
|
+
```typescript
|
|
53
|
+
// In things table
|
|
54
|
+
{
|
|
55
|
+
_id: Id<"things">,
|
|
56
|
+
type: "email",
|
|
57
|
+
name: string, // Subject line
|
|
58
|
+
status: "draft" | "sent" | "delivered" | "failed",
|
|
59
|
+
createdAt: number,
|
|
60
|
+
updatedAt: number,
|
|
61
|
+
properties: {
|
|
62
|
+
// Email-specific fields
|
|
63
|
+
from: string, // Sender email
|
|
64
|
+
fromName: string, // Sender display name
|
|
65
|
+
to: string[], // Recipients
|
|
66
|
+
cc?: string[],
|
|
67
|
+
bcc?: string[],
|
|
68
|
+
subject: string,
|
|
69
|
+
bodyHtml: string,
|
|
70
|
+
bodyText: string,
|
|
71
|
+
folder: "inbox" | "sent" | "drafts" | "trash" | "archive" | "junk",
|
|
72
|
+
read: boolean,
|
|
73
|
+
starred: boolean,
|
|
74
|
+
labels: string[], // ["work", "important", "meeting"]
|
|
75
|
+
threadId?: string, // For conversation threading
|
|
76
|
+
inReplyTo?: string, // Message ID of parent
|
|
77
|
+
references?: string[], // Thread references
|
|
78
|
+
attachments?: Array<{
|
|
79
|
+
name: string,
|
|
80
|
+
size: number,
|
|
81
|
+
type: string,
|
|
82
|
+
url: string
|
|
83
|
+
}>,
|
|
84
|
+
// Resend tracking
|
|
85
|
+
resendId?: string, // Resend message ID
|
|
86
|
+
deliveryStatus?: "sent" | "delivered" | "bounced" | "complained",
|
|
87
|
+
openedAt?: number,
|
|
88
|
+
clickedAt?: number,
|
|
89
|
+
bouncedAt?: number,
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**Email Template Entity:**
|
|
95
|
+
```typescript
|
|
96
|
+
{
|
|
97
|
+
_id: Id<"things">,
|
|
98
|
+
type: "email_template",
|
|
99
|
+
name: string, // Template name
|
|
100
|
+
status: "active" | "draft" | "archived",
|
|
101
|
+
properties: {
|
|
102
|
+
subject: string, // Can include {{variables}}
|
|
103
|
+
bodyHtml: string,
|
|
104
|
+
bodyText: string,
|
|
105
|
+
variables: string[], // ["user.name", "resetLink"]
|
|
106
|
+
category: "transactional" | "notification" | "marketing",
|
|
107
|
+
version: number,
|
|
108
|
+
previewText?: string,
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### 1.2 Connections
|
|
114
|
+
|
|
115
|
+
**Email Relationships:**
|
|
116
|
+
```typescript
|
|
117
|
+
// Sender → Email (who sent it)
|
|
118
|
+
{
|
|
119
|
+
fromThingId: userId,
|
|
120
|
+
toThingId: emailId,
|
|
121
|
+
relationshipType: "sent_email",
|
|
122
|
+
createdAt: number
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Recipient → Email (who received it)
|
|
126
|
+
{
|
|
127
|
+
fromThingId: userId,
|
|
128
|
+
toThingId: emailId,
|
|
129
|
+
relationshipType: "received_email",
|
|
130
|
+
createdAt: number
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Email → Email (reply threading)
|
|
134
|
+
{
|
|
135
|
+
fromThingId: replyEmailId,
|
|
136
|
+
toThingId: originalEmailId,
|
|
137
|
+
relationshipType: "reply_to",
|
|
138
|
+
createdAt: number
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### 1.3 Events
|
|
143
|
+
|
|
144
|
+
**Email Lifecycle Events:**
|
|
145
|
+
```typescript
|
|
146
|
+
// Email drafted
|
|
147
|
+
{
|
|
148
|
+
thingId: emailId,
|
|
149
|
+
eventType: "email_drafted",
|
|
150
|
+
timestamp: Date.now(),
|
|
151
|
+
actorType: "user",
|
|
152
|
+
actorId: userId,
|
|
153
|
+
metadata: { folder: "drafts" }
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Email sent
|
|
157
|
+
{
|
|
158
|
+
thingId: emailId,
|
|
159
|
+
eventType: "email_sent",
|
|
160
|
+
timestamp: Date.now(),
|
|
161
|
+
actorType: "user",
|
|
162
|
+
actorId: userId,
|
|
163
|
+
metadata: {
|
|
164
|
+
resendId: string,
|
|
165
|
+
recipients: string[],
|
|
166
|
+
subject: string
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Email delivered
|
|
171
|
+
{
|
|
172
|
+
thingId: emailId,
|
|
173
|
+
eventType: "email_delivered",
|
|
174
|
+
timestamp: Date.now(),
|
|
175
|
+
actorType: "system",
|
|
176
|
+
metadata: { resendId: string }
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Email opened
|
|
180
|
+
{
|
|
181
|
+
thingId: emailId,
|
|
182
|
+
eventType: "email_opened",
|
|
183
|
+
timestamp: Date.now(),
|
|
184
|
+
actorType: "user",
|
|
185
|
+
actorId: recipientId,
|
|
186
|
+
metadata: { openedAt: number }
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Email clicked
|
|
190
|
+
{
|
|
191
|
+
thingId: emailId,
|
|
192
|
+
eventType: "email_clicked",
|
|
193
|
+
timestamp: Date.now(),
|
|
194
|
+
actorType: "user",
|
|
195
|
+
actorId: recipientId,
|
|
196
|
+
metadata: { clickedLink: string }
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Email failed
|
|
200
|
+
{
|
|
201
|
+
thingId: emailId,
|
|
202
|
+
eventType: "email_failed",
|
|
203
|
+
timestamp: Date.now(),
|
|
204
|
+
actorType: "system",
|
|
205
|
+
metadata: {
|
|
206
|
+
error: string,
|
|
207
|
+
reason: "bounce" | "complaint" | "rejected"
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### 1.4 Tags
|
|
213
|
+
|
|
214
|
+
**Email Categories:**
|
|
215
|
+
```typescript
|
|
216
|
+
// Tag for categorization
|
|
217
|
+
{
|
|
218
|
+
category: "folder",
|
|
219
|
+
value: "inbox" | "sent" | "drafts" | "trash"
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
{
|
|
223
|
+
category: "label",
|
|
224
|
+
value: "work" | "personal" | "important" | "meeting"
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
{
|
|
228
|
+
category: "status",
|
|
229
|
+
value: "read" | "unread" | "starred" | "archived"
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## Phase 2: Backend Services (Effect.ts)
|
|
236
|
+
|
|
237
|
+
### 2.1 Email Service
|
|
238
|
+
|
|
239
|
+
**File:** `convex/services/email/email.ts`
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
import { Effect } from "effect"
|
|
243
|
+
import { ConvexDatabase } from "../providers/convex"
|
|
244
|
+
import { ResendProvider } from "../providers/resend"
|
|
245
|
+
|
|
246
|
+
export class EmailService extends Effect.Service<EmailService>()("EmailService", {
|
|
247
|
+
effect: Effect.gen(function* () {
|
|
248
|
+
const db = yield* ConvexDatabase
|
|
249
|
+
const resend = yield* ResendProvider
|
|
250
|
+
|
|
251
|
+
return {
|
|
252
|
+
// Create draft email
|
|
253
|
+
createDraft: (args: CreateDraftArgs) =>
|
|
254
|
+
Effect.gen(function* () {
|
|
255
|
+
// 1. Validate user
|
|
256
|
+
const user = yield* Effect.tryPromise(() => db.get(args.userId))
|
|
257
|
+
if (!user) {
|
|
258
|
+
return yield* Effect.fail({
|
|
259
|
+
_tag: "UserNotFound",
|
|
260
|
+
message: "User not found"
|
|
261
|
+
})
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// 2. Create email entity
|
|
265
|
+
const emailId = yield* Effect.tryPromise(() =>
|
|
266
|
+
db.insert("things", {
|
|
267
|
+
type: "email",
|
|
268
|
+
name: args.subject,
|
|
269
|
+
status: "draft",
|
|
270
|
+
createdAt: Date.now(),
|
|
271
|
+
updatedAt: Date.now(),
|
|
272
|
+
properties: {
|
|
273
|
+
from: user.properties.email,
|
|
274
|
+
fromName: user.properties.name,
|
|
275
|
+
to: args.to,
|
|
276
|
+
cc: args.cc,
|
|
277
|
+
bcc: args.bcc,
|
|
278
|
+
subject: args.subject,
|
|
279
|
+
bodyHtml: args.bodyHtml,
|
|
280
|
+
bodyText: args.bodyText,
|
|
281
|
+
folder: "drafts",
|
|
282
|
+
read: true,
|
|
283
|
+
starred: false,
|
|
284
|
+
labels: args.labels || [],
|
|
285
|
+
}
|
|
286
|
+
})
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
// 3. Create connection (user authored email)
|
|
290
|
+
yield* Effect.tryPromise(() =>
|
|
291
|
+
db.insert("connections", {
|
|
292
|
+
fromThingId: args.userId,
|
|
293
|
+
toThingId: emailId,
|
|
294
|
+
relationshipType: "sent_email",
|
|
295
|
+
createdAt: Date.now()
|
|
296
|
+
})
|
|
297
|
+
)
|
|
298
|
+
|
|
299
|
+
// 4. Log event
|
|
300
|
+
yield* Effect.tryPromise(() =>
|
|
301
|
+
db.insert("events", {
|
|
302
|
+
thingId: emailId,
|
|
303
|
+
eventType: "email_drafted",
|
|
304
|
+
timestamp: Date.now(),
|
|
305
|
+
actorType: "user",
|
|
306
|
+
actorId: args.userId,
|
|
307
|
+
metadata: { folder: "drafts" }
|
|
308
|
+
})
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
return emailId
|
|
312
|
+
}),
|
|
313
|
+
|
|
314
|
+
// Send email
|
|
315
|
+
send: (args: SendEmailArgs) =>
|
|
316
|
+
Effect.gen(function* () {
|
|
317
|
+
// 1. Get email
|
|
318
|
+
const email = yield* Effect.tryPromise(() => db.get(args.emailId))
|
|
319
|
+
if (!email) {
|
|
320
|
+
return yield* Effect.fail({
|
|
321
|
+
_tag: "EmailNotFound",
|
|
322
|
+
message: "Email not found"
|
|
323
|
+
})
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// 2. Update status to sending
|
|
327
|
+
yield* Effect.tryPromise(() =>
|
|
328
|
+
db.patch(args.emailId, {
|
|
329
|
+
status: "sent",
|
|
330
|
+
updatedAt: Date.now(),
|
|
331
|
+
properties: {
|
|
332
|
+
...email.properties,
|
|
333
|
+
folder: "sent"
|
|
334
|
+
}
|
|
335
|
+
})
|
|
336
|
+
)
|
|
337
|
+
|
|
338
|
+
// 3. Schedule actual send via action (async)
|
|
339
|
+
yield* Effect.promise(() =>
|
|
340
|
+
db.scheduler.runAfter(0, internal.email.sendEmailAction, {
|
|
341
|
+
emailId: args.emailId
|
|
342
|
+
})
|
|
343
|
+
)
|
|
344
|
+
|
|
345
|
+
// 4. Log event
|
|
346
|
+
yield* Effect.tryPromise(() =>
|
|
347
|
+
db.insert("events", {
|
|
348
|
+
thingId: args.emailId,
|
|
349
|
+
eventType: "email_sent",
|
|
350
|
+
timestamp: Date.now(),
|
|
351
|
+
actorType: "user",
|
|
352
|
+
actorId: args.userId,
|
|
353
|
+
metadata: {
|
|
354
|
+
recipients: email.properties.to,
|
|
355
|
+
subject: email.properties.subject
|
|
356
|
+
}
|
|
357
|
+
})
|
|
358
|
+
)
|
|
359
|
+
|
|
360
|
+
return { success: true, emailId: args.emailId }
|
|
361
|
+
}),
|
|
362
|
+
|
|
363
|
+
// List emails by folder
|
|
364
|
+
listByFolder: (args: ListByFolderArgs) =>
|
|
365
|
+
Effect.gen(function* () {
|
|
366
|
+
const emails = yield* Effect.tryPromise(() =>
|
|
367
|
+
db.query("things")
|
|
368
|
+
.withIndex("type", q => q.eq("type", "email"))
|
|
369
|
+
.filter(q =>
|
|
370
|
+
q.eq(q.field("properties.folder"), args.folder)
|
|
371
|
+
)
|
|
372
|
+
.order("desc")
|
|
373
|
+
.collect()
|
|
374
|
+
)
|
|
375
|
+
|
|
376
|
+
return emails
|
|
377
|
+
}),
|
|
378
|
+
|
|
379
|
+
// Search emails
|
|
380
|
+
search: (args: SearchEmailArgs) =>
|
|
381
|
+
Effect.gen(function* () {
|
|
382
|
+
const allEmails = yield* Effect.tryPromise(() =>
|
|
383
|
+
db.query("things")
|
|
384
|
+
.withIndex("type", q => q.eq("type", "email"))
|
|
385
|
+
.collect()
|
|
386
|
+
)
|
|
387
|
+
|
|
388
|
+
// Filter by search query
|
|
389
|
+
const query = args.query.toLowerCase()
|
|
390
|
+
const filtered = allEmails.filter(email =>
|
|
391
|
+
email.properties.subject.toLowerCase().includes(query) ||
|
|
392
|
+
email.properties.bodyText.toLowerCase().includes(query) ||
|
|
393
|
+
email.properties.fromName.toLowerCase().includes(query) ||
|
|
394
|
+
email.properties.from.toLowerCase().includes(query)
|
|
395
|
+
)
|
|
396
|
+
|
|
397
|
+
return filtered
|
|
398
|
+
}),
|
|
399
|
+
|
|
400
|
+
// Archive email
|
|
401
|
+
archive: (args: ArchiveEmailArgs) =>
|
|
402
|
+
Effect.gen(function* () {
|
|
403
|
+
const email = yield* Effect.tryPromise(() => db.get(args.emailId))
|
|
404
|
+
if (!email) {
|
|
405
|
+
return yield* Effect.fail({
|
|
406
|
+
_tag: "EmailNotFound",
|
|
407
|
+
message: "Email not found"
|
|
408
|
+
})
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
yield* Effect.tryPromise(() =>
|
|
412
|
+
db.patch(args.emailId, {
|
|
413
|
+
updatedAt: Date.now(),
|
|
414
|
+
properties: {
|
|
415
|
+
...email.properties,
|
|
416
|
+
folder: "archive"
|
|
417
|
+
}
|
|
418
|
+
})
|
|
419
|
+
)
|
|
420
|
+
|
|
421
|
+
// Log event
|
|
422
|
+
yield* Effect.tryPromise(() =>
|
|
423
|
+
db.insert("events", {
|
|
424
|
+
thingId: args.emailId,
|
|
425
|
+
eventType: "email_archived",
|
|
426
|
+
timestamp: Date.now(),
|
|
427
|
+
actorType: "user",
|
|
428
|
+
actorId: args.userId,
|
|
429
|
+
metadata: {}
|
|
430
|
+
})
|
|
431
|
+
)
|
|
432
|
+
|
|
433
|
+
return { success: true }
|
|
434
|
+
}),
|
|
435
|
+
|
|
436
|
+
// Delete email (move to trash)
|
|
437
|
+
delete: (args: DeleteEmailArgs) =>
|
|
438
|
+
Effect.gen(function* () {
|
|
439
|
+
const email = yield* Effect.tryPromise(() => db.get(args.emailId))
|
|
440
|
+
if (!email) {
|
|
441
|
+
return yield* Effect.fail({
|
|
442
|
+
_tag: "EmailNotFound",
|
|
443
|
+
message: "Email not found"
|
|
444
|
+
})
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
yield* Effect.tryPromise(() =>
|
|
448
|
+
db.patch(args.emailId, {
|
|
449
|
+
updatedAt: Date.now(),
|
|
450
|
+
properties: {
|
|
451
|
+
...email.properties,
|
|
452
|
+
folder: "trash"
|
|
453
|
+
}
|
|
454
|
+
})
|
|
455
|
+
)
|
|
456
|
+
|
|
457
|
+
return { success: true }
|
|
458
|
+
}),
|
|
459
|
+
|
|
460
|
+
// Mark as read/unread
|
|
461
|
+
markRead: (args: MarkReadArgs) =>
|
|
462
|
+
Effect.gen(function* () {
|
|
463
|
+
const email = yield* Effect.tryPromise(() => db.get(args.emailId))
|
|
464
|
+
if (!email) {
|
|
465
|
+
return yield* Effect.fail({
|
|
466
|
+
_tag: "EmailNotFound",
|
|
467
|
+
message: "Email not found"
|
|
468
|
+
})
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
yield* Effect.tryPromise(() =>
|
|
472
|
+
db.patch(args.emailId, {
|
|
473
|
+
updatedAt: Date.now(),
|
|
474
|
+
properties: {
|
|
475
|
+
...email.properties,
|
|
476
|
+
read: args.read
|
|
477
|
+
}
|
|
478
|
+
})
|
|
479
|
+
)
|
|
480
|
+
|
|
481
|
+
return { success: true }
|
|
482
|
+
}),
|
|
483
|
+
|
|
484
|
+
// Get folder counts
|
|
485
|
+
getFolderCounts: (args: GetFolderCountsArgs) =>
|
|
486
|
+
Effect.gen(function* () {
|
|
487
|
+
const allEmails = yield* Effect.tryPromise(() =>
|
|
488
|
+
db.query("things")
|
|
489
|
+
.withIndex("type", q => q.eq("type", "email"))
|
|
490
|
+
.collect()
|
|
491
|
+
)
|
|
492
|
+
|
|
493
|
+
const counts = {
|
|
494
|
+
inbox: allEmails.filter(e => e.properties.folder === "inbox").length,
|
|
495
|
+
sent: allEmails.filter(e => e.properties.folder === "sent").length,
|
|
496
|
+
drafts: allEmails.filter(e => e.properties.folder === "drafts").length,
|
|
497
|
+
trash: allEmails.filter(e => e.properties.folder === "trash").length,
|
|
498
|
+
archive: allEmails.filter(e => e.properties.folder === "archive").length,
|
|
499
|
+
junk: allEmails.filter(e => e.properties.folder === "junk").length,
|
|
500
|
+
unread: allEmails.filter(e => !e.properties.read).length,
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
return counts
|
|
504
|
+
})
|
|
505
|
+
}
|
|
506
|
+
}),
|
|
507
|
+
dependencies: [ConvexDatabase.Default, ResendProvider.Default]
|
|
508
|
+
}) {}
|
|
509
|
+
|
|
510
|
+
// Type definitions
|
|
511
|
+
interface CreateDraftArgs {
|
|
512
|
+
userId: Id<"things">
|
|
513
|
+
to: string[]
|
|
514
|
+
cc?: string[]
|
|
515
|
+
bcc?: string[]
|
|
516
|
+
subject: string
|
|
517
|
+
bodyHtml: string
|
|
518
|
+
bodyText: string
|
|
519
|
+
labels?: string[]
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
interface SendEmailArgs {
|
|
523
|
+
emailId: Id<"things">
|
|
524
|
+
userId: Id<"things">
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
interface ListByFolderArgs {
|
|
528
|
+
folder: "inbox" | "sent" | "drafts" | "trash" | "archive" | "junk"
|
|
529
|
+
userId: Id<"things">
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
interface SearchEmailArgs {
|
|
533
|
+
query: string
|
|
534
|
+
userId: Id<"things">
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
interface ArchiveEmailArgs {
|
|
538
|
+
emailId: Id<"things">
|
|
539
|
+
userId: Id<"things">
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
interface DeleteEmailArgs {
|
|
543
|
+
emailId: Id<"things">
|
|
544
|
+
userId: Id<"things">
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
interface MarkReadArgs {
|
|
548
|
+
emailId: Id<"things">
|
|
549
|
+
read: boolean
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
interface GetFolderCountsArgs {
|
|
553
|
+
userId: Id<"things">
|
|
554
|
+
}
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
### 2.2 Resend Provider
|
|
558
|
+
|
|
559
|
+
**File:** `convex/services/providers/resend.ts`
|
|
560
|
+
|
|
561
|
+
```typescript
|
|
562
|
+
import { Effect, Layer } from "effect"
|
|
563
|
+
import { Resend } from "@convex-dev/resend"
|
|
564
|
+
import { components } from "../../_generated/api"
|
|
565
|
+
|
|
566
|
+
export class ResendProvider extends Effect.Service<ResendProvider>()("ResendProvider", {
|
|
567
|
+
effect: Effect.gen(function* () {
|
|
568
|
+
const resend = new Resend(components.resend, { testMode: false })
|
|
569
|
+
|
|
570
|
+
return {
|
|
571
|
+
send: (args: ResendSendArgs) =>
|
|
572
|
+
Effect.tryPromise({
|
|
573
|
+
try: async () => {
|
|
574
|
+
const result = await resend.sendEmail(ctx, {
|
|
575
|
+
from: args.from,
|
|
576
|
+
to: args.to,
|
|
577
|
+
cc: args.cc,
|
|
578
|
+
bcc: args.bcc,
|
|
579
|
+
subject: args.subject,
|
|
580
|
+
html: args.html,
|
|
581
|
+
text: args.text,
|
|
582
|
+
})
|
|
583
|
+
return result
|
|
584
|
+
},
|
|
585
|
+
catch: (error) => ({
|
|
586
|
+
_tag: "ResendError" as const,
|
|
587
|
+
message: error instanceof Error ? error.message : "Unknown error"
|
|
588
|
+
})
|
|
589
|
+
})
|
|
590
|
+
}
|
|
591
|
+
})
|
|
592
|
+
}) {}
|
|
593
|
+
|
|
594
|
+
interface ResendSendArgs {
|
|
595
|
+
from: string
|
|
596
|
+
to: string[]
|
|
597
|
+
cc?: string[]
|
|
598
|
+
bcc?: string[]
|
|
599
|
+
subject: string
|
|
600
|
+
html: string
|
|
601
|
+
text: string
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
export const ResendProviderLive = Layer.succeed(ResendProvider, ResendProvider)
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
---
|
|
608
|
+
|
|
609
|
+
## Phase 3: Convex Layer (Queries, Mutations, Actions)
|
|
610
|
+
|
|
611
|
+
### 3.1 Queries
|
|
612
|
+
|
|
613
|
+
**File:** `convex/queries/email.ts`
|
|
614
|
+
|
|
615
|
+
```typescript
|
|
616
|
+
import { query } from "./_generated/server"
|
|
617
|
+
import { v } from "convex/values"
|
|
618
|
+
import { confect } from "convex-helpers/server/confect"
|
|
619
|
+
import { Effect } from "effect"
|
|
620
|
+
import { EmailService } from "./services/email/email"
|
|
621
|
+
import { MainLayer } from "./services/layers"
|
|
622
|
+
|
|
623
|
+
// List emails by folder
|
|
624
|
+
export const list = confect.query({
|
|
625
|
+
args: {
|
|
626
|
+
folder: v.union(
|
|
627
|
+
v.literal("inbox"),
|
|
628
|
+
v.literal("sent"),
|
|
629
|
+
v.literal("drafts"),
|
|
630
|
+
v.literal("trash"),
|
|
631
|
+
v.literal("archive"),
|
|
632
|
+
v.literal("junk")
|
|
633
|
+
),
|
|
634
|
+
userId: v.id("things"),
|
|
635
|
+
},
|
|
636
|
+
handler: (ctx, args) =>
|
|
637
|
+
Effect.gen(function* () {
|
|
638
|
+
const emailService = yield* EmailService
|
|
639
|
+
return yield* emailService.listByFolder(args)
|
|
640
|
+
}).pipe(Effect.provide(MainLayer))
|
|
641
|
+
})
|
|
642
|
+
|
|
643
|
+
// Get single email
|
|
644
|
+
export const get = confect.query({
|
|
645
|
+
args: { id: v.id("things") },
|
|
646
|
+
handler: (ctx, args) =>
|
|
647
|
+
Effect.gen(function* () {
|
|
648
|
+
const email = yield* Effect.tryPromise(() => ctx.db.get(args.id))
|
|
649
|
+
return email
|
|
650
|
+
}).pipe(Effect.provide(MainLayer))
|
|
651
|
+
})
|
|
652
|
+
|
|
653
|
+
// Search emails
|
|
654
|
+
export const search = confect.query({
|
|
655
|
+
args: {
|
|
656
|
+
query: v.string(),
|
|
657
|
+
userId: v.id("things"),
|
|
658
|
+
},
|
|
659
|
+
handler: (ctx, args) =>
|
|
660
|
+
Effect.gen(function* () {
|
|
661
|
+
const emailService = yield* EmailService
|
|
662
|
+
return yield* emailService.search(args)
|
|
663
|
+
}).pipe(Effect.provide(MainLayer))
|
|
664
|
+
})
|
|
665
|
+
|
|
666
|
+
// Get folder counts
|
|
667
|
+
export const folderCounts = confect.query({
|
|
668
|
+
args: { userId: v.id("things") },
|
|
669
|
+
handler: (ctx, args) =>
|
|
670
|
+
Effect.gen(function* () {
|
|
671
|
+
const emailService = yield* EmailService
|
|
672
|
+
return yield* emailService.getFolderCounts(args)
|
|
673
|
+
}).pipe(Effect.provide(MainLayer))
|
|
674
|
+
})
|
|
675
|
+
```
|
|
676
|
+
|
|
677
|
+
### 3.2 Mutations
|
|
678
|
+
|
|
679
|
+
**File:** `convex/mutations/email.ts`
|
|
680
|
+
|
|
681
|
+
```typescript
|
|
682
|
+
import { mutation } from "./_generated/server"
|
|
683
|
+
import { v } from "convex/values"
|
|
684
|
+
import { confect } from "convex-helpers/server/confect"
|
|
685
|
+
import { Effect } from "effect"
|
|
686
|
+
import { EmailService } from "./services/email/email"
|
|
687
|
+
import { MainLayer } from "./services/layers"
|
|
688
|
+
|
|
689
|
+
// Create draft
|
|
690
|
+
export const createDraft = confect.mutation({
|
|
691
|
+
args: {
|
|
692
|
+
userId: v.id("things"),
|
|
693
|
+
to: v.array(v.string()),
|
|
694
|
+
cc: v.optional(v.array(v.string())),
|
|
695
|
+
bcc: v.optional(v.array(v.string())),
|
|
696
|
+
subject: v.string(),
|
|
697
|
+
bodyHtml: v.string(),
|
|
698
|
+
bodyText: v.string(),
|
|
699
|
+
labels: v.optional(v.array(v.string())),
|
|
700
|
+
},
|
|
701
|
+
handler: (ctx, args) =>
|
|
702
|
+
Effect.gen(function* () {
|
|
703
|
+
const emailService = yield* EmailService
|
|
704
|
+
return yield* emailService.createDraft(args)
|
|
705
|
+
}).pipe(Effect.provide(MainLayer))
|
|
706
|
+
})
|
|
707
|
+
|
|
708
|
+
// Send email
|
|
709
|
+
export const send = confect.mutation({
|
|
710
|
+
args: {
|
|
711
|
+
emailId: v.id("things"),
|
|
712
|
+
userId: v.id("things"),
|
|
713
|
+
},
|
|
714
|
+
handler: (ctx, args) =>
|
|
715
|
+
Effect.gen(function* () {
|
|
716
|
+
const emailService = yield* EmailService
|
|
717
|
+
return yield* emailService.send(args)
|
|
718
|
+
}).pipe(Effect.provide(MainLayer))
|
|
719
|
+
})
|
|
720
|
+
|
|
721
|
+
// Archive email
|
|
722
|
+
export const archive = confect.mutation({
|
|
723
|
+
args: {
|
|
724
|
+
emailId: v.id("things"),
|
|
725
|
+
userId: v.id("things"),
|
|
726
|
+
},
|
|
727
|
+
handler: (ctx, args) =>
|
|
728
|
+
Effect.gen(function* () {
|
|
729
|
+
const emailService = yield* EmailService
|
|
730
|
+
return yield* emailService.archive(args)
|
|
731
|
+
}).pipe(Effect.provide(MainLayer))
|
|
732
|
+
})
|
|
733
|
+
|
|
734
|
+
// Delete email
|
|
735
|
+
export const deleteEmail = confect.mutation({
|
|
736
|
+
args: {
|
|
737
|
+
emailId: v.id("things"),
|
|
738
|
+
userId: v.id("things"),
|
|
739
|
+
},
|
|
740
|
+
handler: (ctx, args) =>
|
|
741
|
+
Effect.gen(function* () {
|
|
742
|
+
const emailService = yield* EmailService
|
|
743
|
+
return yield* emailService.delete(args)
|
|
744
|
+
}).pipe(Effect.provide(MainLayer))
|
|
745
|
+
})
|
|
746
|
+
|
|
747
|
+
// Mark as read/unread
|
|
748
|
+
export const markRead = confect.mutation({
|
|
749
|
+
args: {
|
|
750
|
+
emailId: v.id("things"),
|
|
751
|
+
read: v.boolean(),
|
|
752
|
+
},
|
|
753
|
+
handler: (ctx, args) =>
|
|
754
|
+
Effect.gen(function* () {
|
|
755
|
+
const emailService = yield* EmailService
|
|
756
|
+
return yield* emailService.markRead(args)
|
|
757
|
+
}).pipe(Effect.provide(MainLayer))
|
|
758
|
+
})
|
|
759
|
+
```
|
|
760
|
+
|
|
761
|
+
### 3.3 Actions
|
|
762
|
+
|
|
763
|
+
**File:** `convex/actions/email.ts`
|
|
764
|
+
|
|
765
|
+
```typescript
|
|
766
|
+
import { internalAction } from "./_generated/server"
|
|
767
|
+
import { v } from "convex/values"
|
|
768
|
+
import { Resend } from "@convex-dev/resend"
|
|
769
|
+
import { components, internal } from "./_generated/api"
|
|
770
|
+
|
|
771
|
+
// Actually send email via Resend
|
|
772
|
+
export const sendEmailAction = internalAction({
|
|
773
|
+
args: { emailId: v.id("things") },
|
|
774
|
+
handler: async (ctx, args) => {
|
|
775
|
+
// 1. Get email
|
|
776
|
+
const email = await ctx.runQuery(internal.email.getEmail, {
|
|
777
|
+
id: args.emailId
|
|
778
|
+
})
|
|
779
|
+
|
|
780
|
+
if (!email) {
|
|
781
|
+
throw new Error("Email not found")
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
// 2. Send via Resend
|
|
785
|
+
const resend = new Resend(components.resend, { testMode: false })
|
|
786
|
+
|
|
787
|
+
try {
|
|
788
|
+
const result = await resend.sendEmail(ctx, {
|
|
789
|
+
from: email.properties.from,
|
|
790
|
+
to: email.properties.to,
|
|
791
|
+
cc: email.properties.cc,
|
|
792
|
+
bcc: email.properties.bcc,
|
|
793
|
+
subject: email.properties.subject,
|
|
794
|
+
html: email.properties.bodyHtml,
|
|
795
|
+
text: email.properties.bodyText,
|
|
796
|
+
})
|
|
797
|
+
|
|
798
|
+
// 3. Update email with Resend ID
|
|
799
|
+
await ctx.runMutation(internal.email.updateResendId, {
|
|
800
|
+
emailId: args.emailId,
|
|
801
|
+
resendId: result.id,
|
|
802
|
+
})
|
|
803
|
+
|
|
804
|
+
// 4. Log delivery event
|
|
805
|
+
await ctx.runMutation(internal.email.logEvent, {
|
|
806
|
+
emailId: args.emailId,
|
|
807
|
+
eventType: "email_delivered",
|
|
808
|
+
metadata: { resendId: result.id }
|
|
809
|
+
})
|
|
810
|
+
|
|
811
|
+
return { success: true, resendId: result.id }
|
|
812
|
+
} catch (error) {
|
|
813
|
+
// Log failure event
|
|
814
|
+
await ctx.runMutation(internal.email.logEvent, {
|
|
815
|
+
emailId: args.emailId,
|
|
816
|
+
eventType: "email_failed",
|
|
817
|
+
metadata: {
|
|
818
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
819
|
+
}
|
|
820
|
+
})
|
|
821
|
+
|
|
822
|
+
throw error
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
})
|
|
826
|
+
```
|
|
827
|
+
|
|
828
|
+
---
|
|
829
|
+
|
|
830
|
+
## Phase 4: Frontend Integration
|
|
831
|
+
|
|
832
|
+
### 4.1 Update use-mail.ts with Convex
|
|
833
|
+
|
|
834
|
+
**File:** `src/components/mail/use-mail.ts`
|
|
835
|
+
|
|
836
|
+
```typescript
|
|
837
|
+
import { atom, useAtom } from "jotai"
|
|
838
|
+
import { Id } from "@/convex/_generated/dataModel"
|
|
839
|
+
|
|
840
|
+
export type MailFolder =
|
|
841
|
+
| "inbox"
|
|
842
|
+
| "drafts"
|
|
843
|
+
| "sent"
|
|
844
|
+
| "junk"
|
|
845
|
+
| "trash"
|
|
846
|
+
| "archive"
|
|
847
|
+
|
|
848
|
+
type Config = {
|
|
849
|
+
selected: Id<"things"> | null
|
|
850
|
+
activeFolder: MailFolder
|
|
851
|
+
searchQuery: string
|
|
852
|
+
activeTab: "all" | "unread"
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
const configAtom = atom<Config>({
|
|
856
|
+
selected: null,
|
|
857
|
+
activeFolder: "inbox",
|
|
858
|
+
searchQuery: "",
|
|
859
|
+
activeTab: "all",
|
|
860
|
+
})
|
|
861
|
+
|
|
862
|
+
export function useMail() {
|
|
863
|
+
return useAtom(configAtom)
|
|
864
|
+
}
|
|
865
|
+
```
|
|
866
|
+
|
|
867
|
+
### 4.2 Update MailList with Real Data
|
|
868
|
+
|
|
869
|
+
**File:** `src/components/mail/MailList.tsx`
|
|
870
|
+
|
|
871
|
+
```tsx
|
|
872
|
+
import { useQuery } from "convex/react"
|
|
873
|
+
import { api } from "@/convex/_generated/api"
|
|
874
|
+
import { formatDistanceToNow } from "date-fns"
|
|
875
|
+
import { cn } from "@/lib/utils"
|
|
876
|
+
import { Badge } from "@/components/ui/badge"
|
|
877
|
+
import { ScrollArea } from "@/components/ui/scroll-area"
|
|
878
|
+
import { useMail } from "./use-mail"
|
|
879
|
+
|
|
880
|
+
export function MailList({ userId }: { userId: string }) {
|
|
881
|
+
const [mail, setMail] = useMail()
|
|
882
|
+
|
|
883
|
+
// Real-time query from Convex
|
|
884
|
+
const emails = useQuery(api.email.list, {
|
|
885
|
+
folder: mail.activeFolder,
|
|
886
|
+
userId: userId as any, // Type assertion for now
|
|
887
|
+
})
|
|
888
|
+
|
|
889
|
+
// Filter by search query (client-side for now)
|
|
890
|
+
const filteredEmails = emails?.filter(email => {
|
|
891
|
+
if (!mail.searchQuery) return true
|
|
892
|
+
|
|
893
|
+
const query = mail.searchQuery.toLowerCase()
|
|
894
|
+
return (
|
|
895
|
+
email.properties.subject.toLowerCase().includes(query) ||
|
|
896
|
+
email.properties.bodyText.toLowerCase().includes(query) ||
|
|
897
|
+
email.properties.fromName.toLowerCase().includes(query)
|
|
898
|
+
)
|
|
899
|
+
}) || []
|
|
900
|
+
|
|
901
|
+
// Filter by tab
|
|
902
|
+
const displayEmails = mail.activeTab === "unread"
|
|
903
|
+
? filteredEmails.filter(e => !e.properties.read)
|
|
904
|
+
: filteredEmails
|
|
905
|
+
|
|
906
|
+
if (!emails) {
|
|
907
|
+
return <div className="p-8 text-center">Loading...</div>
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
if (displayEmails.length === 0) {
|
|
911
|
+
return (
|
|
912
|
+
<div className="flex items-center justify-center p-8 text-center text-sm text-muted-foreground">
|
|
913
|
+
No emails found
|
|
914
|
+
</div>
|
|
915
|
+
)
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
return (
|
|
919
|
+
<ScrollArea className="h-screen">
|
|
920
|
+
<div className="flex flex-col gap-2 p-4 pt-0">
|
|
921
|
+
{displayEmails.map((email) => (
|
|
922
|
+
<button
|
|
923
|
+
key={email._id}
|
|
924
|
+
className={cn(
|
|
925
|
+
"flex flex-col items-start gap-2 rounded-lg border p-3 text-left text-sm transition-all hover:bg-accent active:scale-[0.99]",
|
|
926
|
+
mail.selected === email._id && "bg-muted ring-2 ring-primary/20"
|
|
927
|
+
)}
|
|
928
|
+
onClick={() =>
|
|
929
|
+
setMail({
|
|
930
|
+
...mail,
|
|
931
|
+
selected: email._id,
|
|
932
|
+
})
|
|
933
|
+
}
|
|
934
|
+
>
|
|
935
|
+
<div className="flex w-full flex-col gap-1">
|
|
936
|
+
<div className="flex items-center">
|
|
937
|
+
<div className="flex items-center gap-2">
|
|
938
|
+
<div className={cn(
|
|
939
|
+
"font-semibold",
|
|
940
|
+
!email.properties.read && "text-primary"
|
|
941
|
+
)}>
|
|
942
|
+
{email.properties.fromName}
|
|
943
|
+
</div>
|
|
944
|
+
{!email.properties.read && (
|
|
945
|
+
<span className="flex size-2 rounded-full bg-blue-600 animate-pulse" />
|
|
946
|
+
)}
|
|
947
|
+
</div>
|
|
948
|
+
<div
|
|
949
|
+
className={cn(
|
|
950
|
+
"ml-auto text-xs",
|
|
951
|
+
mail.selected === email._id
|
|
952
|
+
? "text-foreground"
|
|
953
|
+
: "text-muted-foreground"
|
|
954
|
+
)}
|
|
955
|
+
>
|
|
956
|
+
{formatDistanceToNow(new Date(email.createdAt), {
|
|
957
|
+
addSuffix: true,
|
|
958
|
+
})}
|
|
959
|
+
</div>
|
|
960
|
+
</div>
|
|
961
|
+
<div className={cn(
|
|
962
|
+
"text-xs font-medium",
|
|
963
|
+
!email.properties.read && "text-primary"
|
|
964
|
+
)}>
|
|
965
|
+
{email.properties.subject}
|
|
966
|
+
</div>
|
|
967
|
+
</div>
|
|
968
|
+
<div className="line-clamp-2 text-xs text-muted-foreground">
|
|
969
|
+
{email.properties.bodyText.substring(0, 300)}
|
|
970
|
+
</div>
|
|
971
|
+
{email.properties.labels.length ? (
|
|
972
|
+
<div className="flex items-center gap-2">
|
|
973
|
+
{email.properties.labels.map((label) => (
|
|
974
|
+
<Badge key={label} variant="secondary" className="text-xs">
|
|
975
|
+
{label}
|
|
976
|
+
</Badge>
|
|
977
|
+
))}
|
|
978
|
+
</div>
|
|
979
|
+
) : null}
|
|
980
|
+
</button>
|
|
981
|
+
))}
|
|
982
|
+
</div>
|
|
983
|
+
</ScrollArea>
|
|
984
|
+
)
|
|
985
|
+
}
|
|
986
|
+
```
|
|
987
|
+
|
|
988
|
+
### 4.3 Update MailDisplay with Actions
|
|
989
|
+
|
|
990
|
+
**File:** `src/components/mail/MailDisplay.tsx`
|
|
991
|
+
|
|
992
|
+
```tsx
|
|
993
|
+
import { useQuery, useMutation } from "convex/react"
|
|
994
|
+
import { api } from "@/convex/_generated/api"
|
|
995
|
+
import { toast } from "sonner"
|
|
996
|
+
import { Archive, ArchiveX, Trash2, Reply } from "lucide-react"
|
|
997
|
+
import { Button } from "@/components/ui/button"
|
|
998
|
+
import { Textarea } from "@/components/ui/textarea"
|
|
999
|
+
import { useMail } from "./use-mail"
|
|
1000
|
+
import { useState } from "react"
|
|
1001
|
+
|
|
1002
|
+
export function MailDisplay({ userId }: { userId: string }) {
|
|
1003
|
+
const [mail] = useMail()
|
|
1004
|
+
const [replyText, setReplyText] = useState("")
|
|
1005
|
+
|
|
1006
|
+
// Get selected email
|
|
1007
|
+
const currentMail = useQuery(
|
|
1008
|
+
api.email.get,
|
|
1009
|
+
mail.selected ? { id: mail.selected } : "skip"
|
|
1010
|
+
)
|
|
1011
|
+
|
|
1012
|
+
// Mutations
|
|
1013
|
+
const archive = useMutation(api.email.archive)
|
|
1014
|
+
const deleteEmail = useMutation(api.email.deleteEmail)
|
|
1015
|
+
const markRead = useMutation(api.email.markRead)
|
|
1016
|
+
|
|
1017
|
+
const handleArchive = async () => {
|
|
1018
|
+
if (!mail.selected) return
|
|
1019
|
+
|
|
1020
|
+
await archive({ emailId: mail.selected, userId: userId as any })
|
|
1021
|
+
toast.success("Email archived")
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
const handleDelete = async () => {
|
|
1025
|
+
if (!mail.selected) return
|
|
1026
|
+
|
|
1027
|
+
await deleteEmail({ emailId: mail.selected, userId: userId as any })
|
|
1028
|
+
toast.success("Email deleted")
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
const handleReply = async (e: React.FormEvent) => {
|
|
1032
|
+
e.preventDefault()
|
|
1033
|
+
if (!replyText.trim() || !currentMail) return
|
|
1034
|
+
|
|
1035
|
+
// Create draft reply
|
|
1036
|
+
// TODO: Implement reply functionality
|
|
1037
|
+
toast.success("Reply sent")
|
|
1038
|
+
setReplyText("")
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
if (!currentMail) {
|
|
1042
|
+
return (
|
|
1043
|
+
<div className="flex h-full items-center justify-center p-8 text-center text-muted-foreground">
|
|
1044
|
+
No message selected
|
|
1045
|
+
</div>
|
|
1046
|
+
)
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
return (
|
|
1050
|
+
<div className="flex h-full flex-col">
|
|
1051
|
+
<div className="flex items-center p-2 gap-2">
|
|
1052
|
+
<Button variant="ghost" size="icon" onClick={handleArchive}>
|
|
1053
|
+
<Archive className="size-4" />
|
|
1054
|
+
</Button>
|
|
1055
|
+
<Button variant="ghost" size="icon" onClick={handleDelete}>
|
|
1056
|
+
<Trash2 className="size-4" />
|
|
1057
|
+
</Button>
|
|
1058
|
+
</div>
|
|
1059
|
+
|
|
1060
|
+
<div className="flex-1 p-4">
|
|
1061
|
+
<div className="font-semibold text-lg mb-2">
|
|
1062
|
+
{currentMail.properties.subject}
|
|
1063
|
+
</div>
|
|
1064
|
+
<div className="text-sm text-muted-foreground mb-4">
|
|
1065
|
+
From: {currentMail.properties.fromName} ({currentMail.properties.from})
|
|
1066
|
+
</div>
|
|
1067
|
+
<div
|
|
1068
|
+
className="prose prose-sm max-w-none"
|
|
1069
|
+
dangerouslySetInnerHTML={{ __html: currentMail.properties.bodyHtml }}
|
|
1070
|
+
/>
|
|
1071
|
+
</div>
|
|
1072
|
+
|
|
1073
|
+
<div className="border-t p-4">
|
|
1074
|
+
<form onSubmit={handleReply}>
|
|
1075
|
+
<Textarea
|
|
1076
|
+
placeholder="Reply..."
|
|
1077
|
+
value={replyText}
|
|
1078
|
+
onChange={(e) => setReplyText(e.target.value)}
|
|
1079
|
+
className="mb-2"
|
|
1080
|
+
/>
|
|
1081
|
+
<Button type="submit" size="sm">
|
|
1082
|
+
<Reply className="size-4 mr-2" />
|
|
1083
|
+
Send Reply
|
|
1084
|
+
</Button>
|
|
1085
|
+
</form>
|
|
1086
|
+
</div>
|
|
1087
|
+
</div>
|
|
1088
|
+
)
|
|
1089
|
+
}
|
|
1090
|
+
```
|
|
1091
|
+
|
|
1092
|
+
### 4.4 Update mail.astro
|
|
1093
|
+
|
|
1094
|
+
**File:** `src/pages/mail.astro`
|
|
1095
|
+
|
|
1096
|
+
```astro
|
|
1097
|
+
---
|
|
1098
|
+
import BaseLayout from '@/layouts/BaseLayout.astro'
|
|
1099
|
+
import { MailLayout } from '@/components/mail/MailLayout'
|
|
1100
|
+
import { auth } from '@/lib/auth'
|
|
1101
|
+
|
|
1102
|
+
// Get current user
|
|
1103
|
+
const session = await auth.api.getSession({
|
|
1104
|
+
headers: Astro.request.headers
|
|
1105
|
+
})
|
|
1106
|
+
|
|
1107
|
+
if (!session?.user) {
|
|
1108
|
+
return Astro.redirect('/login')
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
const userId = session.user.id
|
|
1112
|
+
---
|
|
1113
|
+
|
|
1114
|
+
<BaseLayout title="Mail">
|
|
1115
|
+
<div class="mail-container">
|
|
1116
|
+
<MailLayout client:load userId={userId} />
|
|
1117
|
+
</div>
|
|
1118
|
+
</BaseLayout>
|
|
1119
|
+
|
|
1120
|
+
<style>
|
|
1121
|
+
.mail-container {
|
|
1122
|
+
height: 100vh;
|
|
1123
|
+
width: 100vw;
|
|
1124
|
+
overflow: hidden;
|
|
1125
|
+
}
|
|
1126
|
+
</style>
|
|
1127
|
+
```
|
|
1128
|
+
|
|
1129
|
+
---
|
|
1130
|
+
|
|
1131
|
+
## Phase 5: Webhooks (Resend Events)
|
|
1132
|
+
|
|
1133
|
+
### 5.1 Webhook Handler
|
|
1134
|
+
|
|
1135
|
+
**File:** `convex/http/webhooks/resend.ts`
|
|
1136
|
+
|
|
1137
|
+
```typescript
|
|
1138
|
+
import { Hono } from "hono"
|
|
1139
|
+
import { HonoWithConvex, HttpRouterWithHono } from "convex-helpers/server/hono"
|
|
1140
|
+
import { internal } from "../../_generated/api"
|
|
1141
|
+
|
|
1142
|
+
const app: HonoWithConvex = new Hono()
|
|
1143
|
+
|
|
1144
|
+
app.post("/resend", async (c) => {
|
|
1145
|
+
const body = await c.req.json()
|
|
1146
|
+
|
|
1147
|
+
// Verify webhook signature (Resend provides this)
|
|
1148
|
+
// const signature = c.req.header("resend-signature")
|
|
1149
|
+
// if (!verifySignature(signature, body)) {
|
|
1150
|
+
// return c.json({ error: "Invalid signature" }, 401)
|
|
1151
|
+
// }
|
|
1152
|
+
|
|
1153
|
+
const { type, data } = body
|
|
1154
|
+
|
|
1155
|
+
switch (type) {
|
|
1156
|
+
case "email.sent":
|
|
1157
|
+
await c.env.runMutation(internal.email.handleEmailSent, {
|
|
1158
|
+
resendId: data.email_id,
|
|
1159
|
+
timestamp: Date.now()
|
|
1160
|
+
})
|
|
1161
|
+
break
|
|
1162
|
+
|
|
1163
|
+
case "email.delivered":
|
|
1164
|
+
await c.env.runMutation(internal.email.handleEmailDelivered, {
|
|
1165
|
+
resendId: data.email_id,
|
|
1166
|
+
timestamp: Date.now()
|
|
1167
|
+
})
|
|
1168
|
+
break
|
|
1169
|
+
|
|
1170
|
+
case "email.opened":
|
|
1171
|
+
await c.env.runMutation(internal.email.handleEmailOpened, {
|
|
1172
|
+
resendId: data.email_id,
|
|
1173
|
+
timestamp: Date.now()
|
|
1174
|
+
})
|
|
1175
|
+
break
|
|
1176
|
+
|
|
1177
|
+
case "email.clicked":
|
|
1178
|
+
await c.env.runMutation(internal.email.handleEmailClicked, {
|
|
1179
|
+
resendId: data.email_id,
|
|
1180
|
+
clickedLink: data.link,
|
|
1181
|
+
timestamp: Date.now()
|
|
1182
|
+
})
|
|
1183
|
+
break
|
|
1184
|
+
|
|
1185
|
+
case "email.bounced":
|
|
1186
|
+
await c.env.runMutation(internal.email.handleEmailBounced, {
|
|
1187
|
+
resendId: data.email_id,
|
|
1188
|
+
reason: data.bounce_type,
|
|
1189
|
+
timestamp: Date.now()
|
|
1190
|
+
})
|
|
1191
|
+
break
|
|
1192
|
+
|
|
1193
|
+
case "email.complained":
|
|
1194
|
+
await c.env.runMutation(internal.email.handleEmailComplained, {
|
|
1195
|
+
resendId: data.email_id,
|
|
1196
|
+
timestamp: Date.now()
|
|
1197
|
+
})
|
|
1198
|
+
break
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
return c.json({ success: true })
|
|
1202
|
+
})
|
|
1203
|
+
|
|
1204
|
+
export default new HttpRouterWithHono(app)
|
|
1205
|
+
```
|
|
1206
|
+
|
|
1207
|
+
---
|
|
1208
|
+
|
|
1209
|
+
## Implementation Checklist
|
|
1210
|
+
|
|
1211
|
+
### Phase 1: Database Setup
|
|
1212
|
+
- [ ] Add email entity type to things table
|
|
1213
|
+
- [ ] Add email_template entity type to things table
|
|
1214
|
+
- [ ] Add connection types: sent_email, received_email, reply_to
|
|
1215
|
+
- [ ] Add event types: email_drafted, email_sent, email_delivered, email_opened, etc.
|
|
1216
|
+
- [ ] Add tag categories: folder, label, status
|
|
1217
|
+
|
|
1218
|
+
### Phase 2: Backend Services
|
|
1219
|
+
- [ ] Create `convex/services/email/email.ts` (EmailService)
|
|
1220
|
+
- [ ] Create `convex/services/providers/resend.ts` (ResendProvider)
|
|
1221
|
+
- [ ] Implement createDraft, send, listByFolder, search, archive, delete, markRead
|
|
1222
|
+
- [ ] Add to MainLayer in `convex/services/layers.ts`
|
|
1223
|
+
|
|
1224
|
+
### Phase 3: Convex Layer
|
|
1225
|
+
- [ ] Create `convex/queries/email.ts` (list, get, search, folderCounts)
|
|
1226
|
+
- [ ] Create `convex/mutations/email.ts` (createDraft, send, archive, delete, markRead)
|
|
1227
|
+
- [ ] Create `convex/actions/email.ts` (sendEmailAction)
|
|
1228
|
+
- [ ] Create internal mutations for webhook handlers
|
|
1229
|
+
|
|
1230
|
+
### Phase 4: Frontend Integration
|
|
1231
|
+
- [ ] Update `src/components/mail/use-mail.ts` with proper types
|
|
1232
|
+
- [ ] Update `src/components/mail/MailList.tsx` with useQuery
|
|
1233
|
+
- [ ] Update `src/components/mail/MailDisplay.tsx` with useMutation
|
|
1234
|
+
- [ ] Update `src/components/mail/Nav.tsx` with dynamic counts
|
|
1235
|
+
- [ ] Update `src/pages/mail.astro` with auth check
|
|
1236
|
+
- [ ] Add Toaster component for notifications
|
|
1237
|
+
|
|
1238
|
+
### Phase 5: Webhooks
|
|
1239
|
+
- [ ] Create `convex/http/webhooks/resend.ts`
|
|
1240
|
+
- [ ] Configure Resend webhook URL in dashboard
|
|
1241
|
+
- [ ] Implement webhook signature verification
|
|
1242
|
+
- [ ] Test email tracking events
|
|
1243
|
+
|
|
1244
|
+
### Phase 6: Testing
|
|
1245
|
+
- [ ] Test draft creation
|
|
1246
|
+
- [ ] Test email sending (receives in real inbox)
|
|
1247
|
+
- [ ] Test folder navigation
|
|
1248
|
+
- [ ] Test search functionality
|
|
1249
|
+
- [ ] Test archive/delete operations
|
|
1250
|
+
- [ ] Test webhook delivery
|
|
1251
|
+
- [ ] Test real-time updates (open in 2 browsers)
|
|
1252
|
+
|
|
1253
|
+
---
|
|
1254
|
+
|
|
1255
|
+
## Dependencies to Install
|
|
1256
|
+
|
|
1257
|
+
```bash
|
|
1258
|
+
# Already installed
|
|
1259
|
+
✅ @convex-dev/resend
|
|
1260
|
+
✅ jotai
|
|
1261
|
+
✅ sonner
|
|
1262
|
+
✅ lucide-react
|
|
1263
|
+
✅ date-fns
|
|
1264
|
+
|
|
1265
|
+
# Need to install
|
|
1266
|
+
bun add @react-email/components
|
|
1267
|
+
bun add @react-email/render
|
|
1268
|
+
```
|
|
1269
|
+
|
|
1270
|
+
---
|
|
1271
|
+
|
|
1272
|
+
## Environment Variables
|
|
1273
|
+
|
|
1274
|
+
```bash
|
|
1275
|
+
# Already set
|
|
1276
|
+
RESEND_API_KEY=re_...
|
|
1277
|
+
RESEND_FROM_EMAIL=noreply@yourdomain.com
|
|
1278
|
+
|
|
1279
|
+
# Add for webhooks
|
|
1280
|
+
RESEND_WEBHOOK_SECRET=whsec_...
|
|
1281
|
+
```
|
|
1282
|
+
|
|
1283
|
+
---
|
|
1284
|
+
|
|
1285
|
+
## Success Criteria
|
|
1286
|
+
|
|
1287
|
+
### MVP (Minimum Viable Product)
|
|
1288
|
+
- ✅ Users can view emails in inbox
|
|
1289
|
+
- ✅ Users can compose and send emails
|
|
1290
|
+
- ✅ Emails deliver to real inboxes
|
|
1291
|
+
- ✅ Folder navigation works (Inbox, Sent, Drafts, Trash)
|
|
1292
|
+
- ✅ Search functionality works
|
|
1293
|
+
- ✅ Archive/Delete actions work
|
|
1294
|
+
- ✅ Real-time updates when emails arrive
|
|
1295
|
+
|
|
1296
|
+
### Full Features
|
|
1297
|
+
- ✅ Reply/Forward functionality
|
|
1298
|
+
- ✅ Email threading (conversations)
|
|
1299
|
+
- ✅ Attachments support
|
|
1300
|
+
- ✅ Rich text editor
|
|
1301
|
+
- ✅ Webhook tracking (opens, clicks)
|
|
1302
|
+
- ✅ Templates system
|
|
1303
|
+
- ✅ Scheduled sending
|
|
1304
|
+
- ✅ Email signatures
|
|
1305
|
+
|
|
1306
|
+
---
|
|
1307
|
+
|
|
1308
|
+
**Result:** A fully functional email client in `mail.astro` powered by Resend, Convex, and Effect.ts with real-time updates and production-ready email delivery.
|