Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tuyapi/link

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tuyapi/link - npm Package Compare versions

Comparing version 0.3.3 to 0.3.4

73

index.js

@@ -1,2 +0,3 @@

const Cloud = require('@tuyapi/openapi');
const {TuyaContext} = require('@tuya/tuya-connector-nodejs');
const delay = require('delay');
const debug = require('debug')('@tuyapi/link:wizard');

@@ -6,3 +7,3 @@ const TuyaLink = require('./lib/link.js');

/**
* A wrapper that combines `@tuyapi/openapi` and
* A wrapper that combines `@tuya/tuya-connector-nodejs` and
* `(@tuyapi/link).manual` (included in this package)

@@ -38,5 +39,8 @@ * to make registration Just Work™️. Exported as

// Don't need to check key and secret for correct format as
// tuyapi/openapi already does
this.api = new Cloud({key: apiKey, secret: apiSecret, region, schema});
this.api = new TuyaContext({
baseUrl: `https://openapi.tuya${region}.com`,
accessKey: apiKey,
secretKey: apiSecret
});
this.schema = schema;

@@ -55,5 +59,20 @@ // Construct instance of TuyaLink

// Register/login user
await this.api.getToken();
const result = await this.api.request({
path: `/v1.0/apps/${this.schema}/user`,
method: 'POST',
body: {
schema: this.schema,
country_code: '1',
username: this.email,
password: this.password,
username_type: 2,
nick_name: this.email
}
});
this.uid = await this.api.putUser({countryCode: '1', username: this.email, password: this.password, usernameType: 2});
if (!result.success) {
throw new Error(result.msg);
}
this.uid = result.result.uid;
}

@@ -65,3 +84,3 @@

* options
* @param {Number} [options.timeout=60]
* @param {Number} [options.timeout=100]
* how long we should wait for devices to

@@ -83,3 +102,3 @@ * connect before throwing an error, in seconds

*/
async linkDevice({timeout = 60, ssid, wifiPassword = '', devices = 1} = {}) {
async linkDevice({timeout = 100, ssid, wifiPassword = '', devices = 1} = {}) {
if (!ssid) {

@@ -90,4 +109,18 @@ throw new Error('SSID must be provided');

try {
const token = await this.api.getDeviceToken({uid: this.uid, timezone: this.timezone});
const response = await this.api.request({
path: '/v1.0/device/paring/token',
method: 'POST',
body: {
uid: this.uid,
timeZoneId: this.timezone,
paring_type: 'EZ'
}
});
if (!response.success) {
throw new Error(response.msg);
}
const token = response.result;
debug('Token: ', token);

@@ -111,7 +144,16 @@

// eslint-disable-next-line no-await-in-loop
lastAPIResponse = await this.api.getDevicesByToken(token.token);
lastAPIResponse = await this.api.request({
path: `/v1.0/device/paring/tokens/${token.token}`,
method: 'GET'
});
debug(`${lastAPIResponse.successDevices.length} devices returned by API.`);
if (!lastAPIResponse.success) {
throw new Error(lastAPIResponse.msg);
}
if (lastAPIResponse.successDevices.length >= devices) {
const {result} = lastAPIResponse;
debug(`${result.success.length} devices returned by API.`);
if (result.success.length >= devices) {
waitingForDevices = false;

@@ -126,5 +168,8 @@ }

}
// eslint-disable-next-line no-await-in-loop
await delay(1000);
}
const returnedDevices = lastAPIResponse.successDevices;
const returnedDevices = lastAPIResponse.result.success;

@@ -131,0 +176,0 @@ debug('Found device(s)!', returnedDevices);

5

package.json
{
"name": "@tuyapi/link",
"version": "0.3.3",
"version": "0.3.4",
"description": "📡 Effortlessly connect devices to WiFi and the cloud",

@@ -23,2 +23,3 @@ "main": "index.js",

"rules": {
"camelcase": "off",
"indent": [

@@ -53,3 +54,3 @@ "error",

"dependencies": {
"@tuyapi/openapi": "^0.2.0",
"@tuya/tuya-connector-nodejs": "^2.0.3",
"debug": "^4.1.1",

@@ -56,0 +57,0 @@ "delay": "^4.3.0"

@@ -6,3 +6,3 @@ tuyapi/link [![Build Status](https://travis-ci.org/TuyaAPI/link.svg?branch=master)](https://travis-ci.org/TuyaAPI/link) [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/xojs/xo)

- **`(@tuyapi/link).manual`**: a low-level interface for linking devices.
- **`(@tuyapi/link).wizard`**: a wrapper that combines `(@tuyapi/link).manual` and `@tuyapi/cloud`, making it super easy to link devices. It Just Works™️.
- **`(@tuyapi/link).wizard`**: a wrapper that combines `(@tuyapi/link).manual` and `@tuya/tuya-connector-nodejs`, making it super easy to link devices. It Just Works™️.

@@ -9,0 +9,0 @@ ## Installation

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc