tsvesync 1.0.100 → 1.0.101
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.js +20 -7
- package/package.json +1 -1
- package/src/lib/helpers.ts +20 -8
package/dist/lib/helpers.js
CHANGED
|
@@ -452,28 +452,41 @@ class Helpers {
|
|
|
452
452
|
if (loginResponse.code === exports.CROSS_REGION_ERROR_CODE) {
|
|
453
453
|
logger_1.logger.debug('Cross-region error detected in Step 2, retrying with region change token...');
|
|
454
454
|
const { bizToken: regionChangeToken, countryCode: newCountryCode } = loginResponse.result || {};
|
|
455
|
-
if (regionChangeToken) {
|
|
456
|
-
// Retry Step 2 with region change token
|
|
455
|
+
if (regionChangeToken && newCountryCode) {
|
|
456
|
+
// Retry Step 2 with region change token on the SAME endpoint
|
|
457
|
+
// The region change token tells the server to handle the cross-region authentication
|
|
457
458
|
const retryBody = {
|
|
458
|
-
|
|
459
|
+
method: 'loginByAuthorizeCode4Vesync',
|
|
460
|
+
authorizeCode: authorizeCode,
|
|
461
|
+
acceptLanguage: 'en',
|
|
462
|
+
clientInfo: exports.CLIENT_INFO,
|
|
463
|
+
clientType: 'vesyncApp',
|
|
464
|
+
clientVersion: exports.CLIENT_VERSION,
|
|
465
|
+
debugMode: false,
|
|
466
|
+
emailSubscriptions: false,
|
|
467
|
+
osInfo: exports.PHONE_OS,
|
|
468
|
+
terminalId: terminalId,
|
|
469
|
+
timeZone: exports.DEFAULT_TZ,
|
|
470
|
+
userCountryCode: newCountryCode,
|
|
471
|
+
traceId: `APP${appId}${Math.floor(Date.now() / 1000)}`,
|
|
459
472
|
bizToken: regionChangeToken,
|
|
460
|
-
regionChange: 'last_region'
|
|
461
|
-
userCountryCode: newCountryCode || userCountryCode
|
|
473
|
+
regionChange: 'last_region'
|
|
462
474
|
};
|
|
463
475
|
logger_1.logger.debug('Retrying Step 2 with region change token...', {
|
|
464
476
|
newCountryCode,
|
|
465
|
-
|
|
477
|
+
currentEndpoint: getApiBaseUrl()
|
|
466
478
|
});
|
|
467
479
|
const [retryResponse, retryStatus] = await this.callApi('/user/api/accountManage/v1/loginByAuthorizeCode4Vesync', 'post', retryBody, step1Headers, manager);
|
|
468
|
-
setApiBaseUrl(originalUrl); // Restore original URL after retry
|
|
469
480
|
if (retryResponse && retryResponse.code === 0) {
|
|
470
481
|
const { token, accountID, countryCode } = retryResponse.result || {};
|
|
471
482
|
if (token && accountID) {
|
|
472
483
|
logger_1.logger.debug('Step 2 retry successful with region change');
|
|
484
|
+
setApiBaseUrl(originalUrl); // Restore original URL on success
|
|
473
485
|
return [true, token, accountID, countryCode || newCountryCode];
|
|
474
486
|
}
|
|
475
487
|
}
|
|
476
488
|
logger_1.logger.error('Step 2 retry failed:', retryResponse);
|
|
489
|
+
setApiBaseUrl(originalUrl); // Restore original URL on failure
|
|
477
490
|
return [false, null, null, null];
|
|
478
491
|
}
|
|
479
492
|
else {
|
package/package.json
CHANGED
package/src/lib/helpers.ts
CHANGED
|
@@ -583,18 +583,30 @@ export class Helpers {
|
|
|
583
583
|
|
|
584
584
|
const { bizToken: regionChangeToken, countryCode: newCountryCode } = loginResponse.result || {};
|
|
585
585
|
|
|
586
|
-
if (regionChangeToken) {
|
|
587
|
-
// Retry Step 2 with region change token
|
|
586
|
+
if (regionChangeToken && newCountryCode) {
|
|
587
|
+
// Retry Step 2 with region change token on the SAME endpoint
|
|
588
|
+
// The region change token tells the server to handle the cross-region authentication
|
|
588
589
|
const retryBody = {
|
|
589
|
-
|
|
590
|
+
method: 'loginByAuthorizeCode4Vesync',
|
|
591
|
+
authorizeCode: authorizeCode,
|
|
592
|
+
acceptLanguage: 'en',
|
|
593
|
+
clientInfo: CLIENT_INFO,
|
|
594
|
+
clientType: 'vesyncApp',
|
|
595
|
+
clientVersion: CLIENT_VERSION,
|
|
596
|
+
debugMode: false,
|
|
597
|
+
emailSubscriptions: false,
|
|
598
|
+
osInfo: PHONE_OS,
|
|
599
|
+
terminalId: terminalId,
|
|
600
|
+
timeZone: DEFAULT_TZ,
|
|
601
|
+
userCountryCode: newCountryCode,
|
|
602
|
+
traceId: `APP${appId}${Math.floor(Date.now() / 1000)}`,
|
|
590
603
|
bizToken: regionChangeToken,
|
|
591
|
-
regionChange: 'last_region'
|
|
592
|
-
userCountryCode: newCountryCode || userCountryCode
|
|
604
|
+
regionChange: 'last_region'
|
|
593
605
|
};
|
|
594
606
|
|
|
595
607
|
logger.debug('Retrying Step 2 with region change token...', {
|
|
596
608
|
newCountryCode,
|
|
597
|
-
|
|
609
|
+
currentEndpoint: getApiBaseUrl()
|
|
598
610
|
});
|
|
599
611
|
|
|
600
612
|
const [retryResponse, retryStatus] = await this.callApi(
|
|
@@ -605,17 +617,17 @@ export class Helpers {
|
|
|
605
617
|
manager
|
|
606
618
|
);
|
|
607
619
|
|
|
608
|
-
setApiBaseUrl(originalUrl); // Restore original URL after retry
|
|
609
|
-
|
|
610
620
|
if (retryResponse && retryResponse.code === 0) {
|
|
611
621
|
const { token, accountID, countryCode } = retryResponse.result || {};
|
|
612
622
|
if (token && accountID) {
|
|
613
623
|
logger.debug('Step 2 retry successful with region change');
|
|
624
|
+
setApiBaseUrl(originalUrl); // Restore original URL on success
|
|
614
625
|
return [true, token, accountID, countryCode || newCountryCode];
|
|
615
626
|
}
|
|
616
627
|
}
|
|
617
628
|
|
|
618
629
|
logger.error('Step 2 retry failed:', retryResponse);
|
|
630
|
+
setApiBaseUrl(originalUrl); // Restore original URL on failure
|
|
619
631
|
return [false, null, null, null];
|
|
620
632
|
} else {
|
|
621
633
|
logger.error('No region change token in cross-region error response');
|