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

@tuyapi/cloud

v0.6.2

Published

A NodeJS wrapper for Tuya's cloud API

Downloads

1,218

Readme

tuyapi/cloud Build Status Coverage Status XO code style

A NodeJS wrapper for Tuya's API.

At the moment, only the mobile/app API (as captured by web.archive.org) is supported as it covers the vast majority of use cases.

There are two modes of operation:

  • the 'old' API - described in the docs, using MD5 as a sign mechanism
  • the 'new' API - reverse-engineered from the TuyaSmart Android app, using HMAC-SHA256 as a sign mechanism

If you can, use the old API. Unfortunately, for some clientId/key's you must use the new API (eg. clientId used by TuyaSmart app). To use the the new API, specify apiEtVersion as an option in constructor (currently '0.0.1').

Step-by-step instructions for acquiring keys to use with the old API can be found here.

Obtaining keys for new API (additional parameters secret2 and certSign are required) involves disassembling obtained an APK file (either official app or generated "demo" app from iot.tuya.com). For details see tuya-sign-hacking repo.

Installation

npm i @tuyapi/cloud

Usage

old API (register/login and create token):

const Cloud = require('@tuyapi/cloud');

let api = new Cloud({key: 'your-api-app-key', secret: 'your-api-app-secret'});

api.register({email: '[email protected]', password: 'example-password'}).then(async sid => {
  let token = await api.request({action: 'tuya.m.device.token.create', data: {'timeZone': '-05:00'}});

  console.log(token) // => { secret: '0000', token: '01010101' }
});

new API (listing all devices in all groups):

const Cloud = require('@tuyapi/cloud');

let api = new Cloud({key: apiKeys.key,
                     secret: apiKeys.secret,
                     secret2: apiKeys.secret2,
                     certSign: apiKeys.certSign,
                     apiEtVersion: '0.0.1',
                     region: 'EU'});

api.loginEx({email: myEmail, password: myPassword}).then(async sid => {
  console.log(sid);

  api.request({action: 'tuya.m.location.list'}).then(async groups => {
    for (const group of groups) {
      api.request({action: 'tuya.m.my.group.device.list', gid: group.groupId}).then(async devicesArr => {
        for (const device of devicesArr) {
           console.log('group: "%s"\tdevice: "%s"\tdevId: "%s"', group.name, device.name, device.devId);
        }
      });
    }
  });
});

Documentation

Development

  1. After cloning, run npm i.
  2. Add a file called keys.json with the contents
{
  "key": "your-api-key",
  "secret": "your-api-secret"
  // for new API: add also secret2 and certSign
}
  1. Create a file called dev.js as a playground. Since dev.js is in .gitignore, it won't be committed.
  2. To run tests, run npm test.
  3. To output coverage, run npm run cover (it will exit with an error).
  4. To build documentation, run npm run document.

forthebadge