tsvesync 1.0.88 → 1.0.90
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/lib/helpers.d.ts +1 -1
- package/dist/lib/helpers.js +20 -3
- package/dist/lib/vesync.d.ts +1 -1
- package/dist/lib/vesync.js +38 -13
- package/package.json +1 -1
- package/src/lib/helpers.ts +25 -3
- package/src/lib/vesync.ts +43 -17
package/dist/lib/helpers.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare function getApiBaseUrl(): string;
|
|
|
6
6
|
export declare function setApiBaseUrl(url: string): void;
|
|
7
7
|
export declare const API_RATE_LIMIT = 30;
|
|
8
8
|
export declare const API_TIMEOUT = 15000;
|
|
9
|
-
export declare const APP_VERSION = "
|
|
9
|
+
export declare const APP_VERSION = "2.8.6";
|
|
10
10
|
export declare const PHONE_BRAND = "SM N9005";
|
|
11
11
|
export declare const PHONE_OS = "Android";
|
|
12
12
|
export declare const USER_TYPE = "1";
|
package/dist/lib/helpers.js
CHANGED
|
@@ -12,7 +12,7 @@ exports.setApiBaseUrl = setApiBaseUrl;
|
|
|
12
12
|
const axios_1 = __importDefault(require("axios"));
|
|
13
13
|
const crypto_1 = __importDefault(require("crypto"));
|
|
14
14
|
const logger_1 = require("./logger");
|
|
15
|
-
// API configuration
|
|
15
|
+
// API configuration - Always use US endpoint
|
|
16
16
|
let _apiBaseUrl = 'https://smartapi.vesync.com';
|
|
17
17
|
function getApiBaseUrl() {
|
|
18
18
|
return _apiBaseUrl;
|
|
@@ -22,7 +22,7 @@ function setApiBaseUrl(url) {
|
|
|
22
22
|
}
|
|
23
23
|
exports.API_RATE_LIMIT = 30;
|
|
24
24
|
exports.API_TIMEOUT = 15000;
|
|
25
|
-
exports.APP_VERSION = '
|
|
25
|
+
exports.APP_VERSION = '2.8.6';
|
|
26
26
|
exports.PHONE_BRAND = 'SM N9005';
|
|
27
27
|
exports.PHONE_OS = 'Android';
|
|
28
28
|
exports.USER_TYPE = '1';
|
|
@@ -164,7 +164,13 @@ class Helpers {
|
|
|
164
164
|
*/
|
|
165
165
|
static async callApi(endpoint, method, data = null, headers = {}, manager) {
|
|
166
166
|
try {
|
|
167
|
+
// Ensure API base URL is properly set
|
|
168
|
+
if (!_apiBaseUrl || _apiBaseUrl === 'undefined') {
|
|
169
|
+
logger_1.logger.error('API base URL is not properly configured. Setting to default US endpoint...');
|
|
170
|
+
setApiBaseUrl('https://smartapi.vesync.com');
|
|
171
|
+
}
|
|
167
172
|
const url = _apiBaseUrl + endpoint;
|
|
173
|
+
logger_1.logger.debug(`Making API call to: ${url}`);
|
|
168
174
|
const response = await (0, axios_1.default)({
|
|
169
175
|
method,
|
|
170
176
|
url,
|
|
@@ -187,9 +193,20 @@ class Helpers {
|
|
|
187
193
|
return await this.callApi(endpoint, method, data, headers, manager);
|
|
188
194
|
}
|
|
189
195
|
}
|
|
196
|
+
// Log specific error details for debugging
|
|
197
|
+
logger_1.logger.error('API call failed with response:', {
|
|
198
|
+
status: error.response.status,
|
|
199
|
+
code: responseData === null || responseData === void 0 ? void 0 : responseData.code,
|
|
200
|
+
message: responseData === null || responseData === void 0 ? void 0 : responseData.msg,
|
|
201
|
+
url: _apiBaseUrl + endpoint
|
|
202
|
+
});
|
|
190
203
|
return [responseData, error.response.status];
|
|
191
204
|
}
|
|
192
|
-
logger_1.logger.error('API call failed:',
|
|
205
|
+
logger_1.logger.error('API call failed:', {
|
|
206
|
+
code: error.code,
|
|
207
|
+
message: error.message,
|
|
208
|
+
url: _apiBaseUrl + endpoint
|
|
209
|
+
});
|
|
193
210
|
return [null, 0];
|
|
194
211
|
}
|
|
195
212
|
}
|
package/dist/lib/vesync.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export declare class VeSync {
|
|
|
43
43
|
* Initialize VeSync Manager
|
|
44
44
|
* @param username - VeSync account username
|
|
45
45
|
* @param password - VeSync account password
|
|
46
|
-
* @param timeZone - Optional timezone (defaults to America/New_York)
|
|
46
|
+
* @param timeZone - Optional timezone for device operations (defaults to America/New_York)
|
|
47
47
|
* @param debug - Optional debug mode flag
|
|
48
48
|
* @param redact - Optional redact mode flag
|
|
49
49
|
* @param apiUrl - Optional API base URL override
|
package/dist/lib/vesync.js
CHANGED
|
@@ -124,7 +124,7 @@ class VeSync {
|
|
|
124
124
|
* Initialize VeSync Manager
|
|
125
125
|
* @param username - VeSync account username
|
|
126
126
|
* @param password - VeSync account password
|
|
127
|
-
* @param timeZone - Optional timezone (defaults to America/New_York)
|
|
127
|
+
* @param timeZone - Optional timezone for device operations (defaults to America/New_York)
|
|
128
128
|
* @param debug - Optional debug mode flag
|
|
129
129
|
* @param redact - Optional redact mode flag
|
|
130
130
|
* @param apiUrl - Optional API base URL override
|
|
@@ -158,14 +158,7 @@ class VeSync {
|
|
|
158
158
|
switches: this.switches,
|
|
159
159
|
bulbs: this.bulbs
|
|
160
160
|
};
|
|
161
|
-
// Set
|
|
162
|
-
if (apiUrl) {
|
|
163
|
-
(0, helpers_1.setApiBaseUrl)(apiUrl);
|
|
164
|
-
}
|
|
165
|
-
// Set custom logger if provided
|
|
166
|
-
if (customLogger) {
|
|
167
|
-
(0, logger_1.setLogger)(customLogger);
|
|
168
|
-
}
|
|
161
|
+
// Set timezone first
|
|
169
162
|
if (typeof timeZone === 'string' && timeZone) {
|
|
170
163
|
const regTest = /[^a-zA-Z/_]/;
|
|
171
164
|
if (regTest.test(timeZone)) {
|
|
@@ -180,6 +173,18 @@ class VeSync {
|
|
|
180
173
|
this.timeZone = helpers_1.DEFAULT_TZ;
|
|
181
174
|
logger_1.logger.debug('Time zone is not a string');
|
|
182
175
|
}
|
|
176
|
+
// Set custom API URL if provided, otherwise use default US endpoint
|
|
177
|
+
if (apiUrl) {
|
|
178
|
+
(0, helpers_1.setApiBaseUrl)(apiUrl);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
// Always use US endpoint
|
|
182
|
+
(0, helpers_1.setApiBaseUrl)('https://smartapi.vesync.com');
|
|
183
|
+
}
|
|
184
|
+
// Set custom logger if provided
|
|
185
|
+
if (customLogger) {
|
|
186
|
+
(0, logger_1.setLogger)(customLogger);
|
|
187
|
+
}
|
|
183
188
|
if (debug) {
|
|
184
189
|
this.debug = true;
|
|
185
190
|
}
|
|
@@ -408,19 +413,39 @@ class VeSync {
|
|
|
408
413
|
async login(retryAttempts = 3, initialDelayMs = 1000) {
|
|
409
414
|
var _a;
|
|
410
415
|
const body = helpers_1.Helpers.reqBody(this, 'login');
|
|
411
|
-
logger_1.logger.debug('Login request:', {
|
|
412
|
-
url: `${process.env.VESYNC_API_URL}/cloud/v1/user/login`,
|
|
413
|
-
body
|
|
414
|
-
});
|
|
415
416
|
for (let attempt = 0; attempt < retryAttempts; attempt++) {
|
|
416
417
|
try {
|
|
418
|
+
logger_1.logger.debug('Login attempt', {
|
|
419
|
+
attempt: attempt + 1,
|
|
420
|
+
apiUrl: (0, helpers_1.getApiBaseUrl)(),
|
|
421
|
+
timeZone: this.timeZone,
|
|
422
|
+
appVersion: body.appVersion
|
|
423
|
+
});
|
|
417
424
|
const [response, status] = await helpers_1.Helpers.callApi('/cloud/v1/user/login', 'post', body, {}, this);
|
|
418
425
|
logger_1.logger.debug('Login response:', { status, response });
|
|
426
|
+
// Handle specific error codes
|
|
427
|
+
if (response && response.code) {
|
|
428
|
+
switch (response.code) {
|
|
429
|
+
case -11012022:
|
|
430
|
+
logger_1.logger.error('App version too low error. Current version:', body.appVersion);
|
|
431
|
+
logger_1.logger.error('This typically indicates an API version compatibility issue.');
|
|
432
|
+
break;
|
|
433
|
+
case -11003:
|
|
434
|
+
logger_1.logger.error('Authentication failed - check credentials');
|
|
435
|
+
break;
|
|
436
|
+
case -11001:
|
|
437
|
+
logger_1.logger.error('Invalid request format');
|
|
438
|
+
break;
|
|
439
|
+
default:
|
|
440
|
+
logger_1.logger.error('API error code:', response.code, 'message:', response.msg);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
419
443
|
if ((_a = response === null || response === void 0 ? void 0 : response.result) === null || _a === void 0 ? void 0 : _a.token) {
|
|
420
444
|
this.token = response.result.token;
|
|
421
445
|
this.accountId = response.result.accountID;
|
|
422
446
|
this.countryCode = response.result.countryCode;
|
|
423
447
|
this.enabled = true;
|
|
448
|
+
logger_1.logger.debug('Login successful for region:', this.countryCode);
|
|
424
449
|
return true;
|
|
425
450
|
}
|
|
426
451
|
// If we reach here, login failed but didn't throw an error
|
package/package.json
CHANGED
package/src/lib/helpers.ts
CHANGED
|
@@ -7,7 +7,7 @@ import crypto from 'crypto';
|
|
|
7
7
|
import { VeSync } from './vesync';
|
|
8
8
|
import { logger } from './logger';
|
|
9
9
|
|
|
10
|
-
// API configuration
|
|
10
|
+
// API configuration - Always use US endpoint
|
|
11
11
|
let _apiBaseUrl = 'https://smartapi.vesync.com';
|
|
12
12
|
|
|
13
13
|
export function getApiBaseUrl(): string {
|
|
@@ -18,10 +18,11 @@ export function setApiBaseUrl(url: string): void {
|
|
|
18
18
|
_apiBaseUrl = url;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
|
|
21
22
|
export const API_RATE_LIMIT = 30;
|
|
22
23
|
export const API_TIMEOUT = 15000;
|
|
23
24
|
|
|
24
|
-
export const APP_VERSION = '
|
|
25
|
+
export const APP_VERSION = '2.8.6';
|
|
25
26
|
export const PHONE_BRAND = 'SM N9005';
|
|
26
27
|
export const PHONE_OS = 'Android';
|
|
27
28
|
export const USER_TYPE = '1';
|
|
@@ -206,7 +207,15 @@ export class Helpers {
|
|
|
206
207
|
manager: VeSync
|
|
207
208
|
): Promise<[any, number]> {
|
|
208
209
|
try {
|
|
210
|
+
// Ensure API base URL is properly set
|
|
211
|
+
if (!_apiBaseUrl || _apiBaseUrl === 'undefined') {
|
|
212
|
+
logger.error('API base URL is not properly configured. Setting to default US endpoint...');
|
|
213
|
+
setApiBaseUrl('https://smartapi.vesync.com');
|
|
214
|
+
}
|
|
215
|
+
|
|
209
216
|
const url = _apiBaseUrl + endpoint;
|
|
217
|
+
logger.debug(`Making API call to: ${url}`);
|
|
218
|
+
|
|
210
219
|
const response = await axios({
|
|
211
220
|
method,
|
|
212
221
|
url,
|
|
@@ -231,10 +240,23 @@ export class Helpers {
|
|
|
231
240
|
return await this.callApi(endpoint, method, data, headers, manager);
|
|
232
241
|
}
|
|
233
242
|
}
|
|
243
|
+
|
|
244
|
+
// Log specific error details for debugging
|
|
245
|
+
logger.error('API call failed with response:', {
|
|
246
|
+
status: error.response.status,
|
|
247
|
+
code: responseData?.code,
|
|
248
|
+
message: responseData?.msg,
|
|
249
|
+
url: _apiBaseUrl + endpoint
|
|
250
|
+
});
|
|
251
|
+
|
|
234
252
|
return [responseData, error.response.status];
|
|
235
253
|
}
|
|
236
254
|
|
|
237
|
-
logger.error('API call failed:',
|
|
255
|
+
logger.error('API call failed:', {
|
|
256
|
+
code: error.code,
|
|
257
|
+
message: error.message,
|
|
258
|
+
url: _apiBaseUrl + endpoint
|
|
259
|
+
});
|
|
238
260
|
return [null, 0];
|
|
239
261
|
}
|
|
240
262
|
}
|
package/src/lib/vesync.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* VeSync API Device Library
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { Helpers, API_RATE_LIMIT, DEFAULT_TZ, setApiBaseUrl } from './helpers';
|
|
5
|
+
import { Helpers, API_RATE_LIMIT, DEFAULT_TZ, setApiBaseUrl, getApiBaseUrl } from './helpers';
|
|
6
6
|
import { VeSyncBaseDevice } from './vesyncBaseDevice';
|
|
7
7
|
import { fanModules } from './vesyncFanImpl';
|
|
8
8
|
import { outletModules } from './vesyncOutletImpl';
|
|
@@ -180,7 +180,7 @@ export class VeSync {
|
|
|
180
180
|
* Initialize VeSync Manager
|
|
181
181
|
* @param username - VeSync account username
|
|
182
182
|
* @param password - VeSync account password
|
|
183
|
-
* @param timeZone - Optional timezone (defaults to America/New_York)
|
|
183
|
+
* @param timeZone - Optional timezone for device operations (defaults to America/New_York)
|
|
184
184
|
* @param debug - Optional debug mode flag
|
|
185
185
|
* @param redact - Optional redact mode flag
|
|
186
186
|
* @param apiUrl - Optional API base URL override
|
|
@@ -227,16 +227,7 @@ export class VeSync {
|
|
|
227
227
|
bulbs: this.bulbs
|
|
228
228
|
};
|
|
229
229
|
|
|
230
|
-
// Set
|
|
231
|
-
if (apiUrl) {
|
|
232
|
-
setApiBaseUrl(apiUrl);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// Set custom logger if provided
|
|
236
|
-
if (customLogger) {
|
|
237
|
-
setLogger(customLogger);
|
|
238
|
-
}
|
|
239
|
-
|
|
230
|
+
// Set timezone first
|
|
240
231
|
if (typeof timeZone === 'string' && timeZone) {
|
|
241
232
|
const regTest = /[^a-zA-Z/_]/;
|
|
242
233
|
if (regTest.test(timeZone)) {
|
|
@@ -250,6 +241,19 @@ export class VeSync {
|
|
|
250
241
|
logger.debug('Time zone is not a string');
|
|
251
242
|
}
|
|
252
243
|
|
|
244
|
+
// Set custom API URL if provided, otherwise use default US endpoint
|
|
245
|
+
if (apiUrl) {
|
|
246
|
+
setApiBaseUrl(apiUrl);
|
|
247
|
+
} else {
|
|
248
|
+
// Always use US endpoint
|
|
249
|
+
setApiBaseUrl('https://smartapi.vesync.com');
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Set custom logger if provided
|
|
253
|
+
if (customLogger) {
|
|
254
|
+
setLogger(customLogger);
|
|
255
|
+
}
|
|
256
|
+
|
|
253
257
|
if (debug) {
|
|
254
258
|
this.debug = true;
|
|
255
259
|
}
|
|
@@ -506,13 +510,16 @@ export class VeSync {
|
|
|
506
510
|
*/
|
|
507
511
|
async login(retryAttempts: number = 3, initialDelayMs: number = 1000): Promise<boolean> {
|
|
508
512
|
const body = Helpers.reqBody(this, 'login');
|
|
509
|
-
|
|
510
|
-
url: `${process.env.VESYNC_API_URL}/cloud/v1/user/login`,
|
|
511
|
-
body
|
|
512
|
-
});
|
|
513
|
-
|
|
513
|
+
|
|
514
514
|
for (let attempt = 0; attempt < retryAttempts; attempt++) {
|
|
515
515
|
try {
|
|
516
|
+
logger.debug('Login attempt', {
|
|
517
|
+
attempt: attempt + 1,
|
|
518
|
+
apiUrl: getApiBaseUrl(),
|
|
519
|
+
timeZone: this.timeZone,
|
|
520
|
+
appVersion: body.appVersion
|
|
521
|
+
});
|
|
522
|
+
|
|
516
523
|
const [response, status] = await Helpers.callApi(
|
|
517
524
|
'/cloud/v1/user/login',
|
|
518
525
|
'post',
|
|
@@ -523,11 +530,30 @@ export class VeSync {
|
|
|
523
530
|
|
|
524
531
|
logger.debug('Login response:', { status, response });
|
|
525
532
|
|
|
533
|
+
// Handle specific error codes
|
|
534
|
+
if (response && response.code) {
|
|
535
|
+
switch (response.code) {
|
|
536
|
+
case -11012022:
|
|
537
|
+
logger.error('App version too low error. Current version:', body.appVersion);
|
|
538
|
+
logger.error('This typically indicates an API version compatibility issue.');
|
|
539
|
+
break;
|
|
540
|
+
case -11003:
|
|
541
|
+
logger.error('Authentication failed - check credentials');
|
|
542
|
+
break;
|
|
543
|
+
case -11001:
|
|
544
|
+
logger.error('Invalid request format');
|
|
545
|
+
break;
|
|
546
|
+
default:
|
|
547
|
+
logger.error('API error code:', response.code, 'message:', response.msg);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
526
551
|
if (response?.result?.token) {
|
|
527
552
|
this.token = response.result.token;
|
|
528
553
|
this.accountId = response.result.accountID;
|
|
529
554
|
this.countryCode = response.result.countryCode;
|
|
530
555
|
this.enabled = true;
|
|
556
|
+
logger.debug('Login successful for region:', this.countryCode);
|
|
531
557
|
return true;
|
|
532
558
|
}
|
|
533
559
|
|