6.0 KiB
6.0 KiB
19. Backend Router — RemoveBrokers (Data Broker Removal)
meta: id: kordant-unified-restructure-19 feature: kordant-unified-restructure priority: P1 depends_on: [kordant-unified-restructure-12, kordant-unified-restructure-13, kordant-unified-restructure-14] tags: [backend, trpc, removebrokers, privacy, api]
objective:
- Build the tRPC router for RemoveBrokers, the data broker removal service. Port all logic from
services/removebrokers/andpackages/api/src/routes/removebrokers.routes.tsinto a unifiedremovebrokersrouter and service layer.
deliverables:
web/src/server/api/routers/removebrokers.ts— RemoveBrokers router:removebrokers.getBrokerRegistry—protectedProcedurereturning list of supported brokersremovebrokers.getRemovalRequests—protectedProcedurereturning user's removal requestsremovebrokers.createRemovalRequest—protectedProcedureinitiating removal for a brokerremovebrokers.getRequestStatus—protectedProcedurechecking removal progressremovebrokers.getBrokerListings—protectedProcedurereturning found listingsremovebrokers.scanForListings—protectedProcedurescanning brokers for user's dataremovebrokers.getStats—protectedProcedurereturning removal statistics
web/src/server/services/removebrokers.service.ts— Core business logic:getBrokerRegistry()— return all active brokers with metadatacreateRemovalRequest(subscriptionId, brokerId, personalInfo)— validate, create request, initiate removalgetRequestStatus(requestId)— return current status and historyscanForListings(subscriptionId, brokerId)— search broker site for user's dataprocessRemovals()— batch processor for pending removalsupdateRequestStatus(requestId, status, metadata)— update after broker response
web/src/server/services/removebrokers/broker.registry.ts— Broker definitions:- Static registry of supported data brokers
- Each entry: name, domain, category, removalMethod, removalUrl, requiresAccount, estimatedDays
- Methods: AUTOMATED, MANUAL_FORM, EMAIL, PHONE, MAIL
web/src/server/services/removebrokers/removal.engine.ts— Removal automation:submitAutomatedRemoval(broker, personalInfo)— API-based removal where availablegenerateFormPayload(broker, personalInfo)— prepare form data for manual submissionsendRemovalEmail(broker, personalInfo)— email-based removal requesttrackRemovalStatus(broker, requestId)— poll broker for status updates
steps:
- Create
web/src/server/api/routers/removebrokers.ts. - Define Zod schemas:
createRequestSchema:brokerId: z.string().uuid(),personalInfo: z.object({ fullName: z.string(), email: z.string().optional(), phone: z.string().optional(), address: z.string().optional(), dob: z.string().optional() })scanSchema:brokerId: z.string().uuid().optional()(if omitted, scan all)
- Implement router procedures:
- Broker registry listing (public or protected)
- Removal request CRUD
- Listing scan and results
- Stats aggregation
- Create
web/src/server/services/removebrokers.service.ts:- Port from
services/removebrokers/src/ - Implement request lifecycle: PENDING → SUBMITTED → IN_PROGRESS → COMPLETED/FAILED
- Port from
- Create broker registry:
- Hardcode initial list of 20-50 major data brokers
- Include removal instructions and URLs
- Allow admin updates via API (future enhancement)
- Create removal engine:
submitAutomatedRemoval: call broker API if available (rare)generateFormPayload: create structured data for form fillingsendRemovalEmail: use notification service (task 14) to send removal request emailtrackRemovalStatus: placeholder for polling logic
- Implement listing scanner:
- Search broker websites for user's name, email, phone
- Use web scraping (Cheerio, Playwright) where APIs are unavailable
- Store found listings in
BrokerListingtable
- Implement scheduler integration:
- Pending removals should be picked up by background job (task 22)
- Retries for failed removals with exponential backoff
- Wire router into
web/src/server/api/root.ts. - Write unit tests with mocked broker interactions.
steps:
- Unit:
createRemovalRequestcreates record with PENDING status - Unit:
processRemovalsadvances eligible requests to SUBMITTED - Unit:
scanForListingscreates BrokerListing records for found data - Unit: Broker registry returns correct metadata for known brokers
- Integration: tRPC procedures enforce subscription scoping
acceptance_criteria:
- Broker registry lists all supported data brokers with removal methods
- Removal requests can be created per broker with personal info
- Request status tracks lifecycle from PENDING to COMPLETED/FAILED
- Listings scanner finds user's data on broker sites
- Automated removals use APIs where available; manual methods generate instructions
- Failed removals are retried with exponential backoff
- Stats endpoint shows removal progress (total, completed, pending, failed)
validation:
- List brokers and verify registry data
- Create a removal request and verify DB record
- Simulate a scan and verify listing records created
- Run
cd web && pnpm testfor RemoveBrokers unit tests
notes:
- Reference legacy:
services/removebrokers/src/,packages/api/src/routes/removebrokers.routes.ts - Data broker removal is often a manual process. The automation layer should handle the easy cases and provide clear instructions for manual cases.
- Web scraping broker sites may violate Terms of Service. Use public APIs where available and document legal considerations.
- Personal info submitted for removal should be handled carefully. Do not log raw PII.
- The removal engine should be designed as a plugin system: each broker can have its own adapter for API, form, or email removal.
- Consider integrating with a third-party service (e.g., DeleteMe, Optery) for broader broker coverage if building individual adapters is impractical.