fitdays-mcp-server 1.2.0 → 2.0.0
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/README.md +37 -8
- package/dist/fitdays.d.ts +24 -7
- package/dist/fitdays.js +57 -32
- package/dist/index.js +10 -2
- package/dist/server.js +49 -83
- package/dist/session-store.d.ts +12 -0
- package/dist/session-store.js +46 -0
- package/dist/summaries/body-composition-summary.d.ts +26 -0
- package/dist/summaries/body-composition-summary.js +25 -0
- package/dist/summaries/body-type-label.d.ts +2 -0
- package/dist/summaries/body-type-label.js +14 -0
- package/dist/summaries/device-summary.d.ts +10 -0
- package/dist/summaries/device-summary.js +8 -0
- package/dist/summaries/round.d.ts +2 -0
- package/dist/summaries/round.js +2 -0
- package/dist/summaries/user-summary.d.ts +6 -9
- package/dist/summaries/user-summary.js +13 -10
- package/dist/summaries/weight-summary.d.ts +6 -18
- package/dist/summaries/weight-summary.js +11 -24
- package/package.json +15 -12
- package/dist/summaries/sex-label.d.ts +0 -2
- package/dist/summaries/sex-label.js +0 -1
- package/dist/summaries/weight-extension-data-summary.d.ts +0 -50
- package/dist/summaries/weight-extension-data-summary.js +0 -64
package/README.md
CHANGED
|
@@ -8,18 +8,27 @@
|
|
|
8
8
|
the unofficial [FitDays / iComon smart-scale API](https://github.com/roquerodrigo/fitdays-api)
|
|
9
9
|
as tools that an LLM client (Claude Desktop, Claude Code, etc.) can call.
|
|
10
10
|
|
|
11
|
-
It
|
|
12
|
-
|
|
11
|
+
It works with accounts on the FitDays 2.0 app, keeps one FitDays session,
|
|
12
|
+
caches the account data in memory for five minutes, and serves it as
|
|
13
|
+
structured tool responses.
|
|
14
|
+
|
|
15
|
+
> [!WARNING]
|
|
16
|
+
> FitDays allows **one session per account**: when the server logs in, the
|
|
17
|
+
> FitDays phone app is signed out, and logging in to the app again makes the
|
|
18
|
+
> server log in again on its next refresh. Set `FITDAYS_SESSION_FILE` (the
|
|
19
|
+
> Docker image does) so restarts reuse the stored session instead of logging
|
|
20
|
+
> in. Consider a dedicated FitDays account shared with your main one if both
|
|
21
|
+
> need to stay signed in.
|
|
13
22
|
|
|
14
23
|
## Tools
|
|
15
24
|
|
|
16
25
|
| Tool | What it does |
|
|
17
26
|
| --- | --- |
|
|
18
|
-
| `list_users` |
|
|
19
|
-
| `list_devices` |
|
|
20
|
-
| `get_weight_history` |
|
|
21
|
-
| `get_latest_weight` | Most recent
|
|
22
|
-
| `refresh_sync` | Force-refresh the cached
|
|
27
|
+
| `list_users` | Profiles (people) registered under the account, with the active one and the latest height. |
|
|
28
|
+
| `list_devices` | Scales bound to the account. |
|
|
29
|
+
| `get_weight_history` | Weigh-ins with body composition (body fat, muscle, water, protein, bone mass, visceral and subcutaneous fat, BMR, body age, score, body type), newest first. Filters: `account_user_id`, `since`, `until`, `limit`. |
|
|
30
|
+
| `get_latest_weight` | Most recent weigh-in, optionally for one `account_user_id`. |
|
|
31
|
+
| `refresh_sync` | Force-refresh the cached data. Returns record counts. |
|
|
23
32
|
|
|
24
33
|
## Install
|
|
25
34
|
|
|
@@ -37,7 +46,8 @@ The server reads credentials from environment variables:
|
|
|
37
46
|
| --- | --- | --- |
|
|
38
47
|
| `FITDAYS_EMAIL` | yes | — |
|
|
39
48
|
| `FITDAYS_PASSWORD` | yes | — |
|
|
40
|
-
| `FITDAYS_REGION` | no | `us` (
|
|
49
|
+
| `FITDAYS_REGION` | no | `us` (`eu` and `cn` also exist) |
|
|
50
|
+
| `FITDAYS_SESSION_FILE` | no | none — the session lives in memory only. The Docker image sets `/data/session.json` |
|
|
41
51
|
|
|
42
52
|
## Use with Claude Desktop / Claude Code
|
|
43
53
|
|
|
@@ -69,10 +79,14 @@ Container Registry on every release, tagged with the release version
|
|
|
69
79
|
docker run -d --name fitdays-mcp \
|
|
70
80
|
-e FITDAYS_EMAIL=you@example.com \
|
|
71
81
|
-e FITDAYS_PASSWORD=your-password \
|
|
82
|
+
-v fitdays-mcp-data:/data \
|
|
72
83
|
-p 8000:8000 \
|
|
73
84
|
ghcr.io/roquerodrigo/fitdays-mcp-server:latest
|
|
74
85
|
```
|
|
75
86
|
|
|
87
|
+
The volume keeps the FitDays session across container re-creations, so
|
|
88
|
+
updating the image does not log in again (and sign the phone app out).
|
|
89
|
+
|
|
76
90
|
The container serves the server over
|
|
77
91
|
[Streamable HTTP](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http)
|
|
78
92
|
at `http://localhost:8000/mcp`, with a health endpoint at `/healthz`, so
|
|
@@ -101,6 +115,7 @@ container command:
|
|
|
101
115
|
"args": [
|
|
102
116
|
"run", "-i", "--rm",
|
|
103
117
|
"-e", "FITDAYS_EMAIL", "-e", "FITDAYS_PASSWORD",
|
|
118
|
+
"-v", "fitdays-mcp-data:/data",
|
|
104
119
|
"ghcr.io/roquerodrigo/fitdays-mcp-server:latest",
|
|
105
120
|
"fitdays-mcp-server"
|
|
106
121
|
],
|
|
@@ -113,6 +128,20 @@ container command:
|
|
|
113
128
|
}
|
|
114
129
|
```
|
|
115
130
|
|
|
131
|
+
## Upgrading from 1.x
|
|
132
|
+
|
|
133
|
+
Version 2 follows the move of FitDays accounts to the FitDays 2.0 app, whose
|
|
134
|
+
API returns different data:
|
|
135
|
+
|
|
136
|
+
- Profiles are identified by `account_user_id` (a string) instead of `suid`;
|
|
137
|
+
`list_users` no longer returns sex, birthday or target weight.
|
|
138
|
+
- Measurements use descriptive field names (`body_fat_pct`,
|
|
139
|
+
`visceral_fat_index`, …) grouped under `body_composition`.
|
|
140
|
+
- `ext_data` (FitDays reference ranges and targets) and the `include_deleted`
|
|
141
|
+
/ `include_ext_data` options are gone; the 2.0 API does not return deleted
|
|
142
|
+
records.
|
|
143
|
+
- `refresh_sync` returns a plain count of weight records.
|
|
144
|
+
|
|
116
145
|
## Run from source
|
|
117
146
|
|
|
118
147
|
```sh
|
package/dist/fitdays.d.ts
CHANGED
|
@@ -1,12 +1,29 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AccountInfo, AccountUser, Device, FitDaysClient, HeightRecord, WeightRecord } from 'fitdays-api';
|
|
2
|
+
import type { SessionStore } from './session-store.js';
|
|
3
|
+
export type FitDaysSnapshot = {
|
|
4
|
+
readonly account: AccountInfo;
|
|
5
|
+
readonly devices: readonly Device[];
|
|
6
|
+
readonly heights: readonly HeightRecord[];
|
|
7
|
+
readonly users: readonly AccountUser[];
|
|
8
|
+
readonly weights: readonly WeightRecord[];
|
|
9
|
+
};
|
|
10
|
+
/** Loads the account data through one shared FitDays session and caches it for a few minutes. */
|
|
2
11
|
export declare class FitDaysSession {
|
|
3
12
|
private readonly email;
|
|
4
13
|
private readonly password;
|
|
5
|
-
private readonly
|
|
14
|
+
private readonly client;
|
|
15
|
+
private readonly store;
|
|
6
16
|
private cache;
|
|
7
|
-
private
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
17
|
+
private snapshotPromise;
|
|
18
|
+
constructor(email: string, password: string, client: FitDaysClient, store: SessionStore);
|
|
19
|
+
getSnapshot: (force?: boolean) => Promise<FitDaysSnapshot>;
|
|
20
|
+
private fetchSnapshot;
|
|
21
|
+
/**
|
|
22
|
+
* Requests run one after another: an expired access token makes each of
|
|
23
|
+
* them refresh it, and parallel refreshes would invalidate one another.
|
|
24
|
+
*/
|
|
25
|
+
private loadSnapshot;
|
|
26
|
+
private login;
|
|
27
|
+
/** Another process sharing the store may have rotated the tokens; only log in again when it has not. */
|
|
28
|
+
private recoverSession;
|
|
12
29
|
}
|
package/dist/fitdays.js
CHANGED
|
@@ -1,45 +1,70 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const
|
|
1
|
+
import { ACCESS_TOKEN_INVALID_CODE, FitDaysApiError, REFRESH_TOKEN_INVALID_CODE } from 'fitdays-api';
|
|
2
|
+
const SNAPSHOT_TTL_MS = 5 * 60 * 1000;
|
|
3
|
+
/** Loads the account data through one shared FitDays session and caches it for a few minutes. */
|
|
3
4
|
export class FitDaysSession {
|
|
4
5
|
email;
|
|
5
6
|
password;
|
|
6
|
-
|
|
7
|
+
client;
|
|
8
|
+
store;
|
|
7
9
|
cache = null;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
constructor(email, password, region = 'us') {
|
|
10
|
+
snapshotPromise = null;
|
|
11
|
+
constructor(email, password, client, store) {
|
|
11
12
|
this.email = email;
|
|
12
13
|
this.password = password;
|
|
13
|
-
this.
|
|
14
|
+
this.client = client;
|
|
15
|
+
this.store = store;
|
|
14
16
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return this.cache.data;
|
|
17
|
+
getSnapshot = async (force = false) => {
|
|
18
|
+
if (!force && this.cache && Date.now() - this.cache.fetchedAt < SNAPSHOT_TTL_MS) {
|
|
19
|
+
return this.cache.snapshot;
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
this.snapshotPromise ??= this.fetchSnapshot().finally(() => {
|
|
22
|
+
this.snapshotPromise = null;
|
|
23
|
+
});
|
|
24
|
+
return this.snapshotPromise;
|
|
25
|
+
};
|
|
26
|
+
fetchSnapshot = async () => {
|
|
27
|
+
this.client.session ??= await this.store.load();
|
|
28
|
+
if (!this.client.session)
|
|
29
|
+
await this.login();
|
|
30
|
+
let snapshot;
|
|
31
|
+
try {
|
|
32
|
+
snapshot = await this.loadSnapshot();
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
if (!isSessionRejected(error))
|
|
36
|
+
throw error;
|
|
37
|
+
await this.recoverSession();
|
|
38
|
+
snapshot = await this.loadSnapshot();
|
|
24
39
|
}
|
|
25
|
-
this.cache = {
|
|
26
|
-
return
|
|
40
|
+
this.cache = { fetchedAt: Date.now(), snapshot };
|
|
41
|
+
return snapshot;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Requests run one after another: an expired access token makes each of
|
|
45
|
+
* them refresh it, and parallel refreshes would invalidate one another.
|
|
46
|
+
*/
|
|
47
|
+
loadSnapshot = async () => {
|
|
48
|
+
const account = await this.client.getAccountInfo();
|
|
49
|
+
const users = await this.client.listAccountUsers();
|
|
50
|
+
const devices = await this.client.listDevices();
|
|
51
|
+
const heights = await this.client.listAllHeightRecords();
|
|
52
|
+
const weights = await this.client.listAllWeightRecords({ includeBodyComposition: true });
|
|
53
|
+
return { account, devices, heights, users, weights };
|
|
54
|
+
};
|
|
55
|
+
login = async () => {
|
|
56
|
+
console.error('[info] Logging in to FitDays; this signs the FitDays phone app out');
|
|
57
|
+
await this.client.login(this.email, this.password);
|
|
27
58
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (
|
|
32
|
-
this.
|
|
33
|
-
|
|
34
|
-
await c.login(this.email, this.password);
|
|
35
|
-
this.client = c;
|
|
36
|
-
})().finally(() => {
|
|
37
|
-
this.loginPromise = null;
|
|
38
|
-
});
|
|
59
|
+
/** Another process sharing the store may have rotated the tokens; only log in again when it has not. */
|
|
60
|
+
recoverSession = async () => {
|
|
61
|
+
const stored = await this.store.load();
|
|
62
|
+
if (stored && stored.refreshToken !== this.client.session?.refreshToken) {
|
|
63
|
+
this.client.session = stored;
|
|
64
|
+
return;
|
|
39
65
|
}
|
|
40
|
-
await this.
|
|
41
|
-
if (!this.client)
|
|
42
|
-
throw new Error('FitDays client not initialized after login');
|
|
43
|
-
return this.client;
|
|
66
|
+
await this.login();
|
|
44
67
|
};
|
|
45
68
|
}
|
|
69
|
+
const isSessionRejected = (error) => error instanceof FitDaysApiError &&
|
|
70
|
+
(error.code === REFRESH_TOKEN_INVALID_CODE || error.code === ACCESS_TOKEN_INVALID_CODE);
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
|
+
import { FitDaysClient } from 'fitdays-api';
|
|
3
4
|
import { FitDaysSession } from './fitdays.js';
|
|
4
5
|
import { buildServer } from './server.js';
|
|
6
|
+
import { SessionStore } from './session-store.js';
|
|
5
7
|
const main = async () => {
|
|
6
8
|
const email = process.env.FITDAYS_EMAIL;
|
|
7
9
|
const password = process.env.FITDAYS_PASSWORD;
|
|
@@ -10,8 +12,14 @@ const main = async () => {
|
|
|
10
12
|
console.error('FITDAYS_EMAIL and FITDAYS_PASSWORD must be set in the environment.');
|
|
11
13
|
process.exit(1);
|
|
12
14
|
}
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
+
const store = new SessionStore(process.env.FITDAYS_SESSION_FILE || undefined);
|
|
16
|
+
const client = new FitDaysClient({
|
|
17
|
+
onSessionChange: (session) => {
|
|
18
|
+
void store.save(session);
|
|
19
|
+
},
|
|
20
|
+
region,
|
|
21
|
+
});
|
|
22
|
+
const server = buildServer(new FitDaysSession(email, password, client, store));
|
|
15
23
|
const transport = new StdioServerTransport();
|
|
16
24
|
await server.connect(transport);
|
|
17
25
|
};
|
package/dist/server.js
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
+
import { summarizeDevice } from './summaries/device-summary.js';
|
|
3
4
|
import { summarizeUser } from './summaries/user-summary.js';
|
|
4
5
|
import { summarizeWeight } from './summaries/weight-summary.js';
|
|
5
6
|
const json = (value) => ({
|
|
6
7
|
content: [{ text: JSON.stringify(value, null, 2), type: 'text' }],
|
|
7
8
|
});
|
|
8
9
|
const joinDescriptionLines = (lines) => lines.join('\n');
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
'
|
|
12
|
-
'
|
|
13
|
-
'
|
|
14
|
-
'Fat-free-mass reference fields provide the recommended fat-free mass, including `ffmStandard`.',
|
|
15
|
-
'Index fields provide skeletal-muscle indexing, including `smi` (skeletal muscle index).',
|
|
16
|
-
'Classification fields describe body-composition status, including `bodyScore`, `bodyType`, and `obesityDegree`.',
|
|
17
|
-
'Target fields describe target body-composition values, including `targetWeight`, `targetBodyfatMass`, and `targetSMMMass`; unavailable target-mass values are `null`.',
|
|
18
|
-
'Device fields identify the source device, including `deviceModelExt`, `deviceNameExt`, and `deviceSoftwareVer`.',
|
|
10
|
+
const cacheDescriptionLine = 'Data is fetched lazily when no valid cache exists and stored in a global cache shared by all tools for 5 minutes; subsequent queries use that cached snapshot until it expires. Use `refresh_sync` if you are within the 5-minute cache window and fresher data is required.';
|
|
11
|
+
const weightDescriptionLines = [
|
|
12
|
+
'Each measurement contains `record_id`, `account_user_id` (the profile measured), `device_id`, `measured_at` (ISO 8601 timestamp), `measured_time` (Unix-seconds timestamp), `weight_kg`, `weight_lb`, and `body_composition`.',
|
|
13
|
+
'`body_composition` is `null` for weight-only measurements. Otherwise it contains `bmi`, `body_fat_pct`, `fat_mass_kg`, `lean_body_mass_kg`, `muscle_pct`, `muscle_mass_kg`, `skeletal_muscle_pct`, `skeletal_muscle_mass_kg`, `body_water_pct`, `body_water_kg`, `protein_pct`, `protein_mass_kg`, `subcutaneous_fat_pct`, `subcutaneous_fat_mass_kg`, `visceral_fat_index`, `bone_mass_kg`, `bmr_kcal` (basal metabolic rate), `body_age`, `body_score` (FitDays score out of 100), `body_type` (FitDays classification such as `Balanced` or `Obese`), and `obesity_degree_pct` (weight as a percentage of the FitDays standard weight).',
|
|
14
|
+
'FitDays values are estimates from a bioimpedance scale; treat them as informational rather than authoritative.',
|
|
19
15
|
];
|
|
20
16
|
export const buildServer = (session) => {
|
|
21
17
|
const server = new McpServer({
|
|
@@ -32,123 +28,93 @@ export const buildServer = (session) => {
|
|
|
32
28
|
});
|
|
33
29
|
server.registerTool('list_users', {
|
|
34
30
|
description: joinDescriptionLines([
|
|
35
|
-
'List the
|
|
36
|
-
'Each
|
|
37
|
-
'
|
|
38
|
-
'
|
|
39
|
-
'Returns a list where each entry contains `nickname`, `sex` (`male` or `female`, biological sex), `birthday`, `height_cm`, `target_weight_kg` (user-set target weight), `suid`, and `uid` (account uid).',
|
|
31
|
+
'List the profiles (people) registered under the FitDays account.',
|
|
32
|
+
'Each profile has a unique and stable `account_user_id`, used by other tools to query data for that person. You may save it in memory for future queries.',
|
|
33
|
+
'If a required `account_user_id` is not already known, call this tool first and use known user information to identify the correct profile; `is_active` marks the profile currently selected in the FitDays app.',
|
|
34
|
+
'Returns a list where each entry contains `account_user_id`, `nickname`, `is_admin` (the account owner), `is_active`, and `height_cm` (latest recorded height, or `null`).',
|
|
40
35
|
]),
|
|
41
36
|
inputSchema: {},
|
|
42
37
|
title: 'List FitDays users',
|
|
43
38
|
}, async () => {
|
|
44
|
-
const
|
|
45
|
-
return json(
|
|
39
|
+
const snapshot = await session.getSnapshot();
|
|
40
|
+
return json(snapshot.users.map((user) => summarizeUser(user, snapshot.account.activeAccountUserId, snapshot.heights)));
|
|
46
41
|
});
|
|
47
42
|
server.registerTool('list_devices', {
|
|
48
43
|
description: joinDescriptionLines([
|
|
49
44
|
'List the devices bound to the FitDays account.',
|
|
50
|
-
'Returns `device_id` (FitDays device identifier), `name`, `model`, `mac` (MAC address),
|
|
45
|
+
'Returns `device_id` (FitDays device identifier, matching `device_id` on measurements), `name`, `model`, `mac` (MAC address), `firmware_ver` (firmware version, or `null`), and `bound_at` (ISO 8601 timestamp) for each device.',
|
|
51
46
|
]),
|
|
52
47
|
inputSchema: {},
|
|
53
48
|
title: 'List FitDays devices',
|
|
54
49
|
}, async () => {
|
|
55
|
-
const
|
|
56
|
-
return json(
|
|
57
|
-
device_id: d.device_id,
|
|
58
|
-
firmware_ver: d.firmware_ver,
|
|
59
|
-
mac: d.mac,
|
|
60
|
-
model: d.model,
|
|
61
|
-
name: d.name,
|
|
62
|
-
})));
|
|
50
|
+
const snapshot = await session.getSnapshot();
|
|
51
|
+
return json(snapshot.devices.map(summarizeDevice));
|
|
63
52
|
});
|
|
64
53
|
server.registerTool('get_weight_history', {
|
|
65
54
|
description: joinDescriptionLines([
|
|
66
|
-
'Return body-composition / weight measurements, optionally filtered by
|
|
67
|
-
|
|
68
|
-
'Returns a list ordered newest first.
|
|
69
|
-
...
|
|
70
|
-
'By default includes tombstoned records (`is_deleted: 1`); set `include_deleted: false` to hide them.',
|
|
55
|
+
'Return body-composition / weight measurements, optionally filtered by profile (`account_user_id`) and time window.',
|
|
56
|
+
cacheDescriptionLine,
|
|
57
|
+
'Returns a list ordered newest first.',
|
|
58
|
+
...weightDescriptionLines,
|
|
71
59
|
]),
|
|
72
60
|
inputSchema: {
|
|
73
|
-
|
|
74
|
-
.describe('
|
|
75
|
-
include_ext_data: z.boolean().optional()
|
|
76
|
-
.describe('Include the `ext_data` reference/context object on each record. Leave it off when only the measurements are needed, such as for plotting trends. Default: false.'),
|
|
61
|
+
account_user_id: z.string().optional()
|
|
62
|
+
.describe('Profile id resolved by `list_users`. Omit to return records for all profiles.'),
|
|
77
63
|
limit: z.number().int().positive().max(1000).optional()
|
|
78
64
|
.describe('Maximum number of records (newest first). Default: 100.'),
|
|
79
65
|
since: z.number().int().nonnegative().optional()
|
|
80
66
|
.describe('Only include records measured at or after this unix-seconds timestamp.'),
|
|
81
|
-
suid: z.number().int().optional()
|
|
82
|
-
.describe('Sub-user id resolved by `list_users`. Omit to return records for all users.'),
|
|
83
67
|
until: z.number().int().nonnegative().optional()
|
|
84
68
|
.describe('Only include records measured at or before this unix-seconds timestamp.'),
|
|
85
69
|
},
|
|
86
70
|
title: 'Weight history',
|
|
87
|
-
}, async ({
|
|
88
|
-
const
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
.filter((
|
|
93
|
-
.
|
|
94
|
-
.filter((r) => since === undefined || r.measured_time >= since)
|
|
95
|
-
.filter((r) => until === undefined || r.measured_time <= until)
|
|
96
|
-
.sort((a, b) => b.measured_time - a.measured_time)
|
|
71
|
+
}, async ({ account_user_id, limit, since, until }) => {
|
|
72
|
+
const snapshot = await session.getSnapshot();
|
|
73
|
+
const records = snapshot.weights
|
|
74
|
+
.filter((record) => account_user_id === undefined || record.accountUserId === account_user_id)
|
|
75
|
+
.filter((record) => since === undefined || record.dataAt >= since)
|
|
76
|
+
.filter((record) => until === undefined || record.dataAt <= until)
|
|
77
|
+
.toSorted((a, b) => b.dataAt - a.dataAt)
|
|
97
78
|
.slice(0, limit ?? 100)
|
|
98
|
-
.map(
|
|
79
|
+
.map(summarizeWeight);
|
|
99
80
|
return json(records);
|
|
100
81
|
});
|
|
101
82
|
server.registerTool('get_latest_weight', {
|
|
102
83
|
description: joinDescriptionLines([
|
|
103
|
-
'Return the most recent body-composition / weight measurement in the current global cache, optionally for a single
|
|
104
|
-
|
|
105
|
-
'Returns exactly one measurement
|
|
106
|
-
...
|
|
107
|
-
'By default ignores tombstoned records (`is_deleted: 1`).',
|
|
84
|
+
'Return the most recent body-composition / weight measurement in the current global cache, optionally for a single profile (`account_user_id`).',
|
|
85
|
+
cacheDescriptionLine,
|
|
86
|
+
'Returns exactly one measurement, or `null` if no matching measurement exists.',
|
|
87
|
+
...weightDescriptionLines,
|
|
108
88
|
]),
|
|
109
89
|
inputSchema: {
|
|
110
|
-
|
|
111
|
-
.describe('
|
|
112
|
-
include_ext_data: z.boolean().optional()
|
|
113
|
-
.describe('Include the `ext_data` reference/context object. Set to false to omit it. Default: true.'),
|
|
114
|
-
suid: z.number().int().optional()
|
|
115
|
-
.describe('Sub-user id resolved by `list_users`. Omit to return the latest record across all users.'),
|
|
90
|
+
account_user_id: z.string().optional()
|
|
91
|
+
.describe('Profile id resolved by `list_users`. Omit to return the latest record across all profiles.'),
|
|
116
92
|
},
|
|
117
93
|
title: 'Latest weight',
|
|
118
|
-
}, async ({
|
|
119
|
-
const
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
.filter((r) => suid === undefined || r.suid === suid)
|
|
125
|
-
.reduce((acc, r) => {
|
|
126
|
-
return acc === null || r.measured_time > acc.measured_time ? r : acc;
|
|
127
|
-
}, null);
|
|
128
|
-
return json(latest ? summarizeWeight(latest, includeExtensionData) : null);
|
|
94
|
+
}, async ({ account_user_id }) => {
|
|
95
|
+
const snapshot = await session.getSnapshot();
|
|
96
|
+
const latest = snapshot.weights
|
|
97
|
+
.filter((record) => account_user_id === undefined || record.accountUserId === account_user_id)
|
|
98
|
+
.reduce((acc, record) => acc === null || record.dataAt > acc.dataAt ? record : acc, null);
|
|
99
|
+
return json(latest ? summarizeWeight(latest) : null);
|
|
129
100
|
});
|
|
130
101
|
server.registerTool('refresh_sync', {
|
|
131
102
|
description: joinDescriptionLines([
|
|
132
103
|
'Force-refresh the global FitDays cache shared by all tools.',
|
|
133
|
-
'FitDays data is loaded lazily: the first tool call that needs
|
|
104
|
+
'FitDays data is loaded lazily: the first tool call that needs account data fetches a fresh snapshot and stores it in the global cache for 5 minutes. This includes measurement queries such as `get_latest_weight` and `get_weight_history`, as well as account-data queries such as `list_users` and `list_devices`.',
|
|
134
105
|
'Subsequent tool calls within that 5-minute window reuse the same cached snapshot. Use this tool when fresher data is required before the cache expires, such as after a recent measurement, deletion, user change, or device change.',
|
|
135
|
-
'A full resync transfers
|
|
136
|
-
'Returns
|
|
106
|
+
'A full resync transfers every measurement of the account; avoid unnecessary refreshes.',
|
|
107
|
+
'Returns record counts for `devices`, `users`, `height_records`, and `weight_records`.',
|
|
137
108
|
]),
|
|
138
109
|
inputSchema: {},
|
|
139
110
|
title: 'Refresh sync cache',
|
|
140
111
|
}, async () => {
|
|
141
|
-
const
|
|
142
|
-
const activeWeight = data.weight_list.filter((r) => r.is_deleted === 0).length;
|
|
112
|
+
const snapshot = await session.getSnapshot(true);
|
|
143
113
|
return json({
|
|
144
|
-
devices:
|
|
145
|
-
height_records:
|
|
146
|
-
users:
|
|
147
|
-
weight_records:
|
|
148
|
-
active: activeWeight,
|
|
149
|
-
deleted: data.weight_list.length - activeWeight,
|
|
150
|
-
total: data.weight_list.length,
|
|
151
|
-
},
|
|
114
|
+
devices: snapshot.devices.length,
|
|
115
|
+
height_records: snapshot.heights.length,
|
|
116
|
+
users: snapshot.users.length,
|
|
117
|
+
weight_records: snapshot.weights.length,
|
|
152
118
|
});
|
|
153
119
|
});
|
|
154
120
|
return server;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Session } from 'fitdays-api';
|
|
2
|
+
/**
|
|
3
|
+
* Keeps the FitDays session on disk so restarts and the per-client processes
|
|
4
|
+
* spawned by the HTTP gateway reuse one login: FitDays allows a single
|
|
5
|
+
* session per account, and every new login signs the phone app out.
|
|
6
|
+
*/
|
|
7
|
+
export declare class SessionStore {
|
|
8
|
+
private readonly filePath?;
|
|
9
|
+
constructor(filePath?: string | undefined);
|
|
10
|
+
load: () => Promise<null | Session>;
|
|
11
|
+
save: (session: Session) => Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* Keeps the FitDays session on disk so restarts and the per-client processes
|
|
5
|
+
* spawned by the HTTP gateway reuse one login: FitDays allows a single
|
|
6
|
+
* session per account, and every new login signs the phone app out.
|
|
7
|
+
*/
|
|
8
|
+
export class SessionStore {
|
|
9
|
+
filePath;
|
|
10
|
+
constructor(filePath) {
|
|
11
|
+
this.filePath = filePath;
|
|
12
|
+
}
|
|
13
|
+
load = async () => {
|
|
14
|
+
if (!this.filePath)
|
|
15
|
+
return null;
|
|
16
|
+
try {
|
|
17
|
+
const parsed = JSON.parse(await readFile(this.filePath, 'utf8'));
|
|
18
|
+
return isSession(parsed) ? parsed : null;
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (error.code !== 'ENOENT') {
|
|
22
|
+
console.error(`[warn] Failed to read the stored FitDays session: ${String(error)}`);
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
save = async (session) => {
|
|
28
|
+
if (!this.filePath)
|
|
29
|
+
return;
|
|
30
|
+
try {
|
|
31
|
+
await mkdir(dirname(this.filePath), { recursive: true });
|
|
32
|
+
await writeFile(this.filePath, JSON.stringify(session), { mode: 0o600 });
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
console.error(`[warn] Failed to store the FitDays session: ${String(error)}`);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const isSession = (value) => {
|
|
40
|
+
if (typeof value !== 'object' || value === null)
|
|
41
|
+
return false;
|
|
42
|
+
const candidate = value;
|
|
43
|
+
return typeof candidate.accessToken === 'string' &&
|
|
44
|
+
typeof candidate.refreshToken === 'string' &&
|
|
45
|
+
typeof candidate.accountId === 'string';
|
|
46
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { BodyComposition } from 'fitdays-api';
|
|
2
|
+
import { type BodyTypeLabel } from './body-type-label.js';
|
|
3
|
+
export type BodyCompositionSummary = {
|
|
4
|
+
bmi: number;
|
|
5
|
+
bmr_kcal: number;
|
|
6
|
+
body_age: number;
|
|
7
|
+
body_fat_pct: number;
|
|
8
|
+
body_score: number;
|
|
9
|
+
body_type: 'unknown' | BodyTypeLabel;
|
|
10
|
+
body_water_kg: number;
|
|
11
|
+
body_water_pct: number;
|
|
12
|
+
bone_mass_kg: number;
|
|
13
|
+
fat_mass_kg: number;
|
|
14
|
+
lean_body_mass_kg: number;
|
|
15
|
+
muscle_mass_kg: number;
|
|
16
|
+
muscle_pct: number;
|
|
17
|
+
obesity_degree_pct: number;
|
|
18
|
+
protein_mass_kg: number;
|
|
19
|
+
protein_pct: number;
|
|
20
|
+
skeletal_muscle_mass_kg: number;
|
|
21
|
+
skeletal_muscle_pct: number;
|
|
22
|
+
subcutaneous_fat_mass_kg: number;
|
|
23
|
+
subcutaneous_fat_pct: number;
|
|
24
|
+
visceral_fat_index: number;
|
|
25
|
+
};
|
|
26
|
+
export declare const summarizeBodyComposition: (composition: BodyComposition) => BodyCompositionSummary;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { bodyTypeLabel } from './body-type-label.js';
|
|
2
|
+
import { round } from './round.js';
|
|
3
|
+
export const summarizeBodyComposition = (composition) => ({
|
|
4
|
+
bmi: round(composition.bmi),
|
|
5
|
+
bmr_kcal: round(composition.bmr),
|
|
6
|
+
body_age: round(composition.physicalAge),
|
|
7
|
+
body_fat_pct: round(composition.bodyFat),
|
|
8
|
+
body_score: round(composition.bodyScore),
|
|
9
|
+
body_type: bodyTypeLabel(composition.bodyType),
|
|
10
|
+
body_water_kg: round(composition.waterMass),
|
|
11
|
+
body_water_pct: round(composition.water),
|
|
12
|
+
bone_mass_kg: round(composition.boneMass),
|
|
13
|
+
fat_mass_kg: round(composition.fatMass),
|
|
14
|
+
lean_body_mass_kg: round(composition.lbm),
|
|
15
|
+
muscle_mass_kg: round(composition.muscleMass),
|
|
16
|
+
muscle_pct: round(composition.muscle),
|
|
17
|
+
obesity_degree_pct: round(composition.obesityDegree),
|
|
18
|
+
protein_mass_kg: round(composition.proteinMass),
|
|
19
|
+
protein_pct: round(composition.protein),
|
|
20
|
+
skeletal_muscle_mass_kg: round(composition.skeletalMuscleMass),
|
|
21
|
+
skeletal_muscle_pct: round(composition.skeletalMuscle),
|
|
22
|
+
subcutaneous_fat_mass_kg: round(composition.subcutaneousFatMass),
|
|
23
|
+
subcutaneous_fat_pct: round(composition.subcutaneousFat),
|
|
24
|
+
visceral_fat_index: round(composition.visceralFat),
|
|
25
|
+
});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export type BodyTypeLabel = 'Athletic' | 'Balanced' | 'Hidden Overweight' | 'Muscular' | 'Muscular Overweight' | 'Muscular Slim' | 'Obese' | 'Overweight' | 'Slightly Underweight' | 'Slim' | 'Underweight';
|
|
2
|
+
export declare const bodyTypeLabel: (bodyType: number) => "unknown" | BodyTypeLabel;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const BODY_TYPE_LABELS = {
|
|
2
|
+
0: 'Underweight',
|
|
3
|
+
1: 'Slightly Underweight',
|
|
4
|
+
2: 'Muscular Slim',
|
|
5
|
+
3: 'Slim',
|
|
6
|
+
4: 'Muscular',
|
|
7
|
+
5: 'Balanced',
|
|
8
|
+
6: 'Athletic',
|
|
9
|
+
7: 'Muscular Overweight',
|
|
10
|
+
8: 'Obese',
|
|
11
|
+
9: 'Overweight',
|
|
12
|
+
10: 'Hidden Overweight',
|
|
13
|
+
};
|
|
14
|
+
export const bodyTypeLabel = (bodyType) => BODY_TYPE_LABELS[bodyType] ?? 'unknown';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Device } from 'fitdays-api';
|
|
2
|
+
export type DeviceSummary = {
|
|
3
|
+
bound_at: string;
|
|
4
|
+
device_id: string;
|
|
5
|
+
firmware_ver: null | string;
|
|
6
|
+
mac: string;
|
|
7
|
+
model: string;
|
|
8
|
+
name: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const summarizeDevice: (device: Device) => DeviceSummary;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const summarizeDevice = (device) => ({
|
|
2
|
+
bound_at: new Date(device.bindAt * 1000).toISOString(),
|
|
3
|
+
device_id: device.iotDeviceId,
|
|
4
|
+
firmware_ver: device.firmwareVersion || null,
|
|
5
|
+
mac: device.mac,
|
|
6
|
+
model: device.model,
|
|
7
|
+
name: device.productName || device.bleName,
|
|
8
|
+
});
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { type SexLabel } from './sex-label.js';
|
|
1
|
+
import type { AccountUser, HeightRecord } from 'fitdays-api';
|
|
3
2
|
export type UserSummary = {
|
|
4
|
-
|
|
5
|
-
height_cm: number;
|
|
3
|
+
account_user_id: string;
|
|
4
|
+
height_cm: null | number;
|
|
5
|
+
is_active: boolean;
|
|
6
|
+
is_admin: boolean;
|
|
6
7
|
nickname: string;
|
|
7
|
-
sex: SexLabel;
|
|
8
|
-
suid: number;
|
|
9
|
-
target_weight_kg: number;
|
|
10
|
-
uid: number;
|
|
11
8
|
};
|
|
12
|
-
export declare const summarizeUser: (user:
|
|
9
|
+
export declare const summarizeUser: (user: AccountUser, activeAccountUserId: string, heights: readonly HeightRecord[]) => UserSummary;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export const summarizeUser = (user) =>
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { round } from './round.js';
|
|
2
|
+
export const summarizeUser = (user, activeAccountUserId, heights) => {
|
|
3
|
+
const latestHeight = heights
|
|
4
|
+
.filter((record) => record.accountUserId === user.accountUserId)
|
|
5
|
+
.reduce((latest, record) => latest === null || record.dataAt > latest.dataAt ? record : latest, null);
|
|
6
|
+
return {
|
|
7
|
+
account_user_id: user.accountUserId,
|
|
8
|
+
height_cm: latestHeight ? round(latestHeight.height) : null,
|
|
9
|
+
is_active: user.accountUserId === activeAccountUserId,
|
|
10
|
+
is_admin: user.isAdmin === 1,
|
|
11
|
+
nickname: user.nickname,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -1,25 +1,13 @@
|
|
|
1
1
|
import type { WeightRecord } from 'fitdays-api';
|
|
2
|
-
import { type
|
|
2
|
+
import { type BodyCompositionSummary } from './body-composition-summary.js';
|
|
3
3
|
export type WeightSummary = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
bmr_kcal: number;
|
|
8
|
-
bodyage: number;
|
|
9
|
-
data_id: string;
|
|
10
|
-
ext_data?: null | WeightExtensionDataSummary;
|
|
11
|
-
is_deleted: 0 | 1;
|
|
4
|
+
account_user_id: string;
|
|
5
|
+
body_composition: BodyCompositionSummary | null;
|
|
6
|
+
device_id: string;
|
|
12
7
|
measured_at: string;
|
|
13
8
|
measured_time: number;
|
|
14
|
-
|
|
15
|
-
rom_pct: number;
|
|
16
|
-
rosm_pct: number;
|
|
17
|
-
sfr_pct: number;
|
|
18
|
-
suid: number;
|
|
19
|
-
uid: number;
|
|
20
|
-
uvi: number;
|
|
21
|
-
vwc_pct: number;
|
|
9
|
+
record_id: string;
|
|
22
10
|
weight_kg: number;
|
|
23
11
|
weight_lb: number;
|
|
24
12
|
};
|
|
25
|
-
export declare const summarizeWeight: (
|
|
13
|
+
export declare const summarizeWeight: (record: WeightRecord) => WeightSummary;
|
|
@@ -1,25 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
is_deleted: weightRecord.is_deleted,
|
|
13
|
-
measured_at: new Date(weightRecord.measured_time * 1000).toISOString(),
|
|
14
|
-
measured_time: weightRecord.measured_time,
|
|
15
|
-
pp_pct: weightRecord.pp,
|
|
16
|
-
rom_pct: weightRecord.rom,
|
|
17
|
-
rosm_pct: weightRecord.rosm,
|
|
18
|
-
sfr_pct: weightRecord.sfr,
|
|
19
|
-
suid: weightRecord.suid,
|
|
20
|
-
uid: weightRecord.uid,
|
|
21
|
-
uvi: weightRecord.uvi,
|
|
22
|
-
vwc_pct: weightRecord.vwc,
|
|
23
|
-
weight_kg: weightRecord.weight_kg,
|
|
24
|
-
weight_lb: weightRecord.weight_lb,
|
|
1
|
+
import { summarizeBodyComposition } from './body-composition-summary.js';
|
|
2
|
+
import { round } from './round.js';
|
|
3
|
+
export const summarizeWeight = (record) => ({
|
|
4
|
+
account_user_id: record.accountUserId,
|
|
5
|
+
body_composition: record.bodyCompositionInfo ? summarizeBodyComposition(record.bodyCompositionInfo) : null,
|
|
6
|
+
device_id: record.iotDeviceId,
|
|
7
|
+
measured_at: new Date(record.dataAt * 1000).toISOString(),
|
|
8
|
+
measured_time: record.dataAt,
|
|
9
|
+
record_id: record.recordId,
|
|
10
|
+
weight_kg: round(record.weight),
|
|
11
|
+
weight_lb: round(record.weightLb),
|
|
25
12
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fitdays-mcp-server",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "MCP server exposing the unofficial FitDays / iComon smart-scale API as tools (weight history, devices, users) for LLM clients.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|
|
@@ -36,30 +36,33 @@
|
|
|
36
36
|
},
|
|
37
37
|
"sideEffects": false,
|
|
38
38
|
"files": [
|
|
39
|
-
"dist"
|
|
39
|
+
"dist",
|
|
40
|
+
"!dist/**/*.test.*",
|
|
41
|
+
"!dist/testing"
|
|
40
42
|
],
|
|
41
43
|
"scripts": {
|
|
42
44
|
"build": "tsc",
|
|
43
45
|
"build:publish": "rm -rf dist && tsc",
|
|
44
46
|
"start": "node dist/index.js",
|
|
45
47
|
"lint": "eslint --fix",
|
|
48
|
+
"test": "tsc && node --test --experimental-test-coverage --test-coverage-exclude='dist/**/*.test.js' --test-coverage-exclude='dist/testing/**' --test-coverage-exclude='dist/index.js' --test-coverage-lines=90 --test-coverage-functions=90 --test-coverage-branches=80 'dist/**/*.test.js'",
|
|
46
49
|
"prepack": "npm run build:publish",
|
|
47
|
-
"prepublishOnly": "npm run lint"
|
|
50
|
+
"prepublishOnly": "npm run lint && npm test"
|
|
48
51
|
},
|
|
49
52
|
"dependencies": {
|
|
50
|
-
"@modelcontextprotocol/sdk": "1.
|
|
51
|
-
"fitdays-api": "
|
|
52
|
-
"zod": "4.
|
|
53
|
+
"@modelcontextprotocol/sdk": "1.32.2",
|
|
54
|
+
"fitdays-api": "2.0.0",
|
|
55
|
+
"zod": "4.6.7"
|
|
53
56
|
},
|
|
54
57
|
"devDependencies": {
|
|
55
58
|
"@eslint/js": "10.0.1",
|
|
56
|
-
"@stylistic/eslint-plugin": "
|
|
57
|
-
"@types/node": "26.
|
|
58
|
-
"eslint": "10.
|
|
59
|
-
"eslint-plugin-perfectionist": "5.
|
|
60
|
-
"globals": "17.
|
|
59
|
+
"@stylistic/eslint-plugin": "6.0.1",
|
|
60
|
+
"@types/node": "26.6.6",
|
|
61
|
+
"eslint": "10.15.0",
|
|
62
|
+
"eslint-plugin-perfectionist": "5.14.0",
|
|
63
|
+
"globals": "17.14.0",
|
|
61
64
|
"typescript": "6.0.3",
|
|
62
|
-
"typescript-eslint": "8.
|
|
65
|
+
"typescript-eslint": "8.73.0"
|
|
63
66
|
},
|
|
64
67
|
"engines": {
|
|
65
68
|
"node": ">=22.0.0"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const sexLabel = (sex) => sex === 0 ? 'male' : 'female';
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { WeightExtData } from 'fitdays-api';
|
|
2
|
-
import { type SexLabel } from './sex-label.js';
|
|
3
|
-
export type BodyTypeLabel = 'Athletic' | 'Balanced' | 'Hidden Overweight' | 'Muscular' | 'Muscular Overweight' | 'Muscular Slim' | 'Obese' | 'Overweight' | 'Slightly Underweight' | 'Slim' | 'Underweight';
|
|
4
|
-
export type WeightExtensionDataSummary = {
|
|
5
|
-
age: number;
|
|
6
|
-
bfmControl: number;
|
|
7
|
-
bfmMax: number;
|
|
8
|
-
bfmMin: number;
|
|
9
|
-
bfmStandard: number;
|
|
10
|
-
bfpMax: number;
|
|
11
|
-
bfpMin: number;
|
|
12
|
-
bfpStandard: number;
|
|
13
|
-
bmiMax: number;
|
|
14
|
-
bmiMin: number;
|
|
15
|
-
bmiStandard: number;
|
|
16
|
-
bmrMax: number;
|
|
17
|
-
bmrMin: number;
|
|
18
|
-
bmrStandard: number;
|
|
19
|
-
bodyScore: number;
|
|
20
|
-
bodyType: 'unknown' | BodyTypeLabel;
|
|
21
|
-
boneMax: number;
|
|
22
|
-
boneMin: number;
|
|
23
|
-
deviceModelExt: string;
|
|
24
|
-
deviceNameExt: string;
|
|
25
|
-
deviceSoftwareVer: null | string;
|
|
26
|
-
ffmControl: number;
|
|
27
|
-
ffmStandard: number;
|
|
28
|
-
height: number;
|
|
29
|
-
muscleMassMax: number;
|
|
30
|
-
muscleMassMin: number;
|
|
31
|
-
obesityDegree: number;
|
|
32
|
-
onlyMeasureWeight: boolean;
|
|
33
|
-
proteinMassMax: number;
|
|
34
|
-
proteinMassMin: number;
|
|
35
|
-
sex: SexLabel;
|
|
36
|
-
smi: number;
|
|
37
|
-
smmMax: number;
|
|
38
|
-
smmMin: number;
|
|
39
|
-
smmStandard: number;
|
|
40
|
-
targetBodyfatMass: null | number;
|
|
41
|
-
targetSMMMass: null | number;
|
|
42
|
-
targetWeight: number;
|
|
43
|
-
waterMassMax: number;
|
|
44
|
-
waterMassMin: number;
|
|
45
|
-
weightControl: number;
|
|
46
|
-
weightMax: number;
|
|
47
|
-
weightMin: number;
|
|
48
|
-
weightStandard: number;
|
|
49
|
-
};
|
|
50
|
-
export declare const summarizeWeightExtensionData: (extensionData: null | WeightExtData) => null | WeightExtensionDataSummary;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { sexLabel } from './sex-label.js';
|
|
2
|
-
const BODY_TYPE_LABELS = {
|
|
3
|
-
0: 'Underweight',
|
|
4
|
-
1: 'Slightly Underweight',
|
|
5
|
-
2: 'Muscular Slim',
|
|
6
|
-
3: 'Slim',
|
|
7
|
-
4: 'Muscular',
|
|
8
|
-
5: 'Balanced',
|
|
9
|
-
6: 'Athletic',
|
|
10
|
-
7: 'Muscular Overweight',
|
|
11
|
-
8: 'Obese',
|
|
12
|
-
9: 'Overweight',
|
|
13
|
-
10: 'Hidden Overweight',
|
|
14
|
-
};
|
|
15
|
-
export const summarizeWeightExtensionData = (extensionData) => {
|
|
16
|
-
if (extensionData === null)
|
|
17
|
-
return null;
|
|
18
|
-
return {
|
|
19
|
-
age: extensionData.age,
|
|
20
|
-
bfmControl: extensionData.bfmControl,
|
|
21
|
-
bfmMax: extensionData.bfmMax,
|
|
22
|
-
bfmMin: extensionData.bfmMin,
|
|
23
|
-
bfmStandard: extensionData.bfmStandard,
|
|
24
|
-
bfpMax: extensionData.bfpMax,
|
|
25
|
-
bfpMin: extensionData.bfpMin,
|
|
26
|
-
bfpStandard: extensionData.bfpStandard,
|
|
27
|
-
bmiMax: extensionData.bmiMax,
|
|
28
|
-
bmiMin: extensionData.bmiMin,
|
|
29
|
-
bmiStandard: extensionData.bmiStandard,
|
|
30
|
-
bmrMax: extensionData.bmrMax,
|
|
31
|
-
bmrMin: extensionData.bmrMin,
|
|
32
|
-
bmrStandard: extensionData.bmrStandard,
|
|
33
|
-
bodyScore: extensionData.bodyScore,
|
|
34
|
-
bodyType: BODY_TYPE_LABELS[extensionData.bodyType] ?? 'unknown',
|
|
35
|
-
boneMax: extensionData.boneMax,
|
|
36
|
-
boneMin: extensionData.boneMin,
|
|
37
|
-
deviceModelExt: extensionData.deviceModelExt,
|
|
38
|
-
deviceNameExt: extensionData.deviceNameExt,
|
|
39
|
-
deviceSoftwareVer: extensionData.deviceSoftwareVer ?? null,
|
|
40
|
-
ffmControl: extensionData.ffmControl,
|
|
41
|
-
ffmStandard: extensionData.ffmStandard,
|
|
42
|
-
height: extensionData.height,
|
|
43
|
-
muscleMassMax: extensionData.muscleMassMax,
|
|
44
|
-
muscleMassMin: extensionData.muscleMassMin,
|
|
45
|
-
obesityDegree: extensionData.obesityDegree,
|
|
46
|
-
onlyMeasureWeight: extensionData.onlyMeasureWeight === '1',
|
|
47
|
-
proteinMassMax: extensionData.proteinMassMax,
|
|
48
|
-
proteinMassMin: extensionData.proteinMassMin,
|
|
49
|
-
sex: sexLabel(extensionData.sex),
|
|
50
|
-
smi: extensionData.smi,
|
|
51
|
-
smmMax: extensionData.smmMax,
|
|
52
|
-
smmMin: extensionData.smmMin,
|
|
53
|
-
smmStandard: extensionData.smmStandard,
|
|
54
|
-
targetBodyfatMass: extensionData.targetBodyfatMass ?? null,
|
|
55
|
-
targetSMMMass: extensionData.targetSMMMass ?? null,
|
|
56
|
-
targetWeight: extensionData.targetWeight,
|
|
57
|
-
waterMassMax: extensionData.waterMassMax,
|
|
58
|
-
waterMassMin: extensionData.waterMassMin,
|
|
59
|
-
weightControl: extensionData.weightControl,
|
|
60
|
-
weightMax: extensionData.weightMax,
|
|
61
|
-
weightMin: extensionData.weightMin,
|
|
62
|
-
weightStandard: extensionData.weightStandard,
|
|
63
|
-
};
|
|
64
|
-
};
|