@larksuiteoapi/node-sdk 1.58.0 → 1.60.0
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/es/index.js +17 -4
- package/lib/index.js +17 -4
- package/package.json +3 -3
- package/types/index.d.ts +1 -0
package/es/index.js
CHANGED
|
@@ -85285,6 +85285,7 @@ var HttpStatusCode;
|
|
|
85285
85285
|
class WSClient {
|
|
85286
85286
|
constructor(params) {
|
|
85287
85287
|
this.wsConfig = new WSConfig();
|
|
85288
|
+
this.reconnectGeneration = 0;
|
|
85288
85289
|
this.isConnecting = false;
|
|
85289
85290
|
this.reconnectInfo = {
|
|
85290
85291
|
lastConnectTime: 0,
|
|
@@ -85376,11 +85377,13 @@ class WSClient {
|
|
|
85376
85377
|
}
|
|
85377
85378
|
reConnect(isStart = false) {
|
|
85378
85379
|
return __awaiter(this, void 0, void 0, function* () {
|
|
85379
|
-
if (this.isConnecting) {
|
|
85380
|
+
if (this.isConnecting && !isStart) {
|
|
85380
85381
|
this.logger.debug('[ws]', 'repeat connection');
|
|
85381
85382
|
return;
|
|
85382
85383
|
}
|
|
85383
85384
|
this.isConnecting = true;
|
|
85385
|
+
// Invalidate any in-flight reconnect loops from previous sessions
|
|
85386
|
+
const currentGeneration = ++this.reconnectGeneration;
|
|
85384
85387
|
const tryConnect = () => {
|
|
85385
85388
|
this.reconnectInfo.lastConnectTime = Date.now();
|
|
85386
85389
|
return this.pullConnectConfig()
|
|
@@ -85396,14 +85399,14 @@ class WSClient {
|
|
|
85396
85399
|
if (this.pingInterval) {
|
|
85397
85400
|
clearTimeout(this.pingInterval);
|
|
85398
85401
|
}
|
|
85402
|
+
if (this.reconnectInterval) {
|
|
85403
|
+
clearTimeout(this.reconnectInterval);
|
|
85404
|
+
}
|
|
85399
85405
|
const wsInstance = this.wsConfig.getWSInstance();
|
|
85400
85406
|
if (isStart) {
|
|
85401
85407
|
if (wsInstance) {
|
|
85402
85408
|
wsInstance === null || wsInstance === void 0 ? void 0 : wsInstance.terminate();
|
|
85403
85409
|
}
|
|
85404
|
-
if (this.reconnectInterval) {
|
|
85405
|
-
clearTimeout(this.reconnectInterval);
|
|
85406
|
-
}
|
|
85407
85410
|
let isSuccess = false;
|
|
85408
85411
|
try {
|
|
85409
85412
|
isSuccess = yield tryConnect();
|
|
@@ -85431,8 +85434,16 @@ class WSClient {
|
|
|
85431
85434
|
this.reconnectInterval = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
85432
85435
|
(function loopReConnect(count) {
|
|
85433
85436
|
return __awaiter(this, void 0, void 0, function* () {
|
|
85437
|
+
// Stale loop — a newer reConnect session has started
|
|
85438
|
+
if (currentGeneration !== this.reconnectGeneration) {
|
|
85439
|
+
return;
|
|
85440
|
+
}
|
|
85434
85441
|
count++;
|
|
85435
85442
|
const isSuccess = yield tryConnect();
|
|
85443
|
+
// Re-check after async operation in case a new session started
|
|
85444
|
+
if (currentGeneration !== this.reconnectGeneration) {
|
|
85445
|
+
return;
|
|
85446
|
+
}
|
|
85436
85447
|
// if reconnectCount < 0, the reconnect time is infinite
|
|
85437
85448
|
if (isSuccess) {
|
|
85438
85449
|
this.logger.debug('[ws]', 'reconnect success');
|
|
@@ -85578,6 +85589,8 @@ class WSClient {
|
|
|
85578
85589
|
*/
|
|
85579
85590
|
close(params = {}) {
|
|
85580
85591
|
const { force = false } = params;
|
|
85592
|
+
// Invalidate any in-flight reconnect loops
|
|
85593
|
+
this.reconnectGeneration++;
|
|
85581
85594
|
if (this.pingInterval) {
|
|
85582
85595
|
clearTimeout(this.pingInterval);
|
|
85583
85596
|
this.pingInterval = undefined;
|
package/lib/index.js
CHANGED
|
@@ -85300,6 +85300,7 @@ var HttpStatusCode;
|
|
|
85300
85300
|
class WSClient {
|
|
85301
85301
|
constructor(params) {
|
|
85302
85302
|
this.wsConfig = new WSConfig();
|
|
85303
|
+
this.reconnectGeneration = 0;
|
|
85303
85304
|
this.isConnecting = false;
|
|
85304
85305
|
this.reconnectInfo = {
|
|
85305
85306
|
lastConnectTime: 0,
|
|
@@ -85391,11 +85392,13 @@ class WSClient {
|
|
|
85391
85392
|
}
|
|
85392
85393
|
reConnect(isStart = false) {
|
|
85393
85394
|
return __awaiter(this, void 0, void 0, function* () {
|
|
85394
|
-
if (this.isConnecting) {
|
|
85395
|
+
if (this.isConnecting && !isStart) {
|
|
85395
85396
|
this.logger.debug('[ws]', 'repeat connection');
|
|
85396
85397
|
return;
|
|
85397
85398
|
}
|
|
85398
85399
|
this.isConnecting = true;
|
|
85400
|
+
// Invalidate any in-flight reconnect loops from previous sessions
|
|
85401
|
+
const currentGeneration = ++this.reconnectGeneration;
|
|
85399
85402
|
const tryConnect = () => {
|
|
85400
85403
|
this.reconnectInfo.lastConnectTime = Date.now();
|
|
85401
85404
|
return this.pullConnectConfig()
|
|
@@ -85411,14 +85414,14 @@ class WSClient {
|
|
|
85411
85414
|
if (this.pingInterval) {
|
|
85412
85415
|
clearTimeout(this.pingInterval);
|
|
85413
85416
|
}
|
|
85417
|
+
if (this.reconnectInterval) {
|
|
85418
|
+
clearTimeout(this.reconnectInterval);
|
|
85419
|
+
}
|
|
85414
85420
|
const wsInstance = this.wsConfig.getWSInstance();
|
|
85415
85421
|
if (isStart) {
|
|
85416
85422
|
if (wsInstance) {
|
|
85417
85423
|
wsInstance === null || wsInstance === void 0 ? void 0 : wsInstance.terminate();
|
|
85418
85424
|
}
|
|
85419
|
-
if (this.reconnectInterval) {
|
|
85420
|
-
clearTimeout(this.reconnectInterval);
|
|
85421
|
-
}
|
|
85422
85425
|
let isSuccess = false;
|
|
85423
85426
|
try {
|
|
85424
85427
|
isSuccess = yield tryConnect();
|
|
@@ -85446,8 +85449,16 @@ class WSClient {
|
|
|
85446
85449
|
this.reconnectInterval = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
85447
85450
|
(function loopReConnect(count) {
|
|
85448
85451
|
return __awaiter(this, void 0, void 0, function* () {
|
|
85452
|
+
// Stale loop — a newer reConnect session has started
|
|
85453
|
+
if (currentGeneration !== this.reconnectGeneration) {
|
|
85454
|
+
return;
|
|
85455
|
+
}
|
|
85449
85456
|
count++;
|
|
85450
85457
|
const isSuccess = yield tryConnect();
|
|
85458
|
+
// Re-check after async operation in case a new session started
|
|
85459
|
+
if (currentGeneration !== this.reconnectGeneration) {
|
|
85460
|
+
return;
|
|
85461
|
+
}
|
|
85451
85462
|
// if reconnectCount < 0, the reconnect time is infinite
|
|
85452
85463
|
if (isSuccess) {
|
|
85453
85464
|
this.logger.debug('[ws]', 'reconnect success');
|
|
@@ -85593,6 +85604,8 @@ class WSClient {
|
|
|
85593
85604
|
*/
|
|
85594
85605
|
close(params = {}) {
|
|
85595
85606
|
const { force = false } = params;
|
|
85607
|
+
// Invalidate any in-flight reconnect loops
|
|
85608
|
+
this.reconnectGeneration++;
|
|
85596
85609
|
if (this.pingInterval) {
|
|
85597
85610
|
clearTimeout(this.pingInterval);
|
|
85598
85611
|
this.pingInterval = undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@larksuiteoapi/node-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.60.0",
|
|
4
4
|
"description": "larksuite open sdk for nodejs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"feishu",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"lodash.merge": "^4.6.2",
|
|
35
35
|
"lodash.pickby": "^4.6.0",
|
|
36
36
|
"protobufjs": "^7.2.6",
|
|
37
|
-
"qs": "^6.
|
|
38
|
-
"ws": "^8.
|
|
37
|
+
"qs": "^6.14.2",
|
|
38
|
+
"ws": "^8.19.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@koa/router": "^12.0.0",
|
package/types/index.d.ts
CHANGED
|
@@ -293056,6 +293056,7 @@ declare class WSClient {
|
|
|
293056
293056
|
private eventDispatcher?;
|
|
293057
293057
|
private pingInterval?;
|
|
293058
293058
|
private reconnectInterval?;
|
|
293059
|
+
private reconnectGeneration;
|
|
293059
293060
|
private isConnecting;
|
|
293060
293061
|
private reconnectInfo;
|
|
293061
293062
|
private agent?;
|