feat: add MyFitnessPal integration and external provider settings UI#1101
feat: add MyFitnessPal integration and external provider settings UI#1101serjsv87 wants to merge 2 commits intoCodeWithCJ:mainfrom
Conversation
- Add MyFitnessPalService for MFP data sync via Garmin integration - Add mfpRoutes (/api/integrations/myfitnesspal/sync, /status) - Add mfpSyncService for syncing daily food totals - Extend externalProviderRepository with MFP-aware queries - Add ExternalProviderSettings UI with ProviderCard, AddExternalProviderForm, EditProviderForm, ProviderSpecificFields components - Add useIntegrations hook and externalProviderService API client - Add myfitnesspal provider type to settings
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive integration with MyFitnessPal (MFP), enabling users to sync their nutrition data from SparkyFitness to their MFP diary. The changes span the entire stack, including frontend UI for credential management (CSRF tokens and session cookies), manual sync triggers, and status monitoring. The backend implementation features a new MFP service that handles complex authentication flows, data mapping, and an idempotent sync process that clears existing entries before pushing new totals. Additionally, the PR adds Ukrainian language support and refactors some provider settings. Review feedback highlights opportunities to improve type safety by replacing any with specific interfaces or unknown, optimizing sequential network requests during the deletion phase of the sync, and addressing potential scalability issues with the in-memory sync lock.
SparkyFitnessServer/integrations/myfitnesspal/myFitnessPalService.ts
Outdated
Show resolved
Hide resolved
SparkyFitnessServer/integrations/myfitnesspal/myFitnessPalService.ts
Outdated
Show resolved
Hide resolved
SparkyFitnessServer/integrations/myfitnesspal/myFitnessPalService.ts
Outdated
Show resolved
Hide resolved
- myFitnessPalService: add MFPProvider interface, remove all `as any` casts - myFitnessPalService: parallel entry deletion with DELETE_CONCURRENCY=5 limit instead of sequential loop (avoids rate limiting on large diaries) - myFitnessPalService: fix calories skip check (< 0 not <= 0) so zero-calorie entries (supplements, water) are still synced - myFitnessPalService: use `unknown` + type narrowing in all catch blocks - mfpSyncService: add SyncResult return type, replace `any` with typed interfaces - mfpSyncService: document that activeSyncs is a single-process lock and note distributed lock requirement for horizontal scaling
87c25af to
07293ac
Compare
Tip
Help us review and merge your PR faster!
Please ensure you have completed the Checklist below.
For Frontend changes, please run
pnpm run validateto check for any errors.PRs that include tests and clear screenshots are highly preferred!
Note: AI-generated descriptions must be manually edited for conciseness. Do not paste raw AI summaries.
Description
What problem does this PR solve?
Adds MyFitnessPal integration for syncing food diary data via Garmin, and introduces a redesigned External Provider Settings UI that makes managing all third-party integrations consistent and user-friendly.
How did you implement the solution?
Added
myFitnessPalService.ts(MFP API client),mfpSyncService.ts(daily totals sync), andmfpRoutes.ts(POST /api/integrations/myfitnesspal/sync,GET /status). ExtendedexternalProviderRepository.tswith MFP-aware queries. On the frontend, refactored provider settings into reusable components:ExternalProviderSettings,ProviderCard,AddExternalProviderForm,EditProviderForm, andProviderSpecificFields. AddeduseIntegrationshook andexternalProviderServiceAPI client.Linked Issue: #
How to Test
pnpm run validatePOST /api/integrations/myfitnesspal/syncPR Type
Checklist
All PRs:
New features only:
Frontend changes (
SparkyFitnessFrontend/orsrc/):pnpm run validateand it passes.en) translation file.Backend changes (
SparkyFitnessServer/):rls_policies.sqlfor any new user-specific tables. (Note: No new tables added; uses existingexternal_data_providerstable).UI changes (components, screens, pages):
Screenshots
Click to expand
Before
(add screenshot of old provider settings)

After
(add screenshot of new ExternalProviderSettings UI)

Notes for Reviewers