npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eightsleep

v1.5.3

Published

eightsleep api client

Downloads

19

Readme

eightsleep

Eightsleep api client for Node.js

Installation

npm i --save eightsleep

Usage

Supports both ESM and CommonJS

// esm
import Eightsleep from 'eightsleep'
// commonjs
const Eightsleep = require('eightsleep')

Login Example

import Eightsleep from 'eightsleep'

const eightsleep = new Eightsleep()

const session = await eightsleep.login()
/*
{
  "expirationDate": 2020-06-30T05:40:30.880Z,
  "token": "1234567890abcdef1234567890abcdef-1234567890abcdef1234567890abcdef",
  "userId": "1234567890abcdef123456789011111",
}
*/

Get Me and Get User Example

import Eightsleep from 'eightsleep'

const eightsleep = new Eightsleep()
await eightsleep.login()

const me = await eightsleep.getMe()
/*
{
  "currentDevice": {
    "id": "123456789012345678901234",
    "side": "left",
  },
  "devices": [
    "123456789012345678901234",
  ],
  "dob": 1900-04-01T08:34:30.000Z,
  "email": "[email protected]",
  "emailVerified": true,
  "features": [
    "warming",
    "cooling",
  ],
  "firstName": "Owner",
  "gender": "male",
  "lastName": "Person",
  "notifications": {
    "sessionProcessed": true,
    "weeklyReportEmail": true,
  },
  "sharingMetricsFrom": [
    "1234567890abcdef123456789022222",
  ],
  "sharingMetricsTo": [
    "1234567890abcdef123456789022222",
  ],
  "timezone": "America/Los_Angeles",
  "userId": "1234567890abcdef123456789011111",
  "zip": 11111,
}
*/
const user = await eightsleep.getUser('1234567890abcdef123456789022222')
/*
{
  "currentDevice": {
    "id": "123456789012345678901234",
    "side": "right",
  },
  "devices": [
    "123456789012345678901234",
  ],
  "dob": 1900-10-26T08:34:30.000Z,
  "email": "[email protected]",
  "emailVerified": true,
  "features": [
    "warming",
    "cooling",
  ],
  "firstName": "Partner",
  "gender": "female",
  "lastName": "Person",
  "notifications": {
    "sessionProcessed": true,
    "weeklyReportEmail": true,
  },
  "sharingMetricsFrom": [
    "1234567890abcdef123456789011111",
  ],
  "sharingMetricsTo": [
    "1234567890abcdef123456789011111",
  ],
  "timezone": "America/Los_Angeles",
  "userId": "1234567890abcdef123456789022222",
  "zip": 11111,
}
*/

Update Me Example

import Eightsleep from 'eightsleep'

const eightsleep = new Eightsleep()
await eightsleep.login()

const me = await eightsleep.updateMe({ zip: 94401 })
/*
{
  "currentDevice": {
    "id": "123456789012345678901234",
    "side": "left",
  },
  "devices": [
    "123456789012345678901234",
  ],
  "dob": 1900-04-01T08:34:30.000Z,
  "email": "[email protected]",
  "emailVerified": true,
  "features": [
    "warming",
    "cooling",
  ],
  "firstName": "Owner",
  "gender": "male",
  "lastName": "Person",
  "notifications": {
    "sessionProcessed": true,
    "weeklyReportEmail": true,
  },
  "sharingMetricsFrom": [
    "1234567890abcdef123456789022222",
  ],
  "sharingMetricsTo": [
    "1234567890abcdef123456789022222",
  ],
  "timezone": "America/Los_Angeles",
  "userId": "1234567890abcdef123456789011111",
  "zip": 94401,
}
*/

Get Device Example

import Eightsleep from 'eightsleep'

const eightsleep = new Eightsleep()
await eightsleep.login()

const me = await eightsleep.getMe()
const deviceId = me.currentDevice.id

