@lumiastream/tapo-cove 3.0.14 → 3.0.16

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/dist/index.d.ts CHANGED
@@ -96,6 +96,7 @@ declare class TapoApi {
96
96
  };
97
97
  state: LightState;
98
98
  fetchConfig?: {
99
+ useAxios: boolean;
99
100
  shouldWait: boolean;
100
101
  };
101
102
  }) => Promise<any>;
package/dist/index.js CHANGED
@@ -163,7 +163,7 @@ var throwErrorIfFound = (responseData) => {
163
163
  }
164
164
  };
165
165
  var handshake = (deviceIp) => __async(void 0, null, function* () {
166
- var _a, _b, _c;
166
+ var _a, _b;
167
167
  const keyPair = yield generateKeyPair();
168
168
  const handshakeRequest = {
169
169
  method: "handshake",
@@ -177,8 +177,12 @@ var handshake = (deviceIp) => __async(void 0, null, function* () {
177
177
  data: handshakeRequest
178
178
  });
179
179
  throwErrorIfFound(response.data);
180
- console.log("response.headers: ", response.headers);
181
- const setCookieHeader = (_c = (_b = (_a = response.headers.get("set-cookie")) != null ? _a : response.headers.get("session-cookie")) != null ? _b : response.headers.get("session-key")) != null ? _c : response.headers.get("lumia-session");
180
+ let setCookieHeader;
181
+ if (response.headers["set-cookie"]) {
182
+ setCookieHeader = (_b = (_a = response.headers["set-cookie"]) == null ? void 0 : _a[0]) != null ? _b : response.headers["set-cookie"];
183
+ } else {
184
+ setCookieHeader = response.headers.get("set-cookie");
185
+ }
182
186
  const sessionCookie = setCookieHeader.substring(0, setCookieHeader.indexOf(";"));
183
187
  const deviceKey = readDeviceKey(response.data.result.key, keyPair.privateKey);
184
188
  return {
@@ -382,6 +386,7 @@ var TapoApi = class {
382
386
  });
383
387
  // Change state using lightstate
384
388
  this.sendState = (config) => {
389
+ var _a;
385
390
  const deviceKey = this._devices.get(config.device.id);
386
391
  let shouldWait = false;
387
392
  if (config.fetchConfig && config.fetchConfig.shouldWait) {
@@ -403,17 +408,30 @@ var TapoApi = class {
403
408
  request: encryptedRequest
404
409
  }
405
410
  };
406
- return (0, import_fetch_cove.fetchWork)({
407
- url: `http://${deviceKey.deviceIp}/app?token=${deviceKey.token}`,
408
- data: {
409
- method: "POST",
410
- body: securePassthroughRequest,
411
- headers: {
412
- Cookie: deviceKey.sessionCookie
411
+ if ((_a = config.fetchConfig) == null ? void 0 : _a.useAxios) {
412
+ return (0, import_axios2.default)({
413
+ url: `http://${deviceKey.deviceIp}/app?token=${deviceKey.token}`,
414
+ data: {
415
+ method: "POST",
416
+ body: securePassthroughRequest,
417
+ headers: {
418
+ Cookie: deviceKey.sessionCookie
419
+ }
413
420
  }
414
- },
415
- shouldWait
416
- });
421
+ });
422
+ } else {
423
+ return (0, import_fetch_cove.fetchWork)({
424
+ url: `http://${deviceKey.deviceIp}/app?token=${deviceKey.token}`,
425
+ data: {
426
+ method: "POST",
427
+ body: securePassthroughRequest,
428
+ headers: {
429
+ Cookie: deviceKey.sessionCookie
430
+ }
431
+ },
432
+ shouldWait
433
+ });
434
+ }
417
435
  };
418
436
  this.sendPower = (config) => {
419
437
  this.sendState({ device: config.device, state: new LightState({ on: config.power }) });
package/dist/index.mjs CHANGED
@@ -131,7 +131,7 @@ var throwErrorIfFound = (responseData) => {
131
131
  }
132
132
  };
133
133
  var handshake = (deviceIp) => __async(void 0, null, function* () {
134
- var _a, _b, _c;
134
+ var _a, _b;
135
135
  const keyPair = yield generateKeyPair();
136
136
  const handshakeRequest = {
137
137
  method: "handshake",
@@ -145,8 +145,12 @@ var handshake = (deviceIp) => __async(void 0, null, function* () {
145
145
  data: handshakeRequest
146
146
  });
147
147
  throwErrorIfFound(response.data);
148
- console.log("response.headers: ", response.headers);
149
- const setCookieHeader = (_c = (_b = (_a = response.headers.get("set-cookie")) != null ? _a : response.headers.get("session-cookie")) != null ? _b : response.headers.get("session-key")) != null ? _c : response.headers.get("lumia-session");
148
+ let setCookieHeader;
149
+ if (response.headers["set-cookie"]) {
150
+ setCookieHeader = (_b = (_a = response.headers["set-cookie"]) == null ? void 0 : _a[0]) != null ? _b : response.headers["set-cookie"];
151
+ } else {
152
+ setCookieHeader = response.headers.get("set-cookie");
153
+ }
150
154
  const sessionCookie = setCookieHeader.substring(0, setCookieHeader.indexOf(";"));
151
155
  const deviceKey = readDeviceKey(response.data.result.key, keyPair.privateKey);
152
156
  return {
@@ -350,6 +354,7 @@ var TapoApi = class {
350
354
  });
351
355
  // Change state using lightstate
352
356
  this.sendState = (config) => {
357
+ var _a;
353
358
  const deviceKey = this._devices.get(config.device.id);
354
359
  let shouldWait = false;
355
360
  if (config.fetchConfig && config.fetchConfig.shouldWait) {
@@ -371,17 +376,30 @@ var TapoApi = class {
371
376
  request: encryptedRequest
372
377
  }
373
378
  };
374
- return fetchWork({
375
- url: `http://${deviceKey.deviceIp}/app?token=${deviceKey.token}`,
376
- data: {
377
- method: "POST",
378
- body: securePassthroughRequest,
379
- headers: {
380
- Cookie: deviceKey.sessionCookie
379
+ if ((_a = config.fetchConfig) == null ? void 0 : _a.useAxios) {
380
+ return axios2({
381
+ url: `http://${deviceKey.deviceIp}/app?token=${deviceKey.token}`,
382
+ data: {
383
+ method: "POST",
384
+ body: securePassthroughRequest,
385
+ headers: {
386
+ Cookie: deviceKey.sessionCookie
387
+ }
381
388
  }
382
- },
383
- shouldWait
384
- });
389
+ });
390
+ } else {
391
+ return fetchWork({
392
+ url: `http://${deviceKey.deviceIp}/app?token=${deviceKey.token}`,
393
+ data: {
394
+ method: "POST",
395
+ body: securePassthroughRequest,
396
+ headers: {
397
+ Cookie: deviceKey.sessionCookie
398
+ }
399
+ },
400
+ shouldWait
401
+ });
402
+ }
385
403
  };
386
404
  this.sendPower = (config) => {
387
405
  this.sendState({ device: config.device, state: new LightState({ on: config.power }) });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lumiastream/tapo-cove",
3
- "version": "3.0.14",
3
+ "version": "3.0.16",
4
4
  "private": false,
5
5
  "license": "GPL",
6
6
  "main": "dist/index.js",
@@ -23,5 +23,5 @@
23
23
  "tsup": "*",
24
24
  "typescript": "*"
25
25
  },
26
- "gitHead": "b9daf4a655697189e3399fe4c769a939c269a61e"
26
+ "gitHead": "eca53cb985b927ddc7e3c886fd2be02e0f2b4bdb"
27
27
  }