Skip to content

shared: build a context-card diffing utility and validation layer #31

@ShantKhatri

Description

@ShantKhatri

Summary

Product doc section 4.5 describes 'Context Cards' — multiple curated cards per user (Professional, Hackathon, Community). Currently the cards.ts route handles creation, but there is no shared utility to validate card platform selections or diff two versions of a card.

Context

This utility lives in packages/shared so it can be used by both the web and mobile clients. The backend apps/backend/src/routes/cards.ts creates cards, but the validation is minimal.

Tasks

  • in packages/shared/src/cards.ts (new file), create:
    • validateCardPlatforms(platforms: string[]): ValidationResult — checks that all platform IDs in a card are in PLATFORMS, max 10 platforms, no duplicates.
    • diffCardPlatforms(oldCard: string[], newCard: string[]): { added: string[], removed: string[], unchanged: string[] } — pure diff utility.
    • type CardValidationResult = { valid: boolean; errors: string[] }.
  • export these from packages/shared/src/index.ts.
  • write comprehensive unit tests in packages/shared/src/__tests__/cards.test.ts covering edge cases: empty array, all-invalid platforms, duplicate platforms, max exceeded.
  • update the backend route apps/backend/src/routes/cards.ts to use validateCardPlatforms for input validation instead of ad-hoc checks.

Acceptance Criteria

  • shared utilities are typed, exported, and tested.
  • backend uses the shared validator.
  • pnpm -r test passes.

Difficulty

medium — cross-package logic, requires careful TypeScript type design and edge case coverage.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions