{"id":19858231,"url":"https://github.com/tuya/tuya-connector-nodejs","last_synced_at":"2025-05-02T02:30:50.103Z","repository":{"id":41220718,"uuid":"377399085","full_name":"tuya/tuya-connector-nodejs","owner":"tuya","description":"nodejs sdk","archived":false,"fork":false,"pushed_at":"2022-04-20T16:46:03.000Z","size":182,"stargazers_count":44,"open_issues_count":12,"forks_count":19,"subscribers_count":15,"default_branch":"main","last_synced_at":"2025-05-01T04:46:59.037Z","etag":null,"topics":["tuya"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tuya.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-16T06:49:10.000Z","updated_at":"2025-04-09T16:23:28.000Z","dependencies_parsed_at":"2022-09-15T18:30:40.337Z","dependency_job_id":null,"html_url":"https://github.com/tuya/tuya-connector-nodejs","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuya%2Ftuya-connector-nodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuya%2Ftuya-connector-nodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuya%2Ftuya-connector-nodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuya%2Ftuya-connector-nodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tuya","download_url":"https://codeload.github.com/tuya/tuya-connector-nodejs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251972441,"owners_count":21673604,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["tuya"],"created_at":"2024-11-12T14:22:13.953Z","updated_at":"2025-05-02T02:30:48.508Z","avatar_url":"https://github.com/tuya.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[English](README.md) | [中文版](README_CN.md)\n\n### What is `tuya-connector`?\n\n[Tuya Open Platform—API Reference](https://developer.tuya.com/en/docs/iot/api-reference?id=Ka7qb7vhber64)\n\nTuya provides a set of HTTP APIs and signature verification logic. You need to implement the logic when you make the API requests.\n\n`tuya-connector` provides capabilities to sign a request, refresh, store, and renew a token, and encapsulate common APIs, helping you quickly connect to Tuya's open platform.\n\n### Install\n\n```bash\nnpm install @tuya/tuya-connector-nodejs\n\n# or\nyarn add @tuya/tuya-connector-nodejs\n```\n\n### Get started\n\n```ts\nimport { TuyaContext  } from '@tuya/tuya-connector-nodejs';\n\nconst tuya = new TuyaContext({\n  baseUrl: 'https://openapi.tuyacn.com',\n  accessKey: 'xx',\n  secretKey: 'xx',\n});\n\nconst device = await tuya.device.detail({\n  device_id: 'device_id'\n});\n\n```\n\n## Advanced development\n\n### Custom `tokenStore`\n\nBy default, `tokenStore` is implemented based on memory. We recommend that you implement the store instance in your service. In the following code block, the Redis Store is used as an example.\n\n```ts\n// tokenStore.ts\nimport { TuyaTokenStorInterface, TuyaTokensSave } from '@tuya/tuya-connector-nodejs';\nimport IORedis from 'ioredis';\n\nexport class RedisTokenStore implements TuyaTokenStorInterface {\n  private readonly client: IORedis.Redis;\n  private readonly key: string;\n  constructor(client: IORedis.Redis, key: string = 'tuya::token') {\n    this.client = client;\n    this.key = key;\n  }\n\n  async setTokens(tokens: TuyaTokensSave): Promise\u003cboolean\u003e {\n    const res = await this.client.set(this.key, JSON.stringify(tokens));\n    return ! ! res;\n  }\n  async getAccessToken(): Promise\u003cstring | undefined\u003e {\n    const jsonStr = await this.client.get(this.key) || '{}';\n    const tokens: TuyaTokensSave = JSON.parse(jsonStr);\n    return tokens \u0026\u0026 tokens.access_token;\n  }\n  async getRefreshToken(): Promise\u003cstring | undefined\u003e {\n    const jsonStr = await this.client.get(this.key) || '{}';\n    const tokens: TuyaTokensSave = JSON.parse(jsonStr);\n    return tokens.refresh_token;\n  }\n}\n\n// index.ts\nimport { RedisTokenStore } from './tokenStore';\nimport IoRedis from 'ioredis';\nconst redis = new IoRedis();\n\nconst tuya = new TuyaContext({\n  baseUrl: 'https://openapi.tuyacn.com',\n  accessKey: 'xx',\n  secretKey: 'xx',\n  store: new RedisTokenStore(redis),\n});\n```\n\n### Custom request of `httpClient`\n\n`tuya-connector` uses Axios as `httpClient` by default, and exposes replaceable parameters. If necessary, you can also customize `httpClient`.\n\n```ts\nimport axios from 'axios';\nimport { TuyaContext  } from '@tuya/tuya-connector-nodejs';\n\nconst tuya = new TuyaContext({\n  baseUrl: 'https://openapi.tuyacn.com',\n  accessKey: 'xx',\n  secretKey: 'xx',\n  rpc: axios\n});\n```\n\n### Requests of other OpenAPIs\n\n`tuya-connector` encapsulates common APIs, and declares the types of request and response parameters. You can customize additional API requests.\n\n```ts\nimport { TuyaContext  } from '@tuya/tuya-connector-nodejs';\n\nconst tuya = new TuyaContext({\n  baseUrl: 'https://openapi.tuyacn.com',\n  accessKey: 'xx',\n  secretKey: 'xx',\n});\n\nconst { data } = await tuya.request({\n  method: 'GET',\n  path: '/v1.0/xx',\n  body: {},\n});\n```\n\n### Other issues\n\n1. Apply for an authorization key. On the [platform](https://iot.tuya.com/cloud/), you can create a project to get the access ID and access secret of the cloud application.\n\n2. For more information about global error codes, see [Global Error Codes](https://developer.tuya.com/en/docs/iot/error-code?id=K989ruxx88swc).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftuya%2Ftuya-connector-nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftuya%2Ftuya-connector-nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftuya%2Ftuya-connector-nodejs/lists"}