@lumiastream/tapo-cove 3.0.10 → 3.0.11

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
@@ -69,14 +69,11 @@ type TapoDeviceKey = {
69
69
  declare class TapoApi {
70
70
  _baseUrl: string;
71
71
  _baseTapoCareUrl: string;
72
- private axiosInstance;
73
72
  private _config;
74
73
  private _token;
75
74
  private _devices;
76
75
  constructor(config?: {
77
76
  token?: string;
78
- timeout?: number;
79
- httpTimeout?: number;
80
77
  });
81
78
  auth: ({ email, password }: {
82
79
  email: string;
package/dist/index.js CHANGED
@@ -72,8 +72,8 @@ __export(src_exports, {
72
72
  module.exports = __toCommonJS(src_exports);
73
73
 
74
74
  // src/discovery.ts
75
+ var import_fetch_cove3 = require("@lumiastream/fetch-cove");
75
76
  var import_lumia_rgb_types = require("@lumiastream/lumia-rgb-types");
76
- var import_axios3 = __toESM(require("axios"));
77
77
  var import_local_devices = __toESM(require("local-devices"));
78
78
 
79
79
  // src/shared/cipher.ts
@@ -134,7 +134,7 @@ var shaDigest = (data) => {
134
134
  };
135
135
 
136
136
  // src/shared/helpers.ts
137
- var import_axios = __toESM(require("axios"));
137
+ var import_fetch_cove = require("@lumiastream/fetch-cove");
138
138
  var throwErrorIfFound = (responseData) => {
139
139
  const errorCode = responseData["error_code"];
140
140
  if (errorCode) {
@@ -170,15 +170,21 @@ var handshake = (deviceIp) => __async(void 0, null, function* () {
170
170
  key: keyPair.publicKey
171
171
  }
172
172
  };
173
- const response = yield (0, import_axios.default)({
174
- method: "post",
173
+ const response = yield (0, import_fetch_cove.fetchWork)({
175
174
  url: `http://${deviceIp}/app`,
176
- data: handshakeRequest
175
+ data: {
176
+ method: "POST",
177
+ body: handshakeRequest
178
+ },
179
+ shouldWait: true,
180
+ fullResponse: true
177
181
  });
178
- throwErrorIfFound(response.data);
179
- const setCookieHeader = response.headers["set-cookie"][0];
182
+ const data = yield response.json();
183
+ throwErrorIfFound(data);
184
+ const setCookieHeader = response.headers.get("set-cookie");
185
+ console.log("setCookieHeader: ", setCookieHeader);
180
186
  const sessionCookie = setCookieHeader.substring(0, setCookieHeader.indexOf(";"));
181
- const deviceKey = readDeviceKey(response.data.result.key, keyPair.privateKey);
187
+ const deviceKey = readDeviceKey(data.result.key, keyPair.privateKey);
182
188
  return {
183
189
  key: deviceKey.subarray(0, 16),
184
190
  iv: deviceKey.subarray(16, 32),
@@ -194,23 +200,24 @@ var securePassthrough = (deviceRequest, deviceKey) => __async(void 0, null, func
194
200
  request: encryptedRequest
195
201
  }
196
202
  };
197
- const response = yield (0, import_axios.default)({
198
- method: "post",
203
+ const data = yield (0, import_fetch_cove.fetchWork)({
199
204
  url: `http://${deviceKey.deviceIp}/app?token=${deviceKey.token}`,
200
- data: securePassthroughRequest,
201
- headers: {
202
- Cookie: deviceKey.sessionCookie
203
- }
205
+ data: {
206
+ method: "POST",
207
+ body: securePassthroughRequest,
208
+ headers: {
209
+ Cookie: deviceKey.sessionCookie
210
+ }
211
+ },
212
+ shouldWait: true
204
213
  });
205
- throwErrorIfFound(response.data);
206
- const decryptedResponse = decrypt(response.data.result.response, deviceKey);
214
+ throwErrorIfFound(data);
215
+ console.log("data: ", data);
216
+ const decryptedResponse = decrypt(data.result.response, deviceKey);
207
217
  throwErrorIfFound(decryptedResponse);
208
218
  return decryptedResponse.result;
209
219
  });
210
220
 
211
- // src/tapo-api.ts
212
- var import_axios2 = __toESM(require("axios"));
213
-
214
221
  // src/lightstate.ts
215
222
  var import_lumia_rgb_utils = require("@lumiastream/lumia-rgb-utils");
216
223
  var SuperState = class {
@@ -326,17 +333,21 @@ var LightState = class extends SuperState {
326
333
  };
327
334
 
328
335
  // src/tapo-api.ts
329
- var import_fetch_cove = require("@lumiastream/fetch-cove");
336
+ var import_fetch_cove2 = require("@lumiastream/fetch-cove");
330
337
  var import_lumia_rgb_utils2 = require("@lumiastream/lumia-rgb-utils");
331
338
  var TapoApi = class {
332
339
  constructor(config) {
333
340
  this._baseUrl = "https://eu-wap.tplinkcloud.com/";
334
341
  // https://n-euw1-wap-gw.tplinkcloud.com
335
342
  this._baseTapoCareUrl = "https://euw1-app-tapo-care.i.tplinknbu.com";
343
+ // http://use1-relay-dcipc.i.tplinknbu.com
344
+ // http://aps1-relay-dcipc-beta.i.tplinknbu.com
345
+ // http://euw1-relay-dcipc.i.tplinknbu.com
346
+ // http://aps1-relay-dcipc-beta.i.tplinknbu.com
347
+ // http://aps1-relay-dcipc.i.tplinknbu.com
348
+ // http://aps1-relay-dcipc-beta.i.tplinknbu.com
336
349
  this._config = {
337
- authToken: null,
338
- timeout: 1e4,
339
- httpTimeout: 4e3
350
+ authToken: null
340
351
  };
341
352
  this._token = "";
342
353
  this._devices = /* @__PURE__ */ new Map();
@@ -350,13 +361,16 @@ var TapoApi = class {
350
361
  terminalUUID: (0, import_lumia_rgb_utils2.uuidv4)()
351
362
  }
352
363
  };
353
- const response = yield (0, import_axios2.default)({
354
- method: "post",
364
+ const data = yield (0, import_fetch_cove2.fetchWork)({
355
365
  url: this._baseUrl,
356
- data: loginRequest
366
+ data: {
367
+ method: "POST",
368
+ body: loginRequest
369
+ },
370
+ shouldWait: true
357
371
  });
358
- throwErrorIfFound(response.data);
359
- this._token = response.data.result.token;
372
+ throwErrorIfFound(data);
373
+ this._token = data.result.token;
360
374
  return this._token;
361
375
  });
362
376
  this.setup = (_0) => __async(this, [_0], function* ({ email, password, devices }) {
@@ -401,7 +415,7 @@ var TapoApi = class {
401
415
  request: encryptedRequest
402
416
  }
403
417
  };
404
- return (0, import_fetch_cove.fetchWork)({
418
+ return (0, import_fetch_cove2.fetchWork)({
405
419
  url: `http://${deviceKey.deviceIp}/app?token=${deviceKey.token}`,
406
420
  data: {
407
421
  method: "POST",
@@ -416,8 +430,6 @@ var TapoApi = class {
416
430
  this.sendPower = (config) => {
417
431
  this.sendState({ device: config.device, state: new LightState({ on: config.power }) });
418
432
  };
419
- this.axiosInstance = import_axios2.default.create();
420
- this.axiosInstance.defaults.timeout = (config == null ? void 0 : config.httpTimeout) || 4e3;
421
433
  this._config = __spreadValues(__spreadValues({}, this._config), config);
422
434
  }
423
435
  };
@@ -433,15 +445,18 @@ var discover = (config) => __async(void 0, null, function* () {
433
445
  const getDeviceRequest = {
434
446
  method: "getDeviceList"
435
447
  };
436
- const response = yield (0, import_axios3.default)({
437
- method: "post",
448
+ const data = yield (0, import_fetch_cove3.fetchWork)({
438
449
  url: `${api._baseUrl}?token=${token}`,
439
- data: getDeviceRequest
450
+ data: {
451
+ method: "POST",
452
+ body: getDeviceRequest
453
+ },
454
+ shouldWait: true
440
455
  });
441
- throwErrorIfFound(response.data);
456
+ throwErrorIfFound(data);
442
457
  const devices = [];
443
458
  const localDevices = yield (0, import_local_devices.default)({ skipNameResolution: true });
444
- (_a = response.data.result) == null ? void 0 : _a.deviceList.map((deviceInfo) => __async(void 0, null, function* () {
459
+ (_a = data.result) == null ? void 0 : _a.deviceList.map((deviceInfo) => __async(void 0, null, function* () {
445
460
  var _a2, _b;
446
461
  if (!deviceInfo.ip) {
447
462
  const findableMac = deviceInfo.deviceMac.replace(/:/g, "").toUpperCase();
package/dist/index.mjs CHANGED
@@ -40,8 +40,8 @@ var __async = (__this, __arguments, generator) => {
40
40
  };
41
41
 
42
42
  // src/discovery.ts
43
+ import { fetchWork as fetchWork3 } from "@lumiastream/fetch-cove";
43
44
  import { ILumiaDeviceBrands, ILumiaDeviceConnectionType, ILumiaDeviceType } from "@lumiastream/lumia-rgb-types";
44
- import Axios from "axios";
45
45
  import findLocalDevices from "local-devices";
46
46
 
47
47
  // src/shared/cipher.ts
@@ -102,7 +102,7 @@ var shaDigest = (data) => {
102
102
  };
103
103
 
104
104
  // src/shared/helpers.ts
105
- import axios from "axios";
105
+ import { fetchWork } from "@lumiastream/fetch-cove";
106
106
  var throwErrorIfFound = (responseData) => {
107
107
  const errorCode = responseData["error_code"];
108
108
  if (errorCode) {
@@ -138,15 +138,21 @@ var handshake = (deviceIp) => __async(void 0, null, function* () {
138
138
  key: keyPair.publicKey
139
139
  }
140
140
  };
141
- const response = yield axios({
142
- method: "post",
141
+ const response = yield fetchWork({
143
142
  url: `http://${deviceIp}/app`,
144
- data: handshakeRequest
143
+ data: {
144
+ method: "POST",
145
+ body: handshakeRequest
146
+ },
147
+ shouldWait: true,
148
+ fullResponse: true
145
149
  });
146
- throwErrorIfFound(response.data);
147
- const setCookieHeader = response.headers["set-cookie"][0];
150
+ const data = yield response.json();
151
+ throwErrorIfFound(data);
152
+ const setCookieHeader = response.headers.get("set-cookie");
153
+ console.log("setCookieHeader: ", setCookieHeader);
148
154
  const sessionCookie = setCookieHeader.substring(0, setCookieHeader.indexOf(";"));
149
- const deviceKey = readDeviceKey(response.data.result.key, keyPair.privateKey);
155
+ const deviceKey = readDeviceKey(data.result.key, keyPair.privateKey);
150
156
  return {
151
157
  key: deviceKey.subarray(0, 16),
152
158
  iv: deviceKey.subarray(16, 32),
@@ -162,23 +168,24 @@ var securePassthrough = (deviceRequest, deviceKey) => __async(void 0, null, func
162
168
  request: encryptedRequest
163
169
  }
164
170
  };
165
- const response = yield axios({
166
- method: "post",
171
+ const data = yield fetchWork({
167
172
  url: `http://${deviceKey.deviceIp}/app?token=${deviceKey.token}`,
168
- data: securePassthroughRequest,
169
- headers: {
170
- Cookie: deviceKey.sessionCookie
171
- }
173
+ data: {
174
+ method: "POST",
175
+ body: securePassthroughRequest,
176
+ headers: {
177
+ Cookie: deviceKey.sessionCookie
178
+ }
179
+ },
180
+ shouldWait: true
172
181
  });
173
- throwErrorIfFound(response.data);
174
- const decryptedResponse = decrypt(response.data.result.response, deviceKey);
182
+ throwErrorIfFound(data);
183
+ console.log("data: ", data);
184
+ const decryptedResponse = decrypt(data.result.response, deviceKey);
175
185
  throwErrorIfFound(decryptedResponse);
176
186
  return decryptedResponse.result;
177
187
  });
178
188
 
179
- // src/tapo-api.ts
180
- import axios2 from "axios";
181
-
182
189
  // src/lightstate.ts
183
190
  import { isTruly, isFunction, rgb2hsv } from "@lumiastream/lumia-rgb-utils";
184
191
  var SuperState = class {
@@ -294,17 +301,21 @@ var LightState = class extends SuperState {
294
301
  };
295
302
 
296
303
  // src/tapo-api.ts
297
- import { fetchWork } from "@lumiastream/fetch-cove";
304
+ import { fetchWork as fetchWork2 } from "@lumiastream/fetch-cove";
298
305
  import { uuidv4 } from "@lumiastream/lumia-rgb-utils";
299
306
  var TapoApi = class {
300
307
  constructor(config) {
301
308
  this._baseUrl = "https://eu-wap.tplinkcloud.com/";
302
309
  // https://n-euw1-wap-gw.tplinkcloud.com
303
310
  this._baseTapoCareUrl = "https://euw1-app-tapo-care.i.tplinknbu.com";
311
+ // http://use1-relay-dcipc.i.tplinknbu.com
312
+ // http://aps1-relay-dcipc-beta.i.tplinknbu.com
313
+ // http://euw1-relay-dcipc.i.tplinknbu.com
314
+ // http://aps1-relay-dcipc-beta.i.tplinknbu.com
315
+ // http://aps1-relay-dcipc.i.tplinknbu.com
316
+ // http://aps1-relay-dcipc-beta.i.tplinknbu.com
304
317
  this._config = {
305
- authToken: null,
306
- timeout: 1e4,
307
- httpTimeout: 4e3
318
+ authToken: null
308
319
  };
309
320
  this._token = "";
310
321
  this._devices = /* @__PURE__ */ new Map();
@@ -318,13 +329,16 @@ var TapoApi = class {
318
329
  terminalUUID: uuidv4()
319
330
  }
320
331
  };
321
- const response = yield axios2({
322
- method: "post",
332
+ const data = yield fetchWork2({
323
333
  url: this._baseUrl,
324
- data: loginRequest
334
+ data: {
335
+ method: "POST",
336
+ body: loginRequest
337
+ },
338
+ shouldWait: true
325
339
  });
326
- throwErrorIfFound(response.data);
327
- this._token = response.data.result.token;
340
+ throwErrorIfFound(data);
341
+ this._token = data.result.token;
328
342
  return this._token;
329
343
  });
330
344
  this.setup = (_0) => __async(this, [_0], function* ({ email, password, devices }) {
@@ -369,7 +383,7 @@ var TapoApi = class {
369
383
  request: encryptedRequest
370
384
  }
371
385
  };
372
- return fetchWork({
386
+ return fetchWork2({
373
387
  url: `http://${deviceKey.deviceIp}/app?token=${deviceKey.token}`,
374
388
  data: {
375
389
  method: "POST",
@@ -384,8 +398,6 @@ var TapoApi = class {
384
398
  this.sendPower = (config) => {
385
399
  this.sendState({ device: config.device, state: new LightState({ on: config.power }) });
386
400
  };
387
- this.axiosInstance = axios2.create();
388
- this.axiosInstance.defaults.timeout = (config == null ? void 0 : config.httpTimeout) || 4e3;
389
401
  this._config = __spreadValues(__spreadValues({}, this._config), config);
390
402
  }
391
403
  };
@@ -401,15 +413,18 @@ var discover = (config) => __async(void 0, null, function* () {
401
413
  const getDeviceRequest = {
402
414
  method: "getDeviceList"
403
415
  };
404
- const response = yield Axios({
405
- method: "post",
416
+ const data = yield fetchWork3({
406
417
  url: `${api._baseUrl}?token=${token}`,
407
- data: getDeviceRequest
418
+ data: {
419
+ method: "POST",
420
+ body: getDeviceRequest
421
+ },
422
+ shouldWait: true
408
423
  });
409
- throwErrorIfFound(response.data);
424
+ throwErrorIfFound(data);
410
425
  const devices = [];
411
426
  const localDevices = yield findLocalDevices({ skipNameResolution: true });
412
- (_a = response.data.result) == null ? void 0 : _a.deviceList.map((deviceInfo) => __async(void 0, null, function* () {
427
+ (_a = data.result) == null ? void 0 : _a.deviceList.map((deviceInfo) => __async(void 0, null, function* () {
413
428
  var _a2, _b;
414
429
  if (!deviceInfo.ip) {
415
430
  const findableMac = deviceInfo.deviceMac.replace(/:/g, "").toUpperCase();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lumiastream/tapo-cove",
3
- "version": "3.0.10",
3
+ "version": "3.0.11",
4
4
  "private": false,
5
5
  "license": "GPL",
6
6
  "main": "dist/index.js",
@@ -11,10 +11,9 @@
11
11
  "lint": "tsc"
12
12
  },
13
13
  "dependencies": {
14
- "@lumiastream/fetch-cove": "^3.0.9",
14
+ "@lumiastream/fetch-cove": "^3.0.11",
15
15
  "@lumiastream/lumia-rgb-types": "^3.0.9",
16
16
  "@lumiastream/lumia-rgb-utils": "^3.0.9",
17
- "axios": "*",
18
17
  "local-devices": "^4.0.0"
19
18
  },
20
19
  "devDependencies": {
@@ -23,5 +22,5 @@
23
22
  "tsup": "*",
24
23
  "typescript": "*"
25
24
  },
26
- "gitHead": "aeb4676ebaf5bfc0fc1a7873c9cdc150fbdf9692"
25
+ "gitHead": "e0d45e28250cbf71461ee820b026dca1b2439bf0"
27
26
  }