tsvesync 1.0.99 → 1.0.100

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.
@@ -442,9 +442,9 @@ class Helpers {
442
442
  const step2Body = this.reqBodyAuthStep2(authorizeCode, bizToken, appId, terminalId, userCountryCode);
443
443
  logger_1.logger.debug('Step 2: Logging in with authorization code...');
444
444
  const [loginResponse, loginStatus] = await this.callApi('/user/api/accountManage/v1/loginByAuthorizeCode4Vesync', 'post', step2Body, step1Headers, manager);
445
- setApiBaseUrl(originalUrl); // Restore original URL
446
445
  if (!loginResponse || loginStatus !== 200) {
447
446
  logger_1.logger.error('Step 2 failed:', loginResponse);
447
+ setApiBaseUrl(originalUrl); // Restore original URL on failure
448
448
  return [false, null, null, null];
449
449
  }
450
450
  if (loginResponse.code !== 0) {
@@ -460,8 +460,12 @@ class Helpers {
460
460
  regionChange: 'last_region',
461
461
  userCountryCode: newCountryCode || userCountryCode
462
462
  };
463
- logger_1.logger.debug('Retrying Step 2 with region change token...');
463
+ logger_1.logger.debug('Retrying Step 2 with region change token...', {
464
+ newCountryCode,
465
+ hasRegionChangeToken: true
466
+ });
464
467
  const [retryResponse, retryStatus] = await this.callApi('/user/api/accountManage/v1/loginByAuthorizeCode4Vesync', 'post', retryBody, step1Headers, manager);
468
+ setApiBaseUrl(originalUrl); // Restore original URL after retry
465
469
  if (retryResponse && retryResponse.code === 0) {
466
470
  const { token, accountID, countryCode } = retryResponse.result || {};
467
471
  if (token && accountID) {
@@ -470,11 +474,17 @@ class Helpers {
470
474
  }
471
475
  }
472
476
  logger_1.logger.error('Step 2 retry failed:', retryResponse);
477
+ return [false, null, null, null];
478
+ }
479
+ else {
480
+ logger_1.logger.error('No region change token in cross-region error response');
473
481
  }
474
482
  }
475
483
  logger_1.logger.error('Step 2 error code:', loginResponse.code, 'message:', loginResponse.msg);
484
+ setApiBaseUrl(originalUrl); // Restore original URL on error
476
485
  return [false, null, null, null];
477
486
  }
487
+ setApiBaseUrl(originalUrl); // Restore original URL on success
478
488
  const { token, accountID, countryCode } = loginResponse.result || {};
479
489
  if (!token || !accountID) {
480
490
  logger_1.logger.error('Missing required fields in step 2 response:', loginResponse.result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsvesync",
3
- "version": "1.0.99",
3
+ "version": "1.0.100",
4
4
  "description": "A TypeScript library for interacting with VeSync smart home devices",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -570,10 +570,9 @@ export class Helpers {
570
570
  manager
571
571
  );
572
572
 
573
- setApiBaseUrl(originalUrl); // Restore original URL
574
-
575
573
  if (!loginResponse || loginStatus !== 200) {
576
574
  logger.error('Step 2 failed:', loginResponse);
575
+ setApiBaseUrl(originalUrl); // Restore original URL on failure
577
576
  return [false, null, null, null];
578
577
  }
579
578
 
@@ -593,7 +592,10 @@ export class Helpers {
593
592
  userCountryCode: newCountryCode || userCountryCode
594
593
  };
595
594
 
596
- logger.debug('Retrying Step 2 with region change token...');
595
+ logger.debug('Retrying Step 2 with region change token...', {
596
+ newCountryCode,
597
+ hasRegionChangeToken: true
598
+ });
597
599
 
598
600
  const [retryResponse, retryStatus] = await this.callApi(
599
601
  '/user/api/accountManage/v1/loginByAuthorizeCode4Vesync',
@@ -603,6 +605,8 @@ export class Helpers {
603
605
  manager
604
606
  );
605
607
 
608
+ setApiBaseUrl(originalUrl); // Restore original URL after retry
609
+
606
610
  if (retryResponse && retryResponse.code === 0) {
607
611
  const { token, accountID, countryCode } = retryResponse.result || {};
608
612
  if (token && accountID) {
@@ -612,13 +616,19 @@ export class Helpers {
612
616
  }
613
617
 
614
618
  logger.error('Step 2 retry failed:', retryResponse);
619
+ return [false, null, null, null];
620
+ } else {
621
+ logger.error('No region change token in cross-region error response');
615
622
  }
616
623
  }
617
624
 
618
625
  logger.error('Step 2 error code:', loginResponse.code, 'message:', loginResponse.msg);
626
+ setApiBaseUrl(originalUrl); // Restore original URL on error
619
627
  return [false, null, null, null];
620
628
  }
621
629
 
630
+ setApiBaseUrl(originalUrl); // Restore original URL on success
631
+
622
632
  const { token, accountID, countryCode } = loginResponse.result || {};
623
633
 
624
634
  if (!token || !accountID) {