@dofek/eight-sleep 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 Asher Cohen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,135 @@
1
+ # @dofek/eight-sleep
2
+
3
+ Unofficial TypeScript client for the private API used by Eight Sleep clients. It
4
+ retrieves trend days containing sleep sessions, sleep-stage data, daily
5
+ biometrics, and heart-rate samples.
6
+
7
+ This package is not affiliated with, endorsed by, or supported by Eight Sleep.
8
+ It uses undocumented endpoints and an observed app authentication flow, so
9
+ either may change without notice.
10
+
11
+ ## Requirements and installation
12
+
13
+ Requires Node.js 22.14 or newer and its built-in
14
+ [`fetch`](https://nodejs.org/api/globals.html#fetch) implementation.
15
+
16
+ ```sh
17
+ npm install @dofek/eight-sleep
18
+ ```
19
+
20
+ ## Quick start
21
+
22
+ Save this as `example.mjs`, set `EIGHT_SLEEP_EMAIL` and
23
+ `EIGHT_SLEEP_PASSWORD`, then run `node example.mjs`.
24
+
25
+ ```js
26
+ import { EightSleepClient } from "@dofek/eight-sleep";
27
+
28
+ const email = process.env.EIGHT_SLEEP_EMAIL;
29
+ const password = process.env.EIGHT_SLEEP_PASSWORD;
30
+ if (!email || !password) {
31
+ throw new Error("Set EIGHT_SLEEP_EMAIL and EIGHT_SLEEP_PASSWORD");
32
+ }
33
+
34
+ const { accessToken, expiresIn, userId } = await EightSleepClient.signIn(
35
+ email,
36
+ password,
37
+ );
38
+ const client = new EightSleepClient(accessToken, userId);
39
+ const trends = await client.getTrends("UTC", "2026-07-01", "2026-07-07");
40
+
41
+ console.log({ expiresIn, days: trends.days.length });
42
+ ```
43
+
44
+ `getTrends(timezone, fromDate, toDate)` expects `YYYY-MM-DD` dates. The
45
+ [current client implementation](https://github.com/Asherlc/dofek/blob/main/packages/eight-sleep/src/client.ts)
46
+ always requests all sessions with model version `v2`.
47
+
48
+ ## Public API
49
+
50
+ - `EightSleepClient.signIn(email, password, fetch?)` returns `accessToken`,
51
+ `expiresIn` in seconds, and `userId`.
52
+ - `new EightSleepClient(accessToken, userId, fetch?)` creates an authenticated
53
+ client. Supplying `fetch` is useful for custom transport instrumentation.
54
+ - `client.getTrends(timezone, fromDate, toDate)` retrieves raw trend days and
55
+ their nested sessions and time series.
56
+
57
+ Supported deep imports:
58
+
59
+ - `@dofek/eight-sleep/client` — client and observed app credential constants.
60
+ - `@dofek/eight-sleep/parsing` — `parseEightSleepTrendDay`,
61
+ `parseEightSleepDailyMetrics`, and `parseEightSleepHeartRateSamples`.
62
+ - `@dofek/eight-sleep/types` — raw response interfaces.
63
+
64
+ For example:
65
+
66
+ ```ts
67
+ import { parseEightSleepDailyMetrics } from "@dofek/eight-sleep/parsing";
68
+ import type { EightSleepTrendDay } from "@dofek/eight-sleep/types";
69
+ ```
70
+
71
+ ## Authentication and persistence
72
+
73
+ The [current implementation](https://github.com/Asherlc/dofek/blob/main/packages/eight-sleep/src/client.ts)
74
+ sends a password-grant request with client credentials observed in the Eight
75
+ Sleep Android application. Those `EIGHT_SLEEP_CLIENT_ID` and
76
+ `EIGHT_SLEEP_CLIENT_SECRET` values identify the upstream app; they are
77
+ intentionally visible in this package and are not a substitute for the user's
78
+ email and password.
79
+
80
+ Persist the returned `accessToken`, `userId`, and calculated expiry in encrypted
81
+ storage. The package does not implement a refresh-token flow. Once the access
82
+ token expires, call `signIn` again and replace the persisted credentials. Never
83
+ log or commit user credentials or access tokens.
84
+
85
+ ## Rate limits and errors
86
+
87
+ The shared
88
+ [rate-limit wrapper](https://github.com/Asherlc/dofek/blob/main/packages/provider-http/src/rate-limit.ts)
89
+ throws `ProviderRateLimitError` for `429` and
90
+ `ProviderServiceUnavailableError` for `502`, `503`, and `504`. Both expose
91
+ `providerId`, `statusCode`, `responseBody`, and `retryAfterSeconds`. The latter
92
+ follows the HTTP
93
+ [`Retry-After`](https://www.rfc-editor.org/rfc/rfc9110.html#name-retry-after)
94
+ header when the upstream response provides it. Other unsuccessful responses
95
+ throw a regular `Error` containing the response status and body.
96
+
97
+ If your application handles these error classes directly, declare
98
+ `@dofek/provider-http` as a direct dependency:
99
+
100
+ ```sh
101
+ npm install @dofek/provider-http
102
+ ```
103
+
104
+ ```ts
105
+ import {
106
+ ProviderRateLimitError,
107
+ ProviderServiceUnavailableError,
108
+ } from "@dofek/provider-http/rate-limit";
109
+
110
+ try {
111
+ await client.getTrends("UTC", "2026-07-01", "2026-07-07");
112
+ } catch (error) {
113
+ if (
114
+ error instanceof ProviderRateLimitError ||
115
+ error instanceof ProviderServiceUnavailableError
116
+ ) {
117
+ console.error(error.providerId, error.statusCode, error.retryAfterSeconds);
118
+ }
119
+ throw error;
120
+ }
121
+ ```
122
+
123
+ ## Parsing behavior
124
+
125
+ The parsers convert raw duration seconds to minutes. Daily metrics come from
126
+ the observed `sleepQualityScore` structure; `parseEightSleepTrendDay` derives
127
+ awake time from presence time minus sleep time, and
128
+ `parseEightSleepHeartRateSamples` reads samples nested under sessions.
129
+
130
+ ## Project
131
+
132
+ - [Source](https://github.com/Asherlc/dofek/tree/main/packages/eight-sleep)
133
+ - [Report an issue](https://github.com/Asherlc/dofek/issues)
134
+ - [Contribute a pull request](https://github.com/Asherlc/dofek/pulls)
135
+ - License: [MIT](./LICENSE)
@@ -0,0 +1,14 @@
1
+ import type { EightSleepTrendsResponse } from "./types.ts";
2
+ export declare const EIGHT_SLEEP_CLIENT_ID = "0894c7f33bb94800a03f1f4df13a4f38";
3
+ export declare const EIGHT_SLEEP_CLIENT_SECRET = "f0954a3ed5763ba3d06834c73731a32f15f168f47d4f164751275def86db0c76";
4
+ export declare class EightSleepClient {
5
+ #private;
6
+ constructor(accessToken: string, userId: string, fetchFn?: typeof globalThis.fetch);
7
+ getTrends(timezone: string, fromDate: string, toDate: string): Promise<EightSleepTrendsResponse>;
8
+ static signIn(email: string, password: string, fetchFn?: typeof globalThis.fetch): Promise<{
9
+ accessToken: string;
10
+ expiresIn: number;
11
+ userId: string;
12
+ }>;
13
+ }
14
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA0B,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAMnF,eAAO,MAAM,qBAAqB,qCAAqC,CAAC;AACxE,eAAO,MAAM,yBAAyB,qEAC8B,CAAC;AAErE,qBAAa,gBAAgB;;gBAMzB,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,OAAO,UAAU,CAAC,KAAwB;IA0B/C,SAAS,CACb,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,wBAAwB,CAAC;WAevB,MAAM,CACjB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,OAAO,UAAU,CAAC,KAAwB,GAClD,OAAO,CAAC;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CA0BvE"}
package/dist/client.js ADDED
@@ -0,0 +1,68 @@
1
+ import { createRateLimitAwareFetch } from "@dofek/provider-http/rate-limit";
2
+ const AUTH_API_BASE = "https://auth-api.8slp.net/v1";
3
+ const CLIENT_API_BASE = "https://client-api.8slp.net/v1";
4
+ // Hardcoded client credentials extracted from the Eight Sleep Android app
5
+ export const EIGHT_SLEEP_CLIENT_ID = "0894c7f33bb94800a03f1f4df13a4f38";
6
+ export const EIGHT_SLEEP_CLIENT_SECRET = "f0954a3ed5763ba3d06834c73731a32f15f168f47d4f164751275def86db0c76";
7
+ export class EightSleepClient {
8
+ #accessToken;
9
+ #userId;
10
+ #fetchFn;
11
+ constructor(accessToken, userId, fetchFn = globalThis.fetch) {
12
+ this.#accessToken = accessToken;
13
+ this.#userId = userId;
14
+ this.#fetchFn = createRateLimitAwareFetch(fetchFn, { providerId: "eight-sleep" });
15
+ }
16
+ async #get(baseUrl, path) {
17
+ const url = `${baseUrl}${path}`;
18
+ const response = await this.#fetchFn(url, {
19
+ headers: {
20
+ Authorization: `Bearer ${this.#accessToken}`,
21
+ "Content-Type": "application/json",
22
+ "User-Agent": "okhttp/4.9.3",
23
+ Accept: "application/json",
24
+ },
25
+ });
26
+ if (!response.ok) {
27
+ const text = await response.text();
28
+ throw new Error(`Eight Sleep API error (${response.status}): ${text}`);
29
+ }
30
+ return response.json();
31
+ }
32
+ async getTrends(timezone, fromDate, toDate) {
33
+ const params = new URLSearchParams({
34
+ tz: timezone,
35
+ from: fromDate,
36
+ to: toDate,
37
+ "include-main": "false",
38
+ "include-all-sessions": "true",
39
+ "model-version": "v2",
40
+ });
41
+ return this.#get(CLIENT_API_BASE, `/users/${this.#userId}/trends?${params}`);
42
+ }
43
+ static async signIn(email, password, fetchFn = globalThis.fetch) {
44
+ const rateLimitFetchFn = createRateLimitAwareFetch(fetchFn, { providerId: "eight-sleep" });
45
+ const response = await rateLimitFetchFn(`${AUTH_API_BASE}/tokens`, {
46
+ method: "POST",
47
+ headers: { "Content-Type": "application/json" },
48
+ body: JSON.stringify({
49
+ client_id: EIGHT_SLEEP_CLIENT_ID,
50
+ client_secret: EIGHT_SLEEP_CLIENT_SECRET,
51
+ grant_type: "password",
52
+ username: email,
53
+ password,
54
+ }),
55
+ });
56
+ if (!response.ok) {
57
+ const text = await response.text();
58
+ throw new Error(`Eight Sleep sign-in failed (${response.status}): ${text}`);
59
+ }
60
+ const data = await response.json();
61
+ return {
62
+ accessToken: data.access_token,
63
+ expiresIn: data.expires_in,
64
+ userId: data.userId,
65
+ };
66
+ }
67
+ }
68
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAG5E,MAAM,aAAa,GAAG,8BAA8B,CAAC;AACrD,MAAM,eAAe,GAAG,gCAAgC,CAAC;AAEzD,0EAA0E;AAC1E,MAAM,CAAC,MAAM,qBAAqB,GAAG,kCAAkC,CAAC;AACxE,MAAM,CAAC,MAAM,yBAAyB,GACpC,kEAAkE,CAAC;AAErE,MAAM,OAAO,gBAAgB;IAC3B,YAAY,CAAS;IACrB,OAAO,CAAS;IAChB,QAAQ,CAA0B;IAElC,YACE,WAAmB,EACnB,MAAc,EACd,UAAmC,UAAU,CAAC,KAAK;QAEnD,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,QAAQ,GAAG,yBAAyB,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC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gBAAgB,CAAC,GAAG,aAAa,SAAS,EAAE;YACjE,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,SAAS,EAAE,qBAAqB;gBAChC,aAAa,EAAE,yBAAyB;gBACxC,UAAU,EAAE,UAAU;gBACtB,QAAQ,EAAE,KAAK;gBACf,QAAQ;aACT,CAAC;SACH,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,+BAA+B,QAAQ,CAAC,MAAM,MAAM,IAAI,EAAE,CAAC,CAAC;QAC9E,CAAC;QAED,MAAM,IAAI,GAA2B,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAC3D,OAAO;YACL,WAAW,EAAE,IAAI,CAAC,YAAY;YAC9B,SAAS,EAAE,IAAI,CAAC,UAAU;YAC1B,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,28 @@
1
+ import type { EightSleepSession, EightSleepTrendDay } from "./types.ts";
2
+ export interface ParsedEightSleepSession {
3
+ externalId: string;
4
+ startedAt: Date;
5
+ endedAt: Date;
6
+ durationMinutes: number;
7
+ deepMinutes: number;
8
+ remMinutes: number;
9
+ lightMinutes: number;
10
+ awakeMinutes: number;
11
+ sleepType: null;
12
+ isNap: boolean;
13
+ }
14
+ export interface ParsedEightSleepDailyMetrics {
15
+ date: string;
16
+ restingHr?: number;
17
+ hrv?: number;
18
+ respiratoryRateAvg?: number;
19
+ skinTempC?: number;
20
+ }
21
+ export interface ParsedEightSleepHrSample {
22
+ recordedAt: Date;
23
+ heartRate: number;
24
+ }
25
+ export declare function parseEightSleepTrendDay(day: EightSleepTrendDay): ParsedEightSleepSession;
26
+ export declare function parseEightSleepDailyMetrics(day: EightSleepTrendDay): ParsedEightSleepDailyMetrics;
27
+ export declare function parseEightSleepHeartRateSamples(sessions: EightSleepSession[]): ParsedEightSleepHrSample[];
28
+ //# sourceMappingURL=parsing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parsing.d.ts","sourceRoot":"","sources":["../src/parsing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAExE,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,EAAE,IAAI,CAAC;IACd,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,IAAI,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,4BAA4B;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,wBAAwB;IACvC,UAAU,EAAE,IAAI,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAMD,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,kBAAkB,GAAG,uBAAuB,CAaxF;AAED,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,kBAAkB,GAAG,4BAA4B,CASjG;AAED,wBAAgB,+BAA+B,CAC7C,QAAQ,EAAE,iBAAiB,EAAE,GAC5B,wBAAwB,EAAE,CAY5B"}
@@ -0,0 +1,42 @@
1
+ function secondsToMinutes(seconds) {
2
+ return Math.round(seconds / 60);
3
+ }
4
+ export function parseEightSleepTrendDay(day) {
5
+ return {
6
+ externalId: `eightsleep-${day.day}`,
7
+ startedAt: new Date(day.presenceStart),
8
+ endedAt: new Date(day.presenceEnd),
9
+ durationMinutes: secondsToMinutes(day.sleepDuration),
10
+ deepMinutes: secondsToMinutes(day.deepDuration),
11
+ remMinutes: secondsToMinutes(day.remDuration),
12
+ lightMinutes: secondsToMinutes(day.lightDuration),
13
+ awakeMinutes: secondsToMinutes(day.presenceDuration - day.sleepDuration),
14
+ sleepType: null,
15
+ isNap: false,
16
+ };
17
+ }
18
+ export function parseEightSleepDailyMetrics(day) {
19
+ const quality = day.sleepQualityScore;
20
+ return {
21
+ date: day.day,
22
+ restingHr: quality?.heartRate?.current,
23
+ hrv: quality?.hrv?.current,
24
+ respiratoryRateAvg: quality?.respiratoryRate?.current,
25
+ skinTempC: quality?.tempBedC?.average,
26
+ };
27
+ }
28
+ export function parseEightSleepHeartRateSamples(sessions) {
29
+ const samples = [];
30
+ for (const session of sessions) {
31
+ const hrSeries = session.timeseries?.heartRate;
32
+ if (!hrSeries)
33
+ continue;
34
+ for (const [timestamp, bpm] of hrSeries) {
35
+ if (bpm > 0) {
36
+ samples.push({ recordedAt: new Date(timestamp), heartRate: Math.round(bpm) });
37
+ }
38
+ }
39
+ }
40
+ return samples;
41
+ }
42
+ //# sourceMappingURL=parsing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parsing.js","sourceRoot":"","sources":["../src/parsing.ts"],"names":[],"mappings":"AA4BA,SAAS,gBAAgB,CAAC,OAAe;IACvC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,GAAuB;IAC7D,OAAO;QACL,UAAU,EAAE,cAAc,GAAG,CAAC,GAAG,EAAE;QACnC,SAAS,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC;QACtC,OAAO,EAAE,IAAI,IAAI,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C,GAAG,CAAC,EAAE,CAAC,CAAC;YAChF,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,83 @@
1
+ export interface EightSleepAuthResponse {
2
+ access_token: string;
3
+ expires_in: number;
4
+ userId: string;
5
+ }
6
+ export interface EightSleepSleepQualityScore {
7
+ total: number;
8
+ hrv?: {
9
+ score: number;
10
+ current: number;
11
+ average: number;
12
+ };
13
+ respiratoryRate?: {
14
+ score: number;
15
+ current: number;
16
+ average: number;
17
+ };
18
+ heartRate?: {
19
+ score: number;
20
+ current: number;
21
+ average: number;
22
+ };
23
+ tempBedC?: {
24
+ average: number;
25
+ };
26
+ tempRoomC?: {
27
+ average: number;
28
+ };
29
+ sleepDurationSeconds?: {
30
+ score: number;
31
+ };
32
+ }
33
+ export interface EightSleepSleepStage {
34
+ stage: string;
35
+ duration: number;
36
+ }
37
+ export interface EightSleepTimeseries {
38
+ heartRate?: Array<[string, number]>;
39
+ tempBedC?: Array<[string, number]>;
40
+ tempRoomC?: Array<[string, number]>;
41
+ respiratoryRate?: Array<[string, number]>;
42
+ hrv?: Array<[string, number]>;
43
+ }
44
+ export interface EightSleepSession {
45
+ stages: EightSleepSleepStage[];
46
+ timeseries: EightSleepTimeseries;
47
+ }
48
+ export interface EightSleepTrendDay {
49
+ day: string;
50
+ score: number;
51
+ tnt: number;
52
+ processing: boolean;
53
+ presenceDuration: number;
54
+ sleepDuration: number;
55
+ lightDuration: number;
56
+ deepDuration: number;
57
+ remDuration: number;
58
+ latencyAsleepSeconds: number;
59
+ latencyOutSeconds: number;
60
+ presenceStart: string;
61
+ presenceEnd: string;
62
+ sleepQualityScore?: EightSleepSleepQualityScore;
63
+ sleepRoutineScore?: {
64
+ total: number;
65
+ latencyAsleepSeconds?: {
66
+ score: number;
67
+ };
68
+ latencyOutSeconds?: {
69
+ score: number;
70
+ };
71
+ wakeupConsistency?: {
72
+ score: number;
73
+ };
74
+ };
75
+ sleepFitnessScore?: {
76
+ total: number;
77
+ };
78
+ sessions?: EightSleepSession[];
79
+ }
80
+ export interface EightSleepTrendsResponse {
81
+ days: EightSleepTrendDay[];
82
+ }
83
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,2BAA2B;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1D,eAAe,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IACtE,SAAS,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAChE,QAAQ,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/B,SAAS,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAChC,oBAAoB,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1C;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,oBAAoB;IACnC,SAAS,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACpC,QAAQ,CAAC,EAAE,KAAK,CAAC,CAAC,M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;CAChC;AAED,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,kBAAkB,EAAE,CAAC;CAC5B"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@dofek/eight-sleep",
3
+ "version": "0.1.0",
4
+ "description": "Unofficial Eight Sleep API client using reverse-engineered authentication",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/Asherlc/dofek.git",
10
+ "directory": "packages/eight-sleep"
11
+ },
12
+ "homepage": "https://github.com/Asherlc/dofek/tree/main/packages/eight-sleep#readme",
13
+ "bugs": "https://github.com/Asherlc/dofek/issues",
14
+ "keywords": [
15
+ "eight-sleep",
16
+ "sleep",
17
+ "api-client",
18
+ "unofficial",
19
+ "typescript"
20
+ ],
21
+ "engines": {
22
+ "node": ">=22.14.0"
23
+ },
24
+ "sideEffects": false,
25
+ "files": [
26
+ "dist",
27
+ "README.md",
28
+ "LICENSE"
29
+ ],
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/client.d.ts",
33
+ "import": "./dist/client.js"
34
+ },
35
+ "./*": {
36
+ "types": "./dist/*.d.ts",
37
+ "import": "./dist/*.js"
38
+ }
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "scripts": {
44
+ "test": "vitest run",
45
+ "test:watch": "vitest --watch",
46
+ "build": "tsc",
47
+ "prepack": "pnpm run build",
48
+ "lint": "biome check .",
49
+ "typecheck": "tsc --noEmit"
50
+ },
51
+ "dependencies": {
52
+ "@dofek/provider-http": "0.1.0"
53
+ },
54
+ "devDependencies": {
55
+ "typescript": "6.0.3",
56
+ "vitest": "3.2.6"
57
+ },
58
+ "gitHead": "ac95258c753c7e75b57da7ae47426d22b78e8c01"
59
+ }