const device = await eightsleep.getDevice(deviceId)
/*
{
  "deviceId": "123456789012345678901234",
  "features": [
    "warming",
    "cooling",
  ],
  "firmwareUpdated": true,
  "firmwareUpdating": false,
  "firmwareVersion": "2.3.18.0",
  "hasWater": true,
  "hubInfo": "12345-0001-A01-AABBCCDD",
  "lastHeard": "2020-06-21T03:36:57.441Z",
  "lastLowWater": "2020-03-04T21:10:38.334Z",
  "lastPrime": "2020-03-04T21:11:23.746Z",
  "ledBrightnessLevel": 30,
  "leftHeatingDuration": 0,
  "leftHeatingLevel": -15,
  "leftKelvin": {
    "active": false,
    "alarms": [],
    "currentActivity": "off",
    "currentTargetLevel": 0,
    "level": 0,
    "scheduleProfiles": [
      {
        "enabled": true,
        "startLocalTime": "22:00:00",
        "weekDays": {
          "friday": true,
          "monday": true,
          "saturday": true,
          "sunday": true,
          "thursday": true,
          "tuesday": true,
          "wednesday": true,
        },
      },
    ],
    "targetLevels": [
      -10,
      -10,
      -20,
    ],
  },
  "leftNowHeating": false,
  "leftSchedule": {
    "daysUTC": {
      "friday": false,
      "monday": false,
      "saturday": false,
      "sunday": false,
      "thursday": false,
      "tuesday": false,
      "wednesday": false,
    },
    "durationSeconds": 0,
    "enabled": false,
    "startUTCHour": 0,
    "startUTCMinute": 0,
  },
  "leftTargetHeatingLevel": 0,
  "leftUserId": "1234567890abcdef123456789011111",
  "location": [
    -122.32171311,
    37.55987324,
  ],
  "mattressInfo": {
    "brand": null,
    "eightMattress": null,
    "firstUsedDate": null,
  },
  "needsPriming": false,
  "online": true,
  "ownerId": "1234567890abcdef123456789011111",
  "priming": false,
  "rightHeatingDuration": 3575,
  "rightHeatingLevel": 21,
  "rightKelvin": {
    "active": true,
    "alarms": [],
    "currentActivity": "schedule",
    "currentTargetLevel": 50,
    "level": 50,
    "phases": [
      {
        "active": false,
        "operation": "on",
        "position": 0,
      },
      {
        "active": true,
        "level": 50,
        "operation": "temperature",
        "position": 0,
      },
      {
        "active": false,
        "level": 10,
        "operation": "temperature",
        "position": 0.33,
      },
      {
        "active": false,
        "level": 30,
        "operation": "temperature",
        "position": 0.67,
      },
      {
        "active": false,
        "operation": "off",
        "position": 1,
      },
    ],
    "scheduleProfiles": [
      {
        "enabled": true,
        "startLocalTime": "21:30:00",
        "weekDays": {
          "friday": true,
          "monday": true,
          "saturday": true,
          "sunday": true,
          "thursday": true,
          "tuesday": true,
          "wednesday": true,
        },
      },
    ],
    "targetLevels": [
      50,
      10,
      30,
    ],
  },
  "rightNowHeating": true,
  "rightSchedule": {
    "daysUTC": {
      "friday": false,
      "monday": false,
      "saturday": false,
      "sunday": false,
      "thursday": false,
      "tuesday": false,
      "wednesday": false,
    },
    "durationSeconds": 0,
    "enabled": false,
    "startUTCHour": 0,
    "startUTCMinute": 0,
  },
  "rightTargetHeatingLevel": 50,
  "rightUserId": "1234567890abcdef123456789022222",
  "sensorInfo": {
    "connected": true,
    "hwRevision": "A01",
    "label": "12345-0001-A01-00000000",
    "lastConnected": "2020-06-21T03:36:57.441Z",
    "partNumber": "12345",
    "serialNumber": "00000000",
    "sku": "0001",
    "skuName": "queen",
  },
  "timezone": "America/Los_Angeles",
}
*/

Turn Device Side On/Off

import Eightsleep, { Sides } from 'eightsleep'

const eightsleep = new Eightsleep()
const appApiClient = eightsleep.getAppApiClient()

const me = await eightsleep.getMe()
const deviceId = me.currentDevice.id

let status
status = await appApiClient.setDeviceSideOn(deviceId, Sides.LEFT)
/*
{
  "left": {
    "currentActivity": "schedule",
    "currentLevel": -31,
    "currentTargetLevel": 10,
    "smartTemperature": {
      "bedLocalTime": "00:00:00",
      "bedTimeLevel": 10,
      "currentPhase": "bedtime",
      "finalSleepLevel": -10,
      "initialSleepLevel": -10,
    },
    "version": 2,
  },
  "right": {
    "currentActivity": "off",
    "currentLevel": -33,
    "currentTargetLevel": 0,
    "version": 2,
  },
}
*/
status = await appApiClient.setDeviceSideOff(deviceId, Sides.LEFT)
/*
{
  "left": {
    "currentActivity": "off",
    "currentLevel": -33,
    "currentTargetLevel": 0,
    "version": 2,
  },
  "right": {
    "currentActivity": "off",
    "currentLevel": -33,
    "currentTargetLevel": 0,
    "version": 2,
  },
}
*/

Set Device Side Level

import Eightsleep, { Sides } from 'eightsleep'

const eightsleep = new Eightsleep()
const appApiClient = eightsleep.getAppApiClient()

const me = await eightsleep.getMe()
const deviceId = me.currentDevice.id

let status
await appApiClient.setDeviceSideOff(deviceId, Sides.LEFT)
/*
{
  "left": {
    "currentActivity": "off",
    "currentLevel": -33,
    "currentTargetLevel": 0,
    "version": 2,
  },
  "right": {
    "currentActivity": "off",
    "currentLevel": -33,
    "currentTargetLevel": 0,
    "version": 2,
  },
}
*/
await appApiClient.setDeviceSideOn(deviceId, Sides.LEFT)
const status = await appApi.setDeviceSideLevel(
  '123456789012345678901234',
  Sides.LEFT,
  30,
)
/*
{
  "left": {
    "currentActivity": "schedule",
    "currentLevel": -31,
    "currentTargetLevel": 30,
    "smartTemperature": {
      "bedLocalTime": "00:00:00",
      "bedTimeLevel": 10,
      "currentPhase": "bedtime",
      "finalSleepLevel": -10,
      "initialSleepLevel": -10,
    },
    "version": 2,
  },
  "right": {
    "currentActivity": "off",
    "currentLevel": -33,
    "currentTargetLevel": 0,
    "version": 2,
  },
}
*/

License

MIT