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