{"_id":"@afreidz/tuya-cloud-api","_rev":"1-233ba2dfed4686d9640ff6144f2af7ec","name":"@afreidz/tuya-cloud-api","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.1":{"name":"@afreidz/tuya-cloud-api","version":"1.0.1","description":"A nodejs implementation of tuya cloud api: https://docs.tuya.com/en/iot/open-api/api-list/api/api","keywords":["tuya","tuya cloud"],"author":{"name":"afreidz","email":"afreidenfelds@gmail.com"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/afreidz/tuya-cloud-api.git"},"main":"dist/index.js","types":"dist/index.d.ts","engines":{"node":">=10.0.0"},"scripts":{"prepublish":"yarn ci:check && yarn build","postversion":"git push origin HEAD --no-verify --tags","build":"rm -fr ./dist && tsc -d --declaration --noEmit false --outDir ./dist","test":"jest","lint":"eslint --fix .","lint:check":"eslint --quiet .","prettier":"prettier --write .","prettier:check":"prettier --check .","ts:check":"tsc","ci:check":"yarn lint:check && yarn ts:check && yarn test"},"husky":{"hooks":{"pre-commit":"lint-staged","pre-push":"yarn ci:check"}},"lint-staged":{"*.{json,md}":["prettier --write"],"*.{js,ts}":["eslint --fix"]},"jest":{"testEnvironment":"node","resetMocks":true,"restoreMocks":true,"testMatch":["**/?(*.)+(spec|test).[jt]s?(x)"],"watchPlugins":["jest-watch-typeahead/filename","jest-watch-typeahead/testname"]},"dependencies":{"got":"^11.3.0"},"devDependencies":{"@babel/core":"^7.10.3","@babel/node":"^7.10.3","@babel/preset-env":"^7.10.3","@babel/preset-typescript":"^7.10.1","@types/jest":"^26.0.3","@types/node":"^14.0.14","@typescript-eslint/eslint-plugin":"^3.4.0","@typescript-eslint/parser":"^3.4.0","eslint":"^7.3.1","eslint-config-prettier":"^6.11.0","eslint-plugin-import":"^2.21.2","eslint-plugin-prettier":"^3.1.4","husky":"^4.2.5","jest":"^26.1.0","jest-watch-typeahead":"^0.6.0","lint-staged":"^10.2.11","prettier":"^2.0.5","typescript":"^3.9.5"},"bugs":{"url":"https://github.com/afreidz/tuya-cloud-api/issues"},"homepage":"https://github.com/afreidz/tuya-cloud-api#readme","gitHead":"d67a6d5b894e2bb3e0cef125a63c086f6fd68896","_id":"@afreidz/tuya-cloud-api@1.0.1","_nodeVersion":"14.10.1","_npmVersion":"6.14.7","dist":{"integrity":"sha512-TEvqTgwpIXiD9m8DSX7EKri43jEs9NacOV+EiBd0alipHULEGCKUeCD0EOYgI3l7TgLeLc96iSoxnlnk+/NYhg==","shasum":"e543f2f480335da11ee6086bd6da4ec995028c79","tarball":"https://registry.npmjs.org/@afreidz/tuya-cloud-api/-/tuya-cloud-api-1.0.1.tgz","fileCount":10,"unpackedSize":14393,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfdiQWCRA9TVsSAnZWagAAzrkP/0FKcor805G1HV9kYVlw\nSLWf4xRiH3eUoNK4FJlT0L6kyY3Ar/+pdlSdPcuqP6Eoh294eT2pGpJtWJoH\nO1qA6JsOeixzFvkRKECo8cKaE0Wy4n7Ny2tcAdOrRq+RllPkGeMfj+or8Rdi\n70zynVFPKl9WolzTjO3s0rMleDX8o0ZmeKLbEPR4KaoRl8OVbaRjVXn2oBko\ne1idFV4qYCwj0LvbnAXaxZOIsQEQhWEEGLZkGgH4gqoa0qjOViTC99cl9WQ5\n6Pn6nxhzidNThBjp2xRojasp6Xnvd2YAEbZ7zPfviw7kdFoSJkyCLhN6borC\nesBSr0de02dZRUU5THC2HmPHOYEYL9m07/jrpn+T4KSCmx1Yrffns9edhG6n\nJZCFcy+Oma1VCq9cYjJ3WsIsMj+PPP8gGZj+ory6E1pmc9yk8kk/BBRW1AtF\nfQi/Qk1EXD7jqj0dI+qUpMWkNmad3p+NMarYbRs1wqIeu2855IbnWF4jAfmI\nkDZ3u8ArrWPrkL7pBMlW1rxdM0bLLrS5HdML2m+DQ/8nDpg7EAHuTqIqqWzl\nP8nmcv5FGAzB4tM5nCQGPCVowilQztDY/VaCp5bfAcqAFL2yiXYZmENqLlxL\nuCCeZkrd1JPdiK3aabwa+4DR23PKHAzX1aWhp5JBGqX9HrNzUNVCOo2lec1S\nFpr+\r\n=s5n6\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCXQWU936pmAyGQ38YL58KNzBocqvXLgyF4VzwPxFpTswIhAOIscyjFCjfJtVlot3MbNY9b7iLiRA2y4DDmPmqoLTgK"}]},"maintainers":[{"name":"afreidz","email":"afreidenfelds@gmail.com"}],"_npmUser":{"name":"afreidz","email":"afreidenfelds@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/tuya-cloud-api_1.0.1_1601578006198_0.9632871041593347"},"_hasShrinkwrap":false}},"time":{"created":"2020-10-01T18:46:46.168Z","1.0.1":"2020-10-01T18:46:46.334Z","modified":"2022-04-04T11:51:19.134Z"},"maintainers":[{"name":"afreidz","email":"afreidenfelds@gmail.com"}],"description":"A nodejs implementation of tuya cloud api: https://docs.tuya.com/en/iot/open-api/api-list/api/api","homepage":"https://github.com/afreidz/tuya-cloud-api#readme","keywords":["tuya","tuya cloud"],"repository":{"type":"git","url":"git+https://github.com/afreidz/tuya-cloud-api.git"},"author":{"name":"afreidz","email":"afreidenfelds@gmail.com"},"bugs":{"url":"https://github.com/afreidz/tuya-cloud-api/issues"},"license":"MIT","readme":"A nodejs implementation of tuya cloud api:\nhttps://docs.tuya.com/en/iot/open-api/api-list/api/api\n\n## Installation\n\n```bash\nnpm install tuya-cloud-api\n```\n\nor\n\n```bash\nyarn add tuya-cloud-api\n```\n\n## Usage Example\n\nYou can read [this issue](https://github.com/codetheweb/tuyapi/issues/323) to\nfind out where to get `deviceId`.\n\nFollow\n[this instructions](https://github.com/codetheweb/tuyapi/blob/master/docs/SETUP.md#linking-a-tuya-device-with-smart-link)\nto get `apiClientId` and `apiClientSecret` values (`api-key` and `api-secret`\nfrom the linked doc).\n\n```js\nimport { tuyaApi } from 'tuya-cloud-api';\n\nconst apiClientId = '...';\nconst apiClientSecret = '...';\nconst deviceId = '...';\nconst code = 'switch_1';\n\nasync function toggleDevice(deviceId, state = false) {\n  await tuyaApi.authorize({\n    apiClientId,\n    apiClientSecret,\n  });\n\n  // get fresh device info\n  const deviceStatus = await tuyaApi.getDeviceStatus({\n    deviceId: this.deviceId,\n  });\n  const switchStatus = deviceStatus.find((item) => item.code === code);\n\n  if (!switchStatus) {\n    throw new Error(`Can not find status for command: ${code}`);\n  }\n\n  if (switchStatus.value === state) {\n    return;\n  }\n\n  await tuyaApi.sendCommand({\n    deviceId,\n    commands: [\n      {\n        code,\n        value: state,\n      },\n    ],\n  });\n}\n\n{\n  (async () => {\n    try {\n      await toggleDevice(deviceId, true);\n\n      console.log('Successfully toggled the device on!');\n      process.exit(0);\n    } catch (error) {\n      console.error('Error toggling device on', error);\n      process.exit(1);\n    }\n  })();\n}\n```\n","readmeFilename":"README.md"}