tsvesync 1.0.32 → 1.0.34
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 +2 -7
- package/dist/lib/vesync.d.ts +1 -1
- package/dist/lib/vesync.js +27 -16
- package/package.json +1 -1
- package/src/lib/helpers.ts +3 -6
- package/src/lib/vesync.ts +37 -23
package/dist/lib/helpers.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { VeSync } from './vesync';
|
|
|
5
5
|
export declare function getApiBaseUrl(): string;
|
|
6
6
|
export declare function setApiBaseUrl(url: string): void;
|
|
7
7
|
export declare const API_RATE_LIMIT = 30;
|
|
8
|
-
export declare const API_TIMEOUT =
|
|
8
|
+
export declare const API_TIMEOUT = 15000;
|
|
9
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";
|
package/dist/lib/helpers.js
CHANGED
|
@@ -21,7 +21,7 @@ function setApiBaseUrl(url) {
|
|
|
21
21
|
_apiBaseUrl = url;
|
|
22
22
|
}
|
|
23
23
|
exports.API_RATE_LIMIT = 30;
|
|
24
|
-
exports.API_TIMEOUT =
|
|
24
|
+
exports.API_TIMEOUT = 15000;
|
|
25
25
|
exports.APP_VERSION = '2.8.6';
|
|
26
26
|
exports.PHONE_BRAND = 'SM N9005';
|
|
27
27
|
exports.PHONE_OS = 'Android';
|
|
@@ -189,12 +189,7 @@ class Helpers {
|
|
|
189
189
|
}
|
|
190
190
|
return [responseData, error.response.status];
|
|
191
191
|
}
|
|
192
|
-
|
|
193
|
-
logger_1.logger.debug('API call failed:', error.code, error.message);
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
logger_1.logger.error('API call failed:', error.code, error.message);
|
|
197
|
-
}
|
|
192
|
+
logger_1.logger.error('API call failed:', error.code, error.message);
|
|
198
193
|
return [null, 0];
|
|
199
194
|
}
|
|
200
195
|
}
|
package/dist/lib/vesync.d.ts
CHANGED
package/dist/lib/vesync.js
CHANGED
|
@@ -385,30 +385,41 @@ class VeSync {
|
|
|
385
385
|
/**
|
|
386
386
|
* Login to VeSync server
|
|
387
387
|
*/
|
|
388
|
-
async login() {
|
|
388
|
+
async login(retryAttempts = 3, initialDelayMs = 1000) {
|
|
389
389
|
var _a;
|
|
390
390
|
const body = helpers_1.Helpers.reqBody(this, 'login');
|
|
391
391
|
logger_1.logger.debug('Login request:', {
|
|
392
392
|
url: `${process.env.VESYNC_API_URL}/cloud/v1/user/login`,
|
|
393
393
|
body
|
|
394
394
|
});
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
395
|
+
for (let attempt = 0; attempt < retryAttempts; attempt++) {
|
|
396
|
+
try {
|
|
397
|
+
const [response, status] = await helpers_1.Helpers.callApi('/cloud/v1/user/login', 'post', body, {}, this);
|
|
398
|
+
logger_1.logger.debug('Login response:', { status, response });
|
|
399
|
+
if ((_a = response === null || response === void 0 ? void 0 : response.result) === null || _a === void 0 ? void 0 : _a.token) {
|
|
400
|
+
this.token = response.result.token;
|
|
401
|
+
this.accountId = response.result.accountID;
|
|
402
|
+
this.countryCode = response.result.countryCode;
|
|
403
|
+
this.enabled = true;
|
|
404
|
+
return true;
|
|
405
|
+
}
|
|
406
|
+
// If we reach here, login failed but didn't throw an error
|
|
407
|
+
const delay = initialDelayMs * Math.pow(2, attempt);
|
|
408
|
+
logger_1.logger.debug(`Login attempt ${attempt + 1} failed, retrying in ${delay}ms...`);
|
|
409
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
410
|
+
}
|
|
411
|
+
catch (error) {
|
|
412
|
+
if (attempt === retryAttempts - 1) {
|
|
413
|
+
logger_1.logger.error('Login error after all retry attempts:', error);
|
|
414
|
+
return false;
|
|
415
|
+
}
|
|
416
|
+
const delay = initialDelayMs * Math.pow(2, attempt);
|
|
417
|
+
logger_1.logger.debug(`Login attempt ${attempt + 1} failed with error, retrying in ${delay}ms...`, error);
|
|
418
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
404
419
|
}
|
|
405
|
-
logger_1.logger.error('Unable to login with supplied credentials');
|
|
406
|
-
return false;
|
|
407
|
-
}
|
|
408
|
-
catch (error) {
|
|
409
|
-
logger_1.logger.error('Login error:', error);
|
|
410
|
-
return false;
|
|
411
420
|
}
|
|
421
|
+
logger_1.logger.error('Unable to login with supplied credentials after all retry attempts');
|
|
422
|
+
return false;
|
|
412
423
|
}
|
|
413
424
|
/**
|
|
414
425
|
* Test if update interval has been exceeded
|
package/package.json
CHANGED
package/src/lib/helpers.ts
CHANGED
|
@@ -19,7 +19,7 @@ export function setApiBaseUrl(url: string): void {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export const API_RATE_LIMIT = 30;
|
|
22
|
-
export const API_TIMEOUT =
|
|
22
|
+
export const API_TIMEOUT = 15000;
|
|
23
23
|
|
|
24
24
|
export const APP_VERSION = '2.8.6';
|
|
25
25
|
export const PHONE_BRAND = 'SM N9005';
|
|
@@ -233,11 +233,8 @@ export class Helpers {
|
|
|
233
233
|
}
|
|
234
234
|
return [responseData, error.response.status];
|
|
235
235
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
} else {
|
|
239
|
-
logger.error('API call failed:', error.code, error.message);
|
|
240
|
-
}
|
|
236
|
+
|
|
237
|
+
logger.error('API call failed:', error.code, error.message);
|
|
241
238
|
return [null, 0];
|
|
242
239
|
}
|
|
243
240
|
}
|
package/src/lib/vesync.ts
CHANGED
|
@@ -469,38 +469,52 @@ export class VeSync {
|
|
|
469
469
|
/**
|
|
470
470
|
* Login to VeSync server
|
|
471
471
|
*/
|
|
472
|
-
async login(): Promise<boolean> {
|
|
472
|
+
async login(retryAttempts: number = 3, initialDelayMs: number = 1000): Promise<boolean> {
|
|
473
473
|
const body = Helpers.reqBody(this, 'login');
|
|
474
474
|
logger.debug('Login request:', {
|
|
475
475
|
url: `${process.env.VESYNC_API_URL}/cloud/v1/user/login`,
|
|
476
476
|
body
|
|
477
477
|
});
|
|
478
478
|
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
479
|
+
for (let attempt = 0; attempt < retryAttempts; attempt++) {
|
|
480
|
+
try {
|
|
481
|
+
const [response, status] = await Helpers.callApi(
|
|
482
|
+
'/cloud/v1/user/login',
|
|
483
|
+
'post',
|
|
484
|
+
body,
|
|
485
|
+
{},
|
|
486
|
+
this
|
|
487
|
+
);
|
|
488
|
+
|
|
489
|
+
logger.debug('Login response:', { status, response });
|
|
490
|
+
|
|
491
|
+
if (response?.result?.token) {
|
|
492
|
+
this.token = response.result.token;
|
|
493
|
+
this.accountId = response.result.accountID;
|
|
494
|
+
this.countryCode = response.result.countryCode;
|
|
495
|
+
this.enabled = true;
|
|
496
|
+
return true;
|
|
497
|
+
}
|
|
489
498
|
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
499
|
+
// If we reach here, login failed but didn't throw an error
|
|
500
|
+
const delay = initialDelayMs * Math.pow(2, attempt);
|
|
501
|
+
logger.debug(`Login attempt ${attempt + 1} failed, retrying in ${delay}ms...`);
|
|
502
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
503
|
+
|
|
504
|
+
} catch (error) {
|
|
505
|
+
if (attempt === retryAttempts - 1) {
|
|
506
|
+
logger.error('Login error after all retry attempts:', error);
|
|
507
|
+
return false;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
const delay = initialDelayMs * Math.pow(2, attempt);
|
|
511
|
+
logger.debug(`Login attempt ${attempt + 1} failed with error, retrying in ${delay}ms...`, error);
|
|
512
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
496
513
|
}
|
|
497
|
-
|
|
498
|
-
logger.error('Unable to login with supplied credentials');
|
|
499
|
-
return false;
|
|
500
|
-
} catch (error) {
|
|
501
|
-
logger.error('Login error:', error);
|
|
502
|
-
return false;
|
|
503
514
|
}
|
|
515
|
+
|
|
516
|
+
logger.error('Unable to login with supplied credentials after all retry attempts');
|
|
517
|
+
return false;
|
|
504
518
|
}
|
|
505
519
|
|
|
506
520
|
/**
|