@lumiastream/tapo-cove 3.0.23 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## [3.1.1](https://github.com/lumiastream/rgb/compare/v3.1.0...v3.1.1) (2023-03-22)
7
+
8
+ ### Bug Fixes
9
+
10
+ - tapo bypass cookie ([39f5dec](https://github.com/lumiastream/rgb/commit/39f5dec51c403d7b99f662b75f4c32a76546e56a))
11
+
12
+ # [3.1.0](https://github.com/lumiastream/rgb/compare/v3.0.15...v3.1.0) (2023-03-21)
13
+
14
+ ### Bug Fixes
15
+
16
+ - tapo using promise.all instead of allsettled ([a6dc480](https://github.com/lumiastream/rgb/commit/a6dc480f86cc129535b6eac7bf1acdc5cdff06b6))
package/dist/index.d.ts CHANGED
@@ -96,7 +96,6 @@ declare class TapoApi {
96
96
  };
97
97
  state: LightState;
98
98
  fetchConfig?: {
99
- useAxios: boolean;
100
99
  shouldWait: boolean;
101
100
  };
102
101
  }) => Promise<any>;
@@ -105,10 +104,6 @@ declare class TapoApi {
105
104
  id: string;
106
105
  };
107
106
  power: boolean;
108
- fetchConfig?: {
109
- useAxios: boolean;
110
- shouldWait: boolean;
111
- };
112
107
  }) => void;
113
108
  }
114
109
 
package/dist/index.js CHANGED
@@ -163,6 +163,7 @@ var throwErrorIfFound = (responseData) => {
163
163
  }
164
164
  };
