Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Eric Lee

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
132 changes: 132 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Garmin Parser

TypeScript client and REST API for fetching health and fitness data from [Garmin Connect](https://connect.garmin.com/).

## Features

- **CLI mode** — Fetch today's data interactively or export a date range to JSON
- **REST API mode** — Serve Garmin data over HTTP with Express
- **Docker support** — Multi-arch container image with GitHub Actions CI/CD
- **Session persistence** — OAuth tokens are saved and reused across restarts
- Daily steps, calories (total / active / BMR), heart rate, sleep, weight, and hydration
- Recent activities with per-activity calorie breakdown

## Prerequisites

- Node.js >= 20
- A [Garmin Connect](https://connect.garmin.com/) account

## Quick Start

### 1. Install dependencies

```bash
npm install
```

### 2. Configure credentials

```bash
cp .env.example .env
```

Edit `.env` and fill in your Garmin Connect credentials:

```
GARMIN_USERNAME=your.email@example.com
GARMIN_PASSWORD=your_password_here
```

### 3. Run in CLI mode

```bash
# Show today's data
npm start

# Export last 7 days to JSON
npm start -- --days 7

# Export last 28 days to JSON
npm start -- --days 28
```

Output files are saved to `./output/`.

### 4. Run as REST API server

```bash
# Build and start
npm run build
npm run serve

# Or run in dev mode
npm run dev:server
```

The server starts on port `3000` by default (configurable via `PORT` env var).

## API Endpoints

| Method | Path | Description |
|--------|------|-------------|
| `GET` | `/health` | Liveness probe |
| `GET` | `/ready` | Readiness probe (checks Garmin client status) |
| `GET` | `/api/profile` | User profile |
| `GET` | `/api/daily?date=YYYY-MM-DD` | Daily data for a specific date (defaults to today) |
| `GET` | `/api/range?days=7` | Aggregated data for a date range (1–28 days) |
| `GET` | `/api/activities?limit=10` | Recent activities (1–50) |

### Example response — `/api/daily`

```json
{
"success": true,
"data": {
"date": "2025-12-25",
"steps": 8432,
"calories": { "total": 2150, "active": 650, "bmr": 1500 },
"heartRate": { "restingHeartRate": 58, "maxHeartRate": 142, "minHeartRate": 52 },
"sleep": { "durationSeconds": 28800, "deepSleepSeconds": 7200, "lightSleepSeconds": 14400, "remSleepSeconds": 5400, "awakeSleepSeconds": 1800 },
"weight": 68.2,
"hydration": 2000
}
}
```

## Docker

### Pull from GitHub Container Registry

```bash
docker pull ghcr.io/happyeric77/garmin-parser:latest
```

### Run

```bash
docker run -d \
-p 3000:3000 \
-e GARMIN_USERNAME=your.email@example.com \
-e GARMIN_PASSWORD=your_password \
-v garmin-tokens:/app/tokens \
ghcr.io/happyeric77/garmin-parser:latest
```

### Build locally

```bash
docker build -t garmin-parser .
```

## Project Structure

```
src/
garmin-client.ts # Garmin Connect client wrapper
server.ts # Express REST API server
index.ts # CLI entry point
```

## License

[MIT](LICENSE)
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"health",
"api"
],
"author": "",
"license": "ISC",
"description": "POC for fetching Garmin Connect data using TypeScript",
"author": "Eric Lee",
"license": "MIT",
"description": "TypeScript client and REST API for fetching health and fitness data from Garmin Connect",
"dependencies": {
"cli-progress": "^3.12.0",
"dotenv": "^17.2.3",
Expand Down
6 changes: 3 additions & 3 deletions src/garmin-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ export interface GarminWeightData {
}

export interface CaloriesData {
total: number | null; // 總消耗卡路里 (BMR + 活動)
active: number | null; // 活動消耗卡路里
bmr: number | null; // 基礎代謝卡路里 (Basal Metabolic Rate)
total: number | null; // Total calories burned (BMR + active)
active: number | null; // Active calories burned
bmr: number | null; // Basal Metabolic Rate calories
}

export interface DailyData {
Expand Down
Loading