@molecule/api-wearable-fitbit 1.0.2 → 1.0.4
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/LICENSE +111 -24
- package/README.md +231 -231
- package/package.json +6 -6
package/LICENSE
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
Apache License
|
|
2
3
|
Version 2.0, January 2004
|
|
3
4
|
http://www.apache.org/licenses/
|
|
@@ -34,21 +35,33 @@
|
|
|
34
35
|
|
|
35
36
|
"Work" shall mean the work of authorship, whether in Source or
|
|
36
37
|
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
38
40
|
|
|
39
41
|
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
42
|
form, that is based on (or derived from) the Work and for which the
|
|
41
43
|
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
-
represent, as a whole, an original work of authorship.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
49
62
|
|
|
50
63
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
51
|
-
on behalf of whom a Contribution has been received by
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
52
65
|
subsequently incorporated within the Work.
|
|
53
66
|
|
|
54
67
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
@@ -61,8 +74,18 @@
|
|
|
61
74
|
3. Grant of Patent License. Subject to the terms and conditions of
|
|
62
75
|
this License, each Contributor hereby grants to You a perpetual,
|
|
63
76
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
64
|
-
|
|
65
|
-
and otherwise transfer the Work
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
66
89
|
|
|
67
90
|
4. Redistribution. You may reproduce and distribute copies of the
|
|
68
91
|
Work or Derivative Works thereof in any medium, with or without
|
|
@@ -84,23 +107,87 @@
|
|
|
84
107
|
(d) If the Work includes a "NOTICE" text file as part of its
|
|
85
108
|
distribution, then any Derivative Works that You distribute must
|
|
86
109
|
include a readable copy of the attribution notices contained
|
|
87
|
-
within such NOTICE file
|
|
88
|
-
|
|
89
|
-
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
90
138
|
|
|
91
139
|
6. Trademarks. This License does not grant permission to use the trade
|
|
92
|
-
names, trademarks, service marks, or product names of the Licensor
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
93
143
|
|
|
94
144
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
95
|
-
agreed to in writing, Licensor provides the Work
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
104
191
|
|
|
105
192
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
106
193
|
you may not use this file except in compliance with the License.
|
package/README.md
CHANGED
|
@@ -3,15 +3,11 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
|
3
3
|
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
4
|
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
5
|
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
-
Generated: 2026-
|
|
6
|
+
Generated: 2026-10-26T04:24:21.592Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/api-wearable-fitbit
|
|
10
10
|
|
|
11
|
-
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
12
|
-
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
13
|
-
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
14
|
-
|
|
15
11
|
Fitbit Web API bond for `@molecule/api-wearable`.
|
|
16
12
|
|
|
17
13
|
Implements daily activity, sleep, heart-rate, and weight ingestion
|
|
@@ -19,6 +15,10 @@ against the Fitbit Web API using OAuth 2.0 PKCE with refresh-token
|
|
|
19
15
|
rotation. Wires under the `wearable` named-multi-provider category as
|
|
20
16
|
`'fitbit'`.
|
|
21
17
|
|
|
18
|
+
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
19
|
+
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
20
|
+
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
21
|
+
|
|
22
22
|
## Quick Start
|
|
23
23
|
|
|
24
24
|
```typescript
|
|
@@ -48,47 +48,6 @@ npm install @molecule/api-wearable-fitbit @molecule/api-bond @molecule/api-http
|
|
|
48
48
|
|
|
49
49
|
### Interfaces
|
|
50
50
|
|
|
51
|
-
#### `DailyActivity`
|
|
52
|
-
|
|
53
|
-
Daily activity rollup. All fields are zero-defaulted by the bond when
|
|
54
|
-
the provider does not return a value, so handlers can sum across days
|
|
55
|
-
without null-checks.
|
|
56
|
-
|
|
57
|
-
```typescript
|
|
58
|
-
interface DailyActivity {
|
|
59
|
-
/** Calendar day this rollup covers (`YYYY-MM-DD`). */
|
|
60
|
-
date: WearableDate
|
|
61
|
-
/** Total step count for the day. */
|
|
62
|
-
steps: number
|
|
63
|
-
/** Total distance traveled, in meters. */
|
|
64
|
-
distanceMeters: number
|
|
65
|
-
/** Total calories burned (active + BMR), in kilocalories. */
|
|
66
|
-
caloriesOut: number
|
|
67
|
-
/** Active minutes (provider-specific intensity definitions). */
|
|
68
|
-
activeMinutes: number
|
|
69
|
-
/** Floors climbed, when reported. */
|
|
70
|
-
floors?: number
|
|
71
|
-
/** Total elevation gain, in meters, when reported. */
|
|
72
|
-
elevationMeters?: number
|
|
73
|
-
/** Resting heart-rate, in beats per minute, when reported. */
|
|
74
|
-
restingHeartRate?: number
|
|
75
|
-
}
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
#### `FitbitAuthorizeStart`
|
|
79
|
-
|
|
80
|
-
Result of {@link FitbitProvider.startAuthorize} — the URL the host
|
|
81
|
-
should redirect the user to plus the `state` value to round-trip.
|
|
82
|
-
|
|
83
|
-
```typescript
|
|
84
|
-
interface FitbitAuthorizeStart {
|
|
85
|
-
/** Fitbit OAuth authorize URL. */
|
|
86
|
-
url: string
|
|
87
|
-
/** Opaque `state` value the host MUST verify on the callback. */
|
|
88
|
-
state: string
|
|
89
|
-
}
|
|
90
|
-
```
|
|
91
|
-
|
|
92
51
|
#### `FitbitCodeVerifierStore`
|
|
93
52
|
|
|
94
53
|
Cache of `code_verifier` strings keyed by the in-flight authorization
|
|
@@ -121,38 +80,6 @@ interface FitbitCodeVerifierStore {
|
|
|
121
80
|
}
|
|
122
81
|
```
|
|
123
82
|
|
|
124
|
-
#### `FitbitProvider`
|
|
125
|
-
|
|
126
|
-
Public surface returned by {@link createProvider}. Extends the
|
|
127
|
-
stack-neutral {@link import('@molecule/api-wearable').WearableProvider}
|
|
128
|
-
with Fitbit-specific OAuth-flow helpers.
|
|
129
|
-
|
|
130
|
-
```typescript
|
|
131
|
-
interface FitbitProvider extends WearableProviderType {
|
|
132
|
-
/**
|
|
133
|
-
* Builds the Fitbit authorize URL and persists a fresh PKCE verifier.
|
|
134
|
-
*
|
|
135
|
-
* @returns The URL to redirect to and the round-trip `state` value.
|
|
136
|
-
*/
|
|
137
|
-
startAuthorize(): Promise<FitbitAuthorizeStart>
|
|
138
|
-
/**
|
|
139
|
-
* Performs the authorization-code → token exchange with an explicit
|
|
140
|
-
* PKCE `code_verifier`. Use this when the host wires the OAuth flow
|
|
141
|
-
* itself (no `codeVerifierStore` configured).
|
|
142
|
-
*
|
|
143
|
-
* @param userId - Host-app user identifier.
|
|
144
|
-
* @param code - OAuth authorization `code` from the redirect callback.
|
|
145
|
-
* @param verifier - The PKCE `code_verifier` used to derive the challenge.
|
|
146
|
-
* @returns The freshly-minted user connection (already persisted).
|
|
147
|
-
*/
|
|
148
|
-
connectWithVerifier(
|
|
149
|
-
userId: string,
|
|
150
|
-
code: string,
|
|
151
|
-
verifier: string,
|
|
152
|
-
): Promise<WearableUserConnection>
|
|
153
|
-
}
|
|
154
|
-
```
|
|
155
|
-
|
|
156
83
|
#### `FitbitProviderOptions`
|
|
157
84
|
|
|
158
85
|
Configuration options for {@link createProvider}.
|
|
@@ -226,105 +153,62 @@ interface FitbitProviderOptions {
|
|
|
226
153
|
}
|
|
227
154
|
```
|
|
228
155
|
|
|
229
|
-
#### `
|
|
230
|
-
|
|
231
|
-
Daily heart-rate summary.
|
|
232
|
-
|
|
233
|
-
```typescript
|
|
234
|
-
interface HeartRateSummary {
|
|
235
|
-
/** Calendar day this summary covers (`YYYY-MM-DD`). */
|
|
236
|
-
date: WearableDate
|
|
237
|
-
/** Resting heart-rate, in beats per minute, when reported. */
|
|
238
|
-
restingHeartRate?: number
|
|
239
|
-
/** Per-zone breakdown, when reported. */
|
|
240
|
-
zones?: HeartRateZone[]
|
|
241
|
-
}
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
#### `HeartRateZone`
|
|
245
|
-
|
|
246
|
-
Heart-rate zone definition (rest/fat-burn/cardio/peak or provider-named).
|
|
247
|
-
|
|
248
|
-
```typescript
|
|
249
|
-
interface HeartRateZone {
|
|
250
|
-
/** Zone label as reported by the provider. */
|
|
251
|
-
name: string
|
|
252
|
-
/** Lower bound of the zone, in beats per minute (inclusive). */
|
|
253
|
-
minBpm: number
|
|
254
|
-
/** Upper bound of the zone, in beats per minute (exclusive). */
|
|
255
|
-
maxBpm: number
|
|
256
|
-
/** Minutes spent in the zone for this period. */
|
|
257
|
-
minutes: number
|
|
258
|
-
/** Calories burned in the zone, in kilocalories. */
|
|
259
|
-
caloriesOut?: number
|
|
260
|
-
}
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
#### `SleepSession`
|
|
156
|
+
#### `FitbitAuthorizeStart`
|
|
264
157
|
|
|
265
|
-
|
|
266
|
-
|
|
158
|
+
Result of {@link FitbitProvider.startAuthorize} — the URL the host
|
|
159
|
+
should redirect the user to plus the `state` value to round-trip.
|
|
267
160
|
|
|
268
161
|
```typescript
|
|
269
|
-
interface
|
|
270
|
-
/**
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
|
|
274
|
-
/** ISO 8601 sleep start. */
|
|
275
|
-
start: string
|
|
276
|
-
/** ISO 8601 sleep end. */
|
|
277
|
-
end: string
|
|
278
|
-
/** Total time in bed, in minutes. */
|
|
279
|
-
timeInBedMinutes: number
|
|
280
|
-
/** Total time asleep, in minutes (excludes `awake` segments). */
|
|
281
|
-
timeAsleepMinutes: number
|
|
282
|
-
/** Sleep efficiency percentage (0-100). */
|
|
283
|
-
efficiency?: number
|
|
284
|
-
/** Whether this session is the user's primary sleep for the day. */
|
|
285
|
-
isMainSleep: boolean
|
|
286
|
-
/** Per-stage minute totals when the provider reports stages. */
|
|
287
|
-
stageSummary?: SleepStageSummary
|
|
288
|
-
/** Per-segment stage breakdown when the provider reports stages. */
|
|
289
|
-
segments?: SleepStageSegment[]
|
|
162
|
+
interface FitbitAuthorizeStart {
|
|
163
|
+
/** Fitbit OAuth authorize URL. */
|
|
164
|
+
url: string
|
|
165
|
+
/** Opaque `state` value the host MUST verify on the callback. */
|
|
166
|
+
state: string
|
|
290
167
|
}
|
|
291
168
|
```
|
|
292
169
|
|
|
293
|
-
#### `
|
|
170
|
+
#### `FitbitProvider`
|
|
294
171
|
|
|
295
|
-
|
|
172
|
+
Public surface returned by {@link createProvider}. Extends the
|
|
173
|
+
stack-neutral {@link import('@molecule/api-wearable').WearableProvider}
|
|
174
|
+
with Fitbit-specific OAuth-flow helpers.
|
|
296
175
|
|
|
297
176
|
```typescript
|
|
298
|
-
interface
|
|
299
|
-
/**
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
|
|
177
|
+
interface FitbitProvider extends WearableProviderType {
|
|
178
|
+
/**
|
|
179
|
+
* Builds the Fitbit authorize URL and persists a fresh PKCE verifier.
|
|
180
|
+
*
|
|
181
|
+
* @returns The URL to redirect to and the round-trip `state` value.
|
|
182
|
+
*/
|
|
183
|
+
startAuthorize(): Promise<FitbitAuthorizeStart>
|
|
184
|
+
/**
|
|
185
|
+
* Performs the authorization-code → token exchange with an explicit
|
|
186
|
+
* PKCE `code_verifier`. Use this when the host wires the OAuth flow
|
|
187
|
+
* itself (no `codeVerifierStore` configured).
|
|
188
|
+
*
|
|
189
|
+
* @param userId - Host-app user identifier.
|
|
190
|
+
* @param code - OAuth authorization `code` from the redirect callback.
|
|
191
|
+
* @param verifier - The PKCE `code_verifier` used to derive the challenge.
|
|
192
|
+
* @returns The freshly-minted user connection (already persisted).
|
|
193
|
+
*/
|
|
194
|
+
connectWithVerifier(
|
|
195
|
+
userId: string,
|
|
196
|
+
code: string,
|
|
197
|
+
verifier: string,
|
|
198
|
+
): Promise<WearableUserConnection>
|
|
307
199
|
}
|
|
308
200
|
```
|
|
309
201
|
|
|
310
|
-
#### `
|
|
202
|
+
#### `WearableDateRange`
|
|
311
203
|
|
|
312
|
-
|
|
313
|
-
that only report the coarse "asleep" classification will omit
|
|
314
|
-
`light`/`deep`/`rem`.
|
|
204
|
+
Inclusive date range.
|
|
315
205
|
|
|
316
206
|
```typescript
|
|
317
|
-
interface
|
|
318
|
-
/**
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
|
|
322
|
-
/** Minutes in deep sleep. */
|
|
323
|
-
deepMinutes?: number
|
|
324
|
-
/** Minutes in REM sleep. */
|
|
325
|
-
remMinutes?: number
|
|
326
|
-
/** Minutes restless (legacy classifications). */
|
|
327
|
-
restlessMinutes?: number
|
|
207
|
+
interface WearableDateRange {
|
|
208
|
+
/** Lower-bound calendar day (`YYYY-MM-DD`), inclusive. */
|
|
209
|
+
start: WearableDate
|
|
210
|
+
/** Upper-bound calendar day (`YYYY-MM-DD`), inclusive. */
|
|
211
|
+
end: WearableDate
|
|
328
212
|
}
|
|
329
213
|
```
|
|
330
214
|
|
|
@@ -392,16 +276,153 @@ interface WearableCredentialsStore {
|
|
|
392
276
|
}
|
|
393
277
|
```
|
|
394
278
|
|
|
395
|
-
#### `
|
|
279
|
+
#### `DailyActivity`
|
|
396
280
|
|
|
397
|
-
|
|
281
|
+
Daily activity rollup. All fields are zero-defaulted by the bond when
|
|
282
|
+
the provider does not return a value, so handlers can sum across days
|
|
283
|
+
without null-checks.
|
|
398
284
|
|
|
399
285
|
```typescript
|
|
400
|
-
interface
|
|
401
|
-
/**
|
|
402
|
-
|
|
403
|
-
/**
|
|
404
|
-
|
|
286
|
+
interface DailyActivity {
|
|
287
|
+
/** Calendar day this rollup covers (`YYYY-MM-DD`). */
|
|
288
|
+
date: WearableDate
|
|
289
|
+
/** Total step count for the day. */
|
|
290
|
+
steps: number
|
|
291
|
+
/** Total distance traveled, in meters. */
|
|
292
|
+
distanceMeters: number
|
|
293
|
+
/** Total calories burned (active + BMR), in kilocalories. */
|
|
294
|
+
caloriesOut: number
|
|
295
|
+
/** Active minutes (provider-specific intensity definitions). */
|
|
296
|
+
activeMinutes: number
|
|
297
|
+
/** Floors climbed, when reported. */
|
|
298
|
+
floors?: number
|
|
299
|
+
/** Total elevation gain, in meters, when reported. */
|
|
300
|
+
elevationMeters?: number
|
|
301
|
+
/** Resting heart-rate, in beats per minute, when reported. */
|
|
302
|
+
restingHeartRate?: number
|
|
303
|
+
}
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
#### `SleepStageSegment`
|
|
307
|
+
|
|
308
|
+
A contiguous block of a single sleep stage within a sleep session.
|
|
309
|
+
|
|
310
|
+
```typescript
|
|
311
|
+
interface SleepStageSegment {
|
|
312
|
+
/** Normalized stage. */
|
|
313
|
+
stage: SleepStage
|
|
314
|
+
/** ISO 8601 segment start. */
|
|
315
|
+
start: string
|
|
316
|
+
/** ISO 8601 segment end. */
|
|
317
|
+
end: string
|
|
318
|
+
/** Segment duration in seconds (provider-reported when available). */
|
|
319
|
+
durationSeconds: number
|
|
320
|
+
}
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
#### `SleepStageSummary`
|
|
324
|
+
|
|
325
|
+
Per-stage totals for a sleep session, in minutes. Optional — providers
|
|
326
|
+
that only report the coarse "asleep" classification will omit
|
|
327
|
+
`light`/`deep`/`rem`.
|
|
328
|
+
|
|
329
|
+
```typescript
|
|
330
|
+
interface SleepStageSummary {
|
|
331
|
+
/** Minutes spent awake during the session. */
|
|
332
|
+
awakeMinutes?: number
|
|
333
|
+
/** Minutes in light sleep. */
|
|
334
|
+
lightMinutes?: number
|
|
335
|
+
/** Minutes in deep sleep. */
|
|
336
|
+
deepMinutes?: number
|
|
337
|
+
/** Minutes in REM sleep. */
|
|
338
|
+
remMinutes?: number
|
|
339
|
+
/** Minutes restless (legacy classifications). */
|
|
340
|
+
restlessMinutes?: number
|
|
341
|
+
}
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
#### `SleepSession`
|
|
345
|
+
|
|
346
|
+
One sleep session. Most users have exactly one per night, but providers
|
|
347
|
+
report naps as separate sessions, so handlers must sum across the array.
|
|
348
|
+
|
|
349
|
+
```typescript
|
|
350
|
+
interface SleepSession {
|
|
351
|
+
/** Provider-specific session id. */
|
|
352
|
+
id: string
|
|
353
|
+
/** Calendar day this session is bucketed under (`YYYY-MM-DD`). */
|
|
354
|
+
date: WearableDate
|
|
355
|
+
/** ISO 8601 sleep start. */
|
|
356
|
+
start: string
|
|
357
|
+
/** ISO 8601 sleep end. */
|
|
358
|
+
end: string
|
|
359
|
+
/** Total time in bed, in minutes. */
|
|
360
|
+
timeInBedMinutes: number
|
|
361
|
+
/** Total time asleep, in minutes (excludes `awake` segments). */
|
|
362
|
+
timeAsleepMinutes: number
|
|
363
|
+
/** Sleep efficiency percentage (0-100). */
|
|
364
|
+
efficiency?: number
|
|
365
|
+
/** Whether this session is the user's primary sleep for the day. */
|
|
366
|
+
isMainSleep: boolean
|
|
367
|
+
/** Per-stage minute totals when the provider reports stages. */
|
|
368
|
+
stageSummary?: SleepStageSummary
|
|
369
|
+
/** Per-segment stage breakdown when the provider reports stages. */
|
|
370
|
+
segments?: SleepStageSegment[]
|
|
371
|
+
}
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
#### `HeartRateZone`
|
|
375
|
+
|
|
376
|
+
Heart-rate zone definition (rest/fat-burn/cardio/peak or provider-named).
|
|
377
|
+
|
|
378
|
+
```typescript
|
|
379
|
+
interface HeartRateZone {
|
|
380
|
+
/** Zone label as reported by the provider. */
|
|
381
|
+
name: string
|
|
382
|
+
/** Lower bound of the zone, in beats per minute (inclusive). */
|
|
383
|
+
minBpm: number
|
|
384
|
+
/** Upper bound of the zone, in beats per minute (exclusive). */
|
|
385
|
+
maxBpm: number
|
|
386
|
+
/** Minutes spent in the zone for this period. */
|
|
387
|
+
minutes: number
|
|
388
|
+
/** Calories burned in the zone, in kilocalories. */
|
|
389
|
+
caloriesOut?: number
|
|
390
|
+
}
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
#### `HeartRateSummary`
|
|
394
|
+
|
|
395
|
+
Daily heart-rate summary.
|
|
396
|
+
|
|
397
|
+
```typescript
|
|
398
|
+
interface HeartRateSummary {
|
|
399
|
+
/** Calendar day this summary covers (`YYYY-MM-DD`). */
|
|
400
|
+
date: WearableDate
|
|
401
|
+
/** Resting heart-rate, in beats per minute, when reported. */
|
|
402
|
+
restingHeartRate?: number
|
|
403
|
+
/** Per-zone breakdown, when reported. */
|
|
404
|
+
zones?: HeartRateZone[]
|
|
405
|
+
}
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
#### `WeightEntry`
|
|
409
|
+
|
|
410
|
+
One body-weight reading.
|
|
411
|
+
|
|
412
|
+
```typescript
|
|
413
|
+
interface WeightEntry {
|
|
414
|
+
/** ISO 8601 timestamp at which the reading was taken. */
|
|
415
|
+
recordedAt: string
|
|
416
|
+
/** Calendar day of the reading (`YYYY-MM-DD`). */
|
|
417
|
+
date: WearableDate
|
|
418
|
+
/** Weight in kilograms. */
|
|
419
|
+
weightKg: number
|
|
420
|
+
/** Body-fat percentage (0-100), when reported. */
|
|
421
|
+
bodyFatPercent?: number
|
|
422
|
+
/** BMI (kg / m²), when reported. */
|
|
423
|
+
bmi?: number
|
|
424
|
+
/** Provider-specific entry id. */
|
|
425
|
+
id?: string
|
|
405
426
|
}
|
|
406
427
|
```
|
|
407
428
|
|
|
@@ -491,29 +512,18 @@ interface WearableProvider {
|
|
|
491
512
|
}
|
|
492
513
|
```
|
|
493
514
|
|
|
494
|
-
|
|
515
|
+
### Types
|
|
495
516
|
|
|
496
|
-
|
|
517
|
+
#### `WearableDate`
|
|
518
|
+
|
|
519
|
+
Calendar-day identifier in `YYYY-MM-DD` format. Wearable providers
|
|
520
|
+
universally bucket activity/sleep/HR data by local-day, so the core
|
|
521
|
+
exchanges date strings (not absolute timestamps) for per-day reads.
|
|
497
522
|
|
|
498
523
|
```typescript
|
|
499
|
-
|
|
500
|
-
/** ISO 8601 timestamp at which the reading was taken. */
|
|
501
|
-
recordedAt: string
|
|
502
|
-
/** Calendar day of the reading (`YYYY-MM-DD`). */
|
|
503
|
-
date: WearableDate
|
|
504
|
-
/** Weight in kilograms. */
|
|
505
|
-
weightKg: number
|
|
506
|
-
/** Body-fat percentage (0-100), when reported. */
|
|
507
|
-
bodyFatPercent?: number
|
|
508
|
-
/** BMI (kg / m²), when reported. */
|
|
509
|
-
bmi?: number
|
|
510
|
-
/** Provider-specific entry id. */
|
|
511
|
-
id?: string
|
|
512
|
-
}
|
|
524
|
+
type WearableDate = string
|
|
513
525
|
```
|
|
514
526
|
|
|
515
|
-
### Types
|
|
516
|
-
|
|
517
527
|
#### `SleepStage`
|
|
518
528
|
|
|
519
529
|
Sleep stage taxonomy normalized across providers.
|
|
@@ -527,16 +537,6 @@ Sleep stage taxonomy normalized across providers.
|
|
|
527
537
|
type SleepStage = 'awake' | 'light' | 'deep' | 'rem' | 'restless' | 'asleep' | 'unknown'
|
|
528
538
|
```
|
|
529
539
|
|
|
530
|
-
#### `WearableDate`
|
|
531
|
-
|
|
532
|
-
Calendar-day identifier in `YYYY-MM-DD` format. Wearable providers
|
|
533
|
-
universally bucket activity/sleep/HR data by local-day, so the core
|
|
534
|
-
exchanges date strings (not absolute timestamps) for per-day reads.
|
|
535
|
-
|
|
536
|
-
```typescript
|
|
537
|
-
type WearableDate = string
|
|
538
|
-
```
|
|
539
|
-
|
|
540
540
|
### Functions
|
|
541
541
|
|
|
542
542
|
#### `base64UrlEncode(bytes)`
|
|
@@ -544,24 +544,25 @@ type WearableDate = string
|
|
|
544
544
|
Base64url-encodes the bytes (RFC 4648 §5 with `=` padding stripped).
|
|
545
545
|
|
|
546
546
|
```typescript
|
|
547
|
-
function base64UrlEncode(bytes: Uint8Array
|
|
547
|
+
function base64UrlEncode(bytes: Uint8Array): string
|
|
548
548
|
```
|
|
549
549
|
|
|
550
550
|
- `bytes` — The bytes to encode.
|
|
551
551
|
|
|
552
552
|
**Returns:** A base64url string.
|
|
553
553
|
|
|
554
|
-
#### `
|
|
554
|
+
#### `sha256Base64Url(input)`
|
|
555
555
|
|
|
556
|
-
|
|
556
|
+
SHA-256-hashes the input string and base64url-encodes the digest. Used
|
|
557
|
+
to derive the PKCE `code_challenge` from the `code_verifier`.
|
|
557
558
|
|
|
558
559
|
```typescript
|
|
559
|
-
function
|
|
560
|
+
function sha256Base64Url(input: string): Promise<string>
|
|
560
561
|
```
|
|
561
562
|
|
|
562
|
-
- `
|
|
563
|
+
- `input` — The string to hash.
|
|
563
564
|
|
|
564
|
-
**Returns:** A
|
|
565
|
+
**Returns:** A base64url-encoded SHA-256 digest.
|
|
565
566
|
|
|
566
567
|
#### `fromFitbitActivity(date, raw)`
|
|
567
568
|
|
|
@@ -570,7 +571,7 @@ normalized {@link DailyActivity} shape. Missing fields are zero-defaulted
|
|
|
570
571
|
so handlers can sum across days without null guards.
|
|
571
572
|
|
|
572
573
|
```typescript
|
|
573
|
-
function fromFitbitActivity(date:
|
|
574
|
+
function fromFitbitActivity(date: WearableDate, raw: FitbitDailyActivityResponse): DailyActivity
|
|
574
575
|
```
|
|
575
576
|
|
|
576
577
|
- `date` — The calendar day the response was requested for.
|
|
@@ -578,19 +579,19 @@ function fromFitbitActivity(date: string, raw: FitbitDailyActivityResponse): Dai
|
|
|
578
579
|
|
|
579
580
|
**Returns:** A normalized daily activity record.
|
|
580
581
|
|
|
581
|
-
#### `
|
|
582
|
+
#### `mapSleepStage(level)`
|
|
582
583
|
|
|
583
|
-
|
|
584
|
-
{@link
|
|
584
|
+
Maps Fitbit's per-segment `level` string onto our normalized
|
|
585
|
+
{@link SleepStage} taxonomy. Both `classic` and `stages` payloads are
|
|
586
|
+
supported; unknown values fall through to `unknown`.
|
|
585
587
|
|
|
586
588
|
```typescript
|
|
587
|
-
function
|
|
589
|
+
function mapSleepStage(level: string): SleepStage
|
|
588
590
|
```
|
|
589
591
|
|
|
590
|
-
- `
|
|
591
|
-
- `raw` — Fitbit's heart-rate response payload.
|
|
592
|
+
- `level` — The Fitbit sleep level string.
|
|
592
593
|
|
|
593
|
-
**Returns:** A normalized
|
|
594
|
+
**Returns:** A normalized sleep stage.
|
|
594
595
|
|
|
595
596
|
#### `fromFitbitSleep(date, raw)`
|
|
596
597
|
|
|
@@ -598,7 +599,7 @@ Translates a Fitbit `sleep/date` payload into a list of normalized
|
|
|
598
599
|
{@link SleepSession} records.
|
|
599
600
|
|
|
600
601
|
```typescript
|
|
601
|
-
function fromFitbitSleep(date:
|
|
602
|
+
function fromFitbitSleep(date: WearableDate, raw: FitbitSleepResponse): SleepSession[]
|
|
602
603
|
```
|
|
603
604
|
|
|
604
605
|
- `date` — Calendar day the response was requested for.
|
|
@@ -606,45 +607,44 @@ function fromFitbitSleep(date: string, raw: FitbitSleepResponse): SleepSession[]
|
|
|
606
607
|
|
|
607
608
|
**Returns:** Normalized sleep sessions ordered by start ascending.
|
|
608
609
|
|
|
609
|
-
#### `
|
|
610
|
+
#### `fromFitbitHeartRate(date, raw)`
|
|
610
611
|
|
|
611
|
-
Translates a Fitbit
|
|
612
|
-
{@link
|
|
612
|
+
Translates a Fitbit `activities/heart/date` payload into the normalized
|
|
613
|
+
{@link HeartRateSummary} shape.
|
|
613
614
|
|
|
614
615
|
```typescript
|
|
615
|
-
function
|
|
616
|
+
function fromFitbitHeartRate(date: WearableDate, raw: FitbitHeartRateResponse): HeartRateSummary
|
|
616
617
|
```
|
|
617
618
|
|
|
618
|
-
- `
|
|
619
|
+
- `date` — Calendar day the response was requested for.
|
|
620
|
+
- `raw` — Fitbit's heart-rate response payload.
|
|
619
621
|
|
|
620
|
-
**Returns:**
|
|
622
|
+
**Returns:** A normalized heart-rate summary.
|
|
621
623
|
|
|
622
|
-
#### `
|
|
624
|
+
#### `fromFitbitWeight(raw)`
|
|
623
625
|
|
|
624
|
-
|
|
625
|
-
{@link
|
|
626
|
-
supported; unknown values fall through to `unknown`.
|
|
626
|
+
Translates a Fitbit weight-log payload into normalized
|
|
627
|
+
{@link WeightEntry} records ordered by `recordedAt` ascending.
|
|
627
628
|
|
|
628
629
|
```typescript
|
|
629
|
-
function
|
|
630
|
+
function fromFitbitWeight(raw: FitbitWeightResponse): WeightEntry[]
|
|
630
631
|
```
|
|
631
632
|
|
|
632
|
-
- `
|
|
633
|
+
- `raw` — Fitbit's weight response payload.
|
|
633
634
|
|
|
634
|
-
**Returns:**
|
|
635
|
+
**Returns:** Normalized weight entries.
|
|
635
636
|
|
|
636
|
-
#### `
|
|
637
|
+
#### `createProvider(options)`
|
|
637
638
|
|
|
638
|
-
|
|
639
|
-
to derive the PKCE `code_challenge` from the `code_verifier`.
|
|
639
|
+
Creates a Fitbit wearable provider.
|
|
640
640
|
|
|
641
641
|
```typescript
|
|
642
|
-
function
|
|
642
|
+
function createProvider(options: FitbitProviderOptions): FitbitProvider
|
|
643
643
|
```
|
|
644
644
|
|
|
645
|
-
- `
|
|
645
|
+
- `options` — Required: `redirectUri` + `credentialsStore`. Falls back to `OAUTH_FITBIT_CLIENT_ID` / `OAUTH_FITBIT_CLIENT_SECRET` env vars when `clientId` / `clientSecret` are omitted.
|
|
646
646
|
|
|
647
|
-
**Returns:** A
|
|
647
|
+
**Returns:** A Fitbit-flavored {@link FitbitProvider}.
|
|
648
648
|
|
|
649
649
|
### Constants
|
|
650
650
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/api-wearable-fitbit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Fitbit Web API bond for molecule.dev — daily activity, sleep, heart-rate, and weight ingestion via OAuth 2.0 PKCE",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -37,12 +37,12 @@
|
|
|
37
37
|
"@molecule/api-wearable": "^1.0.1"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@molecule/api-bond": "1.0.
|
|
41
|
-
"@molecule/api-http": "1.0.
|
|
42
|
-
"@molecule/api-wearable": "1.0.
|
|
43
|
-
"@types/node": "26.
|
|
40
|
+
"@molecule/api-bond": "1.0.4",
|
|
41
|
+
"@molecule/api-http": "1.0.4",
|
|
42
|
+
"@molecule/api-wearable": "1.0.3",
|
|
43
|
+
"@types/node": "26.6.5",
|
|
44
44
|
"typescript": "6.0.3",
|
|
45
|
-
"vitest": "4.1.
|
|
45
|
+
"vitest": "4.1.12"
|
|
46
46
|
},
|
|
47
47
|
"repository": {
|
|
48
48
|
"type": "git",
|