165
165
  var handshake = (deviceIp) => __async(void 0, null, function* () {
166
+ var _a, _b, _c, _d;
166
167
  const keyPair = yield generateKeyPair();
167
168
  const handshakeRequest = {
168
169
  method: "handshake",
@@ -170,7 +171,7 @@ var handshake = (deviceIp) => __async(void 0, null, function* () {
170
171
  key: keyPair.publicKey
171
172
  }
172
173
  };
173
- const response = yield (0, import_axios.default)({
174
+ const response = yield (globalThis.nodeAxios ? globalThis.nodeAxios : import_axios.default)({
174
175
  method: "post",
175
176
  url: `http://${deviceIp}/app`,
176
177
  data: handshakeRequest
@@ -178,9 +179,9 @@ var handshake = (deviceIp) => __async(void 0, null, function* () {
178
179
  throwErrorIfFound(response.data);
179
180
  let setCookieHeader;
180
181
  if (response.headers["set-cookie"]) {
181
- setCookieHeader = Array.isArray(response.headers["set-cookie"]) ? response.headers["set-cookie"][0] : response.headers["set-cookie"];
182
+ setCookieHeader = (_b = (_a = response.headers["set-cookie"]) == null ? void 0 : _a[0]) != null ? _b : response.headers["set-cookie"];
182
183
  } else if (response.headers["bypass-cookie"]) {
183
- setCookieHeader = Array.isArray(response.headers["bypass-cookie"]) ? response.headers["bypass-cookie"][0] : response.headers["bypass-cookie"];
184
+ setCookieHeader = (_d = (_c = response.headers["bypass-cookie"]) == null ? void 0 : _c[0]) != null ? _d : response.headers["bypass-cookie"];
184
185
  } else {
185
186
  setCookieHeader = response.headers.get("set-cookie");
186
187
  }
@@ -206,7 +207,6 @@ var securePassthrough = (deviceRequest, deviceKey) => __async(void 0, null, func
206
207
  url: `http://${deviceKey.deviceIp}/app?token=${deviceKey.token}`,
207
208
  data: securePassthroughRequest,
208
209
  headers: {
209
- BypassCookie: deviceKey.sessionCookie,
210
210
  Cookie: deviceKey.sessionCookie
211
211
  }
212
212
  });
@@ -383,12 +383,11 @@ var TapoApi = class {
383
383
  this._devices.set(device.id, deviceKey);
384
384
  return;
385
385
  }));
386
- yield Promise.all(promises);
386
+ yield Promise.allSettled(promises);
387
387
  return this._devices;
388
388
  });
389
389
  // Change state using lightstate
390
390
  this.sendState = (config) => {
391
- var _a;
392
391
  const deviceKey = this._devices.get(config.device.id);
393
392
  let shouldWait = false;
394
393
  if (config.fetchConfig && config.fetchConfig.shouldWait) {
@@ -410,35 +409,21 @@ var TapoApi = class {
410
409
  request: encryptedRequest
411
410
  }
412
411
  };
413
- if ((_a = config.fetchConfig) == null ? void 0 : _a.useAxios) {
414
- return this.axiosInstance({
415
- url: `http://${deviceKey.deviceIp}/app?token=${deviceKey.token}`,
416
- data: {
417
- method: "POST",
418
- body: securePassthroughRequest,
419
- headers: {
420
- BypassCookie: deviceKey.sessionCookie,
421
- Cookie: deviceKey.sessionCookie
422
- }
412
+ return (0, import_fetch_cove.fetchWork)({
413
+ url: `http://${deviceKey.deviceIp}/app?token=${deviceKey.token}`,
414
+ data: {
415
+ method: "POST",
416
+ body: securePassthroughRequest,
417
+ headers: {
418
+ Cookie: deviceKey.sessionCookie,
419
+ BypassCookie: deviceKey.sessionCookie
423
420
  }
424
- });
425
- } else {
426
- return (0, import_fetch_cove.fetchWork)({
427
- url: `http://${deviceKey.deviceIp}/app?token=${deviceKey.token}`,
428
- data: {
429
- method: "POST",
430
- body: securePassthroughRequest,
431
- headers: {
432
- BypassCookie: deviceKey.sessionCookie,
433
- Cookie: deviceKey.sessionCookie
434
- }
435
- },
436
- shouldWait
437
- });
438
- }
421
+ },
422
+ shouldWait
423
+ });
439
424
  };
440
425
  this.sendPower = (config) => {
441
- this.sendState({ device: config.device, state: new LightState({ on: config.power }), fetchConfig: config.fetchConfig });
426
+ this.sendState({ device: config.device, state: new LightState({ on: config.power }) });
442
427
  };
443
428
  this.axiosInstance = import_axios2.default.create();
444
429
  this.axiosInstance.defaults.timeout = (config == null ? void 0 : config.httpTimeout) || 4e3;
@@ -476,7 +461,9 @@ var discover = (config) => __async(void 0, null, function* () {
476
461
  return;
477
462
  }
478
463
  }
464
+ console.log("deviceInfo: ", deviceInfo);
479
465
  switch (deviceInfo.deviceType) {
466
+ case "IOT.SMARTBULB":
480
467
  case "SMART.TAPOBULB": {
481
468
  if (config.types && !config.types.includes(import_lumia_rgb_types.ILumiaDeviceType.LIGHT)) {
482
469
  return;
@@ -504,6 +491,7 @@ var discover = (config) => __async(void 0, null, function* () {
504
491
  }
505
492
  });
506
493
  }
494
+ case "IOT.SMARTPLUGSWITCH":
507
495
  case "SMART.TAPOPLUG": {
508
496
  if (config.types && !config.types.includes(import_lumia_rgb_types.ILumiaDeviceType.PLUG)) {
509
497
  return;
package/dist/index.mjs CHANGED
@@ -131,6 +131,7 @@ var throwErrorIfFound = (responseData) => {
131
131
  }
132
132
  };
133
133
  var handshake = (deviceIp) => __async(void 0, null, function* () {
134
+ var _a, _b, _c, _d;
134
135
  const keyPair = yield generateKeyPair();
135
136
  const handshakeRequest = {
136
137
  method: "handshake",
@@ -138,7 +139,7 @@ var handshake = (deviceIp) => __async(void 0, null, function* () {
138
139
  key: keyPair.publicKey
139
140
  }
140
141
  };
141
- const response = yield axios({
142
+ const response = yield (globalThis.nodeAxios ? globalThis.nodeAxios : axios)({
142
143
  method: "post",
143
144
  url: `http://${deviceIp}/app`,
144
145
  data: handshakeRequest
@@ -146,9 +147,9 @@ var handshake = (deviceIp) => __async(void 0, null, function* () {
146
147
  throwErrorIfFound(response.data);
147
148
  let setCookieHeader;
148
149
  if (response.headers["set-cookie"]) {
149
- setCookieHeader = Array.isArray(response.headers["set-cookie"]) ? response.headers["set-cookie"][0] : response.headers["set-cookie"];
150
+ setCookieHeader = (_b = (_a = response.headers["set-cookie"]) == null ? void 0 : _a[0]) != null ? _b : response.headers["set-cookie"];
150
151
  } else if (response.headers["bypass-cookie"]) {
151
- setCookieHeader = Array.isArray(response.headers["bypass-cookie"]) ? response.headers["bypass-cookie"][0] : response.headers["bypass-cookie"];
152
+ setCookieHeader = (_d = (_c = response.headers["bypass-cookie"]) == null ? void 0 : _c[0]) != null ? _d : response.headers["bypass-cookie"];
152
153
  } else {
153
154
  setCookieHeader = response.headers.get("set-cookie");
154
155
  }
@@ -174,7 +175,6 @@ var securePassthrough = (deviceRequest, deviceKey) => __async(void 0, null, func
174
175
  url: `http://${deviceKey.deviceIp}/app?token=${deviceKey.token}`,
175
176
  data: securePassthroughRequest,
176
177
  headers: {
177
- BypassCookie: deviceKey.sessionCookie,
178
178
  Cookie: deviceKey.sessionCookie
179
179
  }
180
180
  });
@@ -351,12 +351,11 @@ var TapoApi = class {
351
351
  this._devices.set(device.id, deviceKey);
352
352
  return;
353
353
  }));
354
- yield Promise.all(promises);
354
+ yield Promise.allSettled(promises);
355
355
  return this._devices;
356
356
  });
357
357
  // Change state using lightstate
358
358
  this.sendState = (config) => {
359
- var _a;
360
359
  const deviceKey = this._devices.get(config.device.id);
361
360
  let shouldWait = false;
362
361
  if (config.fetchConfig && config.fetchConfig.shouldWait) {
@@ -378,35 +377,21 @@ var TapoApi = class {
378
377
  request: encryptedRequest
379
378
  }
380
379
  };
381
- if ((_a = config.fetchConfig) == null ? void 0 : _a.useAxios) {
382
- return this.axiosInstance({
383
- url: `http://${deviceKey.deviceIp}/app?token=${deviceKey.token}`,
384
- data: {
385
- method: "POST",
386
- body: securePassthroughRequest,
387
- headers: {
388
- BypassCookie: deviceKey.sessionCookie,
389
- Cookie: deviceKey.sessionCookie
390
- }
380
+ return fetchWork({
381
+ url: `http://${deviceKey.deviceIp}/app?token=${deviceKey.token}`,
382
+ data: {
383
+ method: "POST",
384
+ body: securePassthroughRequest,
385
+ headers: {
386
+ Cookie: deviceKey.sessionCookie,
387
+ BypassCookie: deviceKey.sessionCookie
391
388
  }
392
- });
393
- } else {
394
- return fetchWork({
395
- url: `http://${deviceKey.deviceIp}/app?token=${deviceKey.token}`,
396
- data: {
397
- method: "POST",
398
- body: securePassthroughRequest,
399
- headers: {
400
- BypassCookie: deviceKey.sessionCookie,
401
- Cookie: deviceKey.sessionCookie
402
- }
403
- },
404
- shouldWait
405
- });
406
- }
389
+ },
390
+ shouldWait
391
+ });
407
392
  };
408
393
  this.sendPower = (config) => {
409
- this.sendState({ device: config.device, state: new LightState({ on: config.power }), fetchConfig: config.fetchConfig });
394
+ this.sendState({ device: config.device, state: new LightState({ on: config.power }) });
410
395
  };
411
396
  this.axiosInstance = axios2.create();
412
397
  this.axiosInstance.defaults.timeout = (config == null ? void 0 : config.httpTimeout) || 4e3;
@@ -444,7 +429,9 @@ var discover = (config) => __async(void 0, null, function* () {
444
429
  return;
445
430
  }
446
431
  }
432
+ console.log("deviceInfo: ", deviceInfo);
447
433
  switch (deviceInfo.deviceType) {
434
+ case "IOT.SMARTBULB":
448
435
  case "SMART.TAPOBULB": {
449
436
  if (config.types && !config.types.includes(ILumiaDeviceType.LIGHT)) {
450
437
  return;
@@ -472,6 +459,7 @@ var discover = (config) => __async(void 0, null, function* () {
472
459
  }
473
460
  });
474
461
  }
462
+ case "IOT.SMARTPLUGSWITCH":
475
463
  case "SMART.TAPOPLUG": {
476
464
  if (config.types && !config.types.includes(ILumiaDeviceType.PLUG)) {
477
465
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lumiastream/tapo-cove",
3
- "version": "3.0.23",
3
+ "version": "3.1.1",
4
4
  "private": false,
5
5
  "license": "GPL",
6
6
  "main": "dist/index.js",
@@ -13,7 +13,7 @@
13
13
  "dependencies": {
14
14
  "@lumiastream/fetch-cove": "^3.0.9",
15
15
  "@lumiastream/lumia-rgb-types": "^3.0.9",
16
- "@lumiastream/lumia-rgb-utils": "^3.0.9",
16
+ "@lumiastream/lumia-rgb-utils": "^3.1.0",
17
17
  "axios": "*",
18
18
  "local-devices": "^4.0.0"
19
19
  },
@@ -23,5 +23,5 @@
23
23
  "tsup": "*",
24
24
  "typescript": "*"
25
25
  },
26
- "gitHead": "8a15e1eb7633c33c8b1121964b76af83af48bbce"
26
+ "gitHead": "2cdf08ab42cf7e947b6310ca18a1f12116200204"
27
27
  }