@larksuiteoapi/node-sdk 1.23.0 → 1.24.0-beta.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 +1102 -3
- package/lib/index.js +1104 -2
- package/package.json +6 -3
- package/types/index.d.ts +33 -2
package/lib/index.js
CHANGED
|
@@ -22,6 +22,8 @@ var identity = require('lodash.identity');
|
|
|
22
22
|
var pickBy = require('lodash.pickby');
|
|
23
23
|
var fs = require('fs');
|
|
24
24
|
var merge = require('lodash.merge');
|
|
25
|
+
var qs = require('querystring');
|
|
26
|
+
var WebSocket = require('ws');
|
|
25
27
|
|
|
26
28
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
27
29
|
|
|
@@ -33,6 +35,8 @@ var identity__default = /*#__PURE__*/_interopDefaultLegacy(identity);
|
|
|
33
35
|
var pickBy__default = /*#__PURE__*/_interopDefaultLegacy(pickBy);
|
|
34
36
|
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
35
37
|
var merge__default = /*#__PURE__*/_interopDefaultLegacy(merge);
|
|
38
|
+
var qs__default = /*#__PURE__*/_interopDefaultLegacy(qs);
|
|
39
|
+
var WebSocket__default = /*#__PURE__*/_interopDefaultLegacy(WebSocket);
|
|
36
40
|
|
|
37
41
|
/******************************************************************************
|
|
38
42
|
Copyright (c) Microsoft Corporation.
|
|
@@ -57161,10 +57165,11 @@ class EventDispatcher {
|
|
|
57161
57165
|
});
|
|
57162
57166
|
return this;
|
|
57163
57167
|
}
|
|
57164
|
-
invoke(data) {
|
|
57168
|
+
invoke(data, params) {
|
|
57165
57169
|
var _a, _b;
|
|
57166
57170
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57167
|
-
|
|
57171
|
+
const needCheck = get__default["default"](params, 'needCheck', true);
|
|
57172
|
+
if (needCheck && !((_a = this.requestHandle) === null || _a === void 0 ? void 0 : _a.checkIsEventValidated(data))) {
|
|
57168
57173
|
this.logger.warn('verification failed event');
|
|
57169
57174
|
return undefined;
|
|
57170
57175
|
}
|
|
@@ -57457,12 +57462,1109 @@ var messageCard = /*#__PURE__*/Object.freeze({
|
|
|
57457
57462
|
defaultCard: defaultCard
|
|
57458
57463
|
});
|
|
57459
57464
|
|
|
57465
|
+
// @ts-nocheck
|
|
57466
|
+
/*eslint-disable block-scoped-var, id-length, no-control-regex, no-magic-numbers, no-prototype-builtins, no-redeclare, no-shadow, no-var, sort-vars*/
|
|
57467
|
+
const $protobuf = require("protobufjs/minimal");
|
|
57468
|
+
|
|
57469
|
+
$protobuf.util.Long = undefined;
|
|
57470
|
+
$protobuf.configure();
|
|
57471
|
+
|
|
57472
|
+
// Common aliases
|
|
57473
|
+
const $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
|
|
57474
|
+
|
|
57475
|
+
// Exported root namespace
|
|
57476
|
+
const $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {});
|
|
57477
|
+
|
|
57478
|
+
const pbbp2 = $root.pbbp2 = (() => {
|
|
57479
|
+
/**
|
|
57480
|
+
* Namespace pbbp2.
|
|
57481
|
+
* @exports pbbp2
|
|
57482
|
+
* @namespace
|
|
57483
|
+
*/
|
|
57484
|
+
const pbbp2 = {};
|
|
57485
|
+
|
|
57486
|
+
pbbp2.Header = (function() {
|
|
57487
|
+
|
|
57488
|
+
/**
|
|
57489
|
+
* Properties of a Header.
|
|
57490
|
+
* @memberof pbbp2
|
|
57491
|
+
* @interface IHeader
|
|
57492
|
+
* @property {string} key Header key
|
|
57493
|
+
* @property {string} value Header value
|
|
57494
|
+
*/
|
|
57495
|
+
|
|
57496
|
+
/**
|
|
57497
|
+
* Constructs a new Header.
|
|
57498
|
+
* @memberof pbbp2
|
|
57499
|
+
* @classdesc Represents a Header.
|
|
57500
|
+
* @implements IHeader
|
|
57501
|
+
* @constructor
|
|
57502
|
+
* @param {pbbp2.IHeader=} [properties] Properties to set
|
|
57503
|
+
*/
|
|
57504
|
+
function Header(properties) {
|
|
57505
|
+
if (properties)
|
|
57506
|
+
for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i)
|
|
57507
|
+
if (properties[keys[i]] != null)
|
|
57508
|
+
this[keys[i]] = properties[keys[i]];
|
|
57509
|
+
}
|
|
57510
|
+
|
|
57511
|
+
/**
|
|
57512
|
+
* Header key.
|
|
57513
|
+
* @member {string} key
|
|
57514
|
+
* @memberof pbbp2.Header
|
|
57515
|
+
* @instance
|
|
57516
|
+
*/
|
|
57517
|
+
Header.prototype.key = "";
|
|
57518
|
+
|
|
57519
|
+
/**
|
|
57520
|
+
* Header value.
|
|
57521
|
+
* @member {string} value
|
|
57522
|
+
* @memberof pbbp2.Header
|
|
57523
|
+
* @instance
|
|
57524
|
+
*/
|
|
57525
|
+
Header.prototype.value = "";
|
|
57526
|
+
|
|
57527
|
+
/**
|
|
57528
|
+
* Creates a new Header instance using the specified properties.
|
|
57529
|
+
* @function create
|
|
57530
|
+
* @memberof pbbp2.Header
|
|
57531
|
+
* @static
|
|
57532
|
+
* @param {pbbp2.IHeader=} [properties] Properties to set
|
|
57533
|
+
* @returns {pbbp2.Header} Header instance
|
|
57534
|
+
*/
|
|
57535
|
+
Header.create = function create(properties) {
|
|
57536
|
+
return new Header(properties);
|
|
57537
|
+
};
|
|
57538
|
+
|
|
57539
|
+
/**
|
|
57540
|
+
* Encodes the specified Header message. Does not implicitly {@link pbbp2.Header.verify|verify} messages.
|
|
57541
|
+
* @function encode
|
|
57542
|
+
* @memberof pbbp2.Header
|
|
57543
|
+
* @static
|
|
57544
|
+
* @param {pbbp2.IHeader} message Header message or plain object to encode
|
|
57545
|
+
* @param {$protobuf.Writer} [writer] Writer to encode to
|
|
57546
|
+
* @returns {$protobuf.Writer} Writer
|
|
57547
|
+
*/
|
|
57548
|
+
Header.encode = function encode(message, writer) {
|
|
57549
|
+
if (!writer)
|
|
57550
|
+
writer = $Writer.create();
|
|
57551
|
+
writer.uint32(/* id 1, wireType 2 =*/10).string(message.key);
|
|
57552
|
+
writer.uint32(/* id 2, wireType 2 =*/18).string(message.value);
|
|
57553
|
+
return writer;
|
|
57554
|
+
};
|
|
57555
|
+
|
|
57556
|
+
/**
|
|
57557
|
+
* Encodes the specified Header message, length delimited. Does not implicitly {@link pbbp2.Header.verify|verify} messages.
|
|
57558
|
+
* @function encodeDelimited
|
|
57559
|
+
* @memberof pbbp2.Header
|
|
57560
|
+
* @static
|
|
57561
|
+
* @param {pbbp2.IHeader} message Header message or plain object to encode
|
|
57562
|
+
* @param {$protobuf.Writer} [writer] Writer to encode to
|
|
57563
|
+
* @returns {$protobuf.Writer} Writer
|
|
57564
|
+
*/
|
|
57565
|
+
Header.encodeDelimited = function encodeDelimited(message, writer) {
|
|
57566
|
+
return this.encode(message, writer).ldelim();
|
|
57567
|
+
};
|
|
57568
|
+
|
|
57569
|
+
/**
|
|
57570
|
+
* Decodes a Header message from the specified reader or buffer.
|
|
57571
|
+
* @function decode
|
|
57572
|
+
* @memberof pbbp2.Header
|
|
57573
|
+
* @static
|
|
57574
|
+
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
|
|
57575
|
+
* @param {number} [length] Message length if known beforehand
|
|
57576
|
+
* @returns {pbbp2.Header} Header
|
|
57577
|
+
* @throws {Error} If the payload is not a reader or valid buffer
|
|
57578
|
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
57579
|
+
*/
|
|
57580
|
+
Header.decode = function decode(reader, length) {
|
|
57581
|
+
if (!(reader instanceof $Reader))
|
|
57582
|
+
reader = $Reader.create(reader);
|
|
57583
|
+
let end = length === undefined ? reader.len : reader.pos + length, message = new $root.pbbp2.Header();
|
|
57584
|
+
while (reader.pos < end) {
|
|
57585
|
+
let tag = reader.uint32();
|
|
57586
|
+
switch (tag >>> 3) {
|
|
57587
|
+
case 1: {
|
|
57588
|
+
message.key = reader.string();
|
|
57589
|
+
break;
|
|
57590
|
+
}
|
|
57591
|
+
case 2: {
|
|
57592
|
+
message.value = reader.string();
|
|
57593
|
+
break;
|
|
57594
|
+
}
|
|
57595
|
+
default:
|
|
57596
|
+
reader.skipType(tag & 7);
|
|
57597
|
+
break;
|
|
57598
|
+
}
|
|
57599
|
+
}
|
|
57600
|
+
if (!message.hasOwnProperty("key"))
|
|
57601
|
+
throw $util.ProtocolError("missing required 'key'", { instance: message });
|
|
57602
|
+
if (!message.hasOwnProperty("value"))
|
|
57603
|
+
throw $util.ProtocolError("missing required 'value'", { instance: message });
|
|
57604
|
+
return message;
|
|
57605
|
+
};
|
|
57606
|
+
|
|
57607
|
+
/**
|
|
57608
|
+
* Decodes a Header message from the specified reader or buffer, length delimited.
|
|
57609
|
+
* @function decodeDelimited
|
|
57610
|
+
* @memberof pbbp2.Header
|
|
57611
|
+
* @static
|
|
57612
|
+
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
|
|
57613
|
+
* @returns {pbbp2.Header} Header
|
|
57614
|
+
* @throws {Error} If the payload is not a reader or valid buffer
|
|
57615
|
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
57616
|
+
*/
|
|
57617
|
+
Header.decodeDelimited = function decodeDelimited(reader) {
|
|
57618
|
+
if (!(reader instanceof $Reader))
|
|
57619
|
+
reader = new $Reader(reader);
|
|
57620
|
+
return this.decode(reader, reader.uint32());
|
|
57621
|
+
};
|
|
57622
|
+
|
|
57623
|
+
/**
|
|
57624
|
+
* Verifies a Header message.
|
|
57625
|
+
* @function verify
|
|
57626
|
+
* @memberof pbbp2.Header
|
|
57627
|
+
* @static
|
|
57628
|
+
* @param {Object.<string,*>} message Plain object to verify
|
|
57629
|
+
* @returns {string|null} `null` if valid, otherwise the reason why it is not
|
|
57630
|
+
*/
|
|
57631
|
+
Header.verify = function verify(message) {
|
|
57632
|
+
if (typeof message !== "object" || message === null)
|
|
57633
|
+
return "object expected";
|
|
57634
|
+
if (!$util.isString(message.key))
|
|
57635
|
+
return "key: string expected";
|
|
57636
|
+
if (!$util.isString(message.value))
|
|
57637
|
+
return "value: string expected";
|
|
57638
|
+
return null;
|
|
57639
|
+
};
|
|
57640
|
+
|
|
57641
|
+
/**
|
|
57642
|
+
* Creates a Header message from a plain object. Also converts values to their respective internal types.
|
|
57643
|
+
* @function fromObject
|
|
57644
|
+
* @memberof pbbp2.Header
|
|
57645
|
+
* @static
|
|
57646
|
+
* @param {Object.<string,*>} object Plain object
|
|
57647
|
+
* @returns {pbbp2.Header} Header
|
|
57648
|
+
*/
|
|
57649
|
+
Header.fromObject = function fromObject(object) {
|
|
57650
|
+
if (object instanceof $root.pbbp2.Header)
|
|
57651
|
+
return object;
|
|
57652
|
+
let message = new $root.pbbp2.Header();
|
|
57653
|
+
if (object.key != null)
|
|
57654
|
+
message.key = String(object.key);
|
|
57655
|
+
if (object.value != null)
|
|
57656
|
+
message.value = String(object.value);
|
|
57657
|
+
return message;
|
|
57658
|
+
};
|
|
57659
|
+
|
|
57660
|
+
/**
|
|
57661
|
+
* Creates a plain object from a Header message. Also converts values to other types if specified.
|
|
57662
|
+
* @function toObject
|
|
57663
|
+
* @memberof pbbp2.Header
|
|
57664
|
+
* @static
|
|
57665
|
+
* @param {pbbp2.Header} message Header
|
|
57666
|
+
* @param {$protobuf.IConversionOptions} [options] Conversion options
|
|
57667
|
+
* @returns {Object.<string,*>} Plain object
|
|
57668
|
+
*/
|
|
57669
|
+
Header.toObject = function toObject(message, options) {
|
|
57670
|
+
if (!options)
|
|
57671
|
+
options = {};
|
|
57672
|
+
let object = {};
|
|
57673
|
+
if (options.defaults) {
|
|
57674
|
+
object.key = "";
|
|
57675
|
+
object.value = "";
|
|
57676
|
+
}
|
|
57677
|
+
if (message.key != null && message.hasOwnProperty("key"))
|
|
57678
|
+
object.key = message.key;
|
|
57679
|
+
if (message.value != null && message.hasOwnProperty("value"))
|
|
57680
|
+
object.value = message.value;
|
|
57681
|
+
return object;
|
|
57682
|
+
};
|
|
57683
|
+
|
|
57684
|
+
/**
|
|
57685
|
+
* Converts this Header to JSON.
|
|
57686
|
+
* @function toJSON
|
|
57687
|
+
* @memberof pbbp2.Header
|
|
57688
|
+
* @instance
|
|
57689
|
+
* @returns {Object.<string,*>} JSON object
|
|
57690
|
+
*/
|
|
57691
|
+
Header.prototype.toJSON = function toJSON() {
|
|
57692
|
+
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
|
|
57693
|
+
};
|
|
57694
|
+
|
|
57695
|
+
/**
|
|
57696
|
+
* Gets the default type url for Header
|
|
57697
|
+
* @function getTypeUrl
|
|
57698
|
+
* @memberof pbbp2.Header
|
|
57699
|
+
* @static
|
|
57700
|
+
* @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
|
|
57701
|
+
* @returns {string} The default type url
|
|
57702
|
+
*/
|
|
57703
|
+
Header.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
|
|
57704
|
+
if (typeUrlPrefix === undefined) {
|
|
57705
|
+
typeUrlPrefix = "type.googleapis.com";
|
|
57706
|
+
}
|
|
57707
|
+
return typeUrlPrefix + "/pbbp2.Header";
|
|
57708
|
+
};
|
|
57709
|
+
|
|
57710
|
+
return Header;
|
|
57711
|
+
})();
|
|
57712
|
+
|
|
57713
|
+
pbbp2.Frame = (function() {
|
|
57714
|
+
|
|
57715
|
+
/**
|
|
57716
|
+
* Properties of a Frame.
|
|
57717
|
+
* @memberof pbbp2
|
|
57718
|
+
* @interface IFrame
|
|
57719
|
+
* @property {number} SeqID Frame SeqID
|
|
57720
|
+
* @property {number} LogID Frame LogID
|
|
57721
|
+
* @property {number} service Frame service
|
|
57722
|
+
* @property {number} method Frame method
|
|
57723
|
+
* @property {Array.<pbbp2.IHeader>|null} [headers] Frame headers
|
|
57724
|
+
* @property {string|null} [payloadEncoding] Frame payloadEncoding
|
|
57725
|
+
* @property {string|null} [payloadType] Frame payloadType
|
|
57726
|
+
* @property {Uint8Array|null} [payload] Frame payload
|
|
57727
|
+
* @property {string|null} [LogIDNew] Frame LogIDNew
|
|
57728
|
+
*/
|
|
57729
|
+
|
|
57730
|
+
/**
|
|
57731
|
+
* Constructs a new Frame.
|
|
57732
|
+
* @memberof pbbp2
|
|
57733
|
+
* @classdesc Represents a Frame.
|
|
57734
|
+
* @implements IFrame
|
|
57735
|
+
* @constructor
|
|
57736
|
+
* @param {pbbp2.IFrame=} [properties] Properties to set
|
|
57737
|
+
*/
|
|
57738
|
+
function Frame(properties) {
|
|
57739
|
+
this.headers = [];
|
|
57740
|
+
if (properties)
|
|
57741
|
+
for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i)
|
|
57742
|
+
if (properties[keys[i]] != null)
|
|
57743
|
+
this[keys[i]] = properties[keys[i]];
|
|
57744
|
+
}
|
|
57745
|
+
|
|
57746
|
+
/**
|
|
57747
|
+
* Frame SeqID.
|
|
57748
|
+
* @member {number} SeqID
|
|
57749
|
+
* @memberof pbbp2.Frame
|
|
57750
|
+
* @instance
|
|
57751
|
+
*/
|
|
57752
|
+
Frame.prototype.SeqID = $util.Long ? $util.Long.fromBits(0,0,true) : 0;
|
|
57753
|
+
|
|
57754
|
+
/**
|
|
57755
|
+
* Frame LogID.
|
|
57756
|
+
* @member {number} LogID
|
|
57757
|
+
* @memberof pbbp2.Frame
|
|
57758
|
+
* @instance
|
|
57759
|
+
*/
|
|
57760
|
+
Frame.prototype.LogID = $util.Long ? $util.Long.fromBits(0,0,true) : 0;
|
|
57761
|
+
|
|
57762
|
+
/**
|
|
57763
|
+
* Frame service.
|
|
57764
|
+
* @member {number} service
|
|
57765
|
+
* @memberof pbbp2.Frame
|
|
57766
|
+
* @instance
|
|
57767
|
+
*/
|
|
57768
|
+
Frame.prototype.service = 0;
|
|
57769
|
+
|
|
57770
|
+
/**
|
|
57771
|
+
* Frame method.
|
|
57772
|
+
* @member {number} method
|
|
57773
|
+
* @memberof pbbp2.Frame
|
|
57774
|
+
* @instance
|
|
57775
|
+
*/
|
|
57776
|
+
Frame.prototype.method = 0;
|
|
57777
|
+
|
|
57778
|
+
/**
|
|
57779
|
+
* Frame headers.
|
|
57780
|
+
* @member {Array.<pbbp2.IHeader>} headers
|
|
57781
|
+
* @memberof pbbp2.Frame
|
|
57782
|
+
* @instance
|
|
57783
|
+
*/
|
|
57784
|
+
Frame.prototype.headers = $util.emptyArray;
|
|
57785
|
+
|
|
57786
|
+
/**
|
|
57787
|
+
* Frame payloadEncoding.
|
|
57788
|
+
* @member {string} payloadEncoding
|
|
57789
|
+
* @memberof pbbp2.Frame
|
|
57790
|
+
* @instance
|
|
57791
|
+
*/
|
|
57792
|
+
Frame.prototype.payloadEncoding = "";
|
|
57793
|
+
|
|
57794
|
+
/**
|
|
57795
|
+
* Frame payloadType.
|
|
57796
|
+
* @member {string} payloadType
|
|
57797
|
+
* @memberof pbbp2.Frame
|
|
57798
|
+
* @instance
|
|
57799
|
+
*/
|
|
57800
|
+
Frame.prototype.payloadType = "";
|
|
57801
|
+
|
|
57802
|
+
/**
|
|
57803
|
+
* Frame payload.
|
|
57804
|
+
* @member {Uint8Array} payload
|
|
57805
|
+
* @memberof pbbp2.Frame
|
|
57806
|
+
* @instance
|
|
57807
|
+
*/
|
|
57808
|
+
Frame.prototype.payload = $util.newBuffer([]);
|
|
57809
|
+
|
|
57810
|
+
/**
|
|
57811
|
+
* Frame LogIDNew.
|
|
57812
|
+
* @member {string} LogIDNew
|
|
57813
|
+
* @memberof pbbp2.Frame
|
|
57814
|
+
* @instance
|
|
57815
|
+
*/
|
|
57816
|
+
Frame.prototype.LogIDNew = "";
|
|
57817
|
+
|
|
57818
|
+
/**
|
|
57819
|
+
* Creates a new Frame instance using the specified properties.
|
|
57820
|
+
* @function create
|
|
57821
|
+
* @memberof pbbp2.Frame
|
|
57822
|
+
* @static
|
|
57823
|
+
* @param {pbbp2.IFrame=} [properties] Properties to set
|
|
57824
|
+
* @returns {pbbp2.Frame} Frame instance
|
|
57825
|
+
*/
|
|
57826
|
+
Frame.create = function create(properties) {
|
|
57827
|
+
return new Frame(properties);
|
|
57828
|
+
};
|
|
57829
|
+
|
|
57830
|
+
/**
|
|
57831
|
+
* Encodes the specified Frame message. Does not implicitly {@link pbbp2.Frame.verify|verify} messages.
|
|
57832
|
+
* @function encode
|
|
57833
|
+
* @memberof pbbp2.Frame
|
|
57834
|
+
* @static
|
|
57835
|
+
* @param {pbbp2.IFrame} message Frame message or plain object to encode
|
|
57836
|
+
* @param {$protobuf.Writer} [writer] Writer to encode to
|
|
57837
|
+
* @returns {$protobuf.Writer} Writer
|
|
57838
|
+
*/
|
|
57839
|
+
Frame.encode = function encode(message, writer) {
|
|
57840
|
+
if (!writer)
|
|
57841
|
+
writer = $Writer.create();
|
|
57842
|
+
writer.uint32(/* id 1, wireType 0 =*/8).uint64(message.SeqID);
|
|
57843
|
+
writer.uint32(/* id 2, wireType 0 =*/16).uint64(message.LogID);
|
|
57844
|
+
writer.uint32(/* id 3, wireType 0 =*/24).int32(message.service);
|
|
57845
|
+
writer.uint32(/* id 4, wireType 0 =*/32).int32(message.method);
|
|
57846
|
+
if (message.headers != null && message.headers.length)
|
|
57847
|
+
for (let i = 0; i < message.headers.length; ++i)
|
|
57848
|
+
$root.pbbp2.Header.encode(message.headers[i], writer.uint32(/* id 5, wireType 2 =*/42).fork()).ldelim();
|
|
57849
|
+
if (message.payloadEncoding != null && Object.hasOwnProperty.call(message, "payloadEncoding"))
|
|
57850
|
+
writer.uint32(/* id 6, wireType 2 =*/50).string(message.payloadEncoding);
|
|
57851
|
+
if (message.payloadType != null && Object.hasOwnProperty.call(message, "payloadType"))
|
|
57852
|
+
writer.uint32(/* id 7, wireType 2 =*/58).string(message.payloadType);
|
|
57853
|
+
if (message.payload != null && Object.hasOwnProperty.call(message, "payload"))
|
|
57854
|
+
writer.uint32(/* id 8, wireType 2 =*/66).bytes(message.payload);
|
|
57855
|
+
if (message.LogIDNew != null && Object.hasOwnProperty.call(message, "LogIDNew"))
|
|
57856
|
+
writer.uint32(/* id 9, wireType 2 =*/74).string(message.LogIDNew);
|
|
57857
|
+
return writer;
|
|
57858
|
+
};
|
|
57859
|
+
|
|
57860
|
+
/**
|
|
57861
|
+
* Encodes the specified Frame message, length delimited. Does not implicitly {@link pbbp2.Frame.verify|verify} messages.
|
|
57862
|
+
* @function encodeDelimited
|
|
57863
|
+
* @memberof pbbp2.Frame
|
|
57864
|
+
* @static
|
|
57865
|
+
* @param {pbbp2.IFrame} message Frame message or plain object to encode
|
|
57866
|
+
* @param {$protobuf.Writer} [writer] Writer to encode to
|
|
57867
|
+
* @returns {$protobuf.Writer} Writer
|
|
57868
|
+
*/
|
|
57869
|
+
Frame.encodeDelimited = function encodeDelimited(message, writer) {
|
|
57870
|
+
return this.encode(message, writer).ldelim();
|
|
57871
|
+
};
|
|
57872
|
+
|
|
57873
|
+
/**
|
|
57874
|
+
* Decodes a Frame message from the specified reader or buffer.
|
|
57875
|
+
* @function decode
|
|
57876
|
+
* @memberof pbbp2.Frame
|
|
57877
|
+
* @static
|
|
57878
|
+
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
|
|
57879
|
+
* @param {number} [length] Message length if known beforehand
|
|
57880
|
+
* @returns {pbbp2.Frame} Frame
|
|
57881
|
+
* @throws {Error} If the payload is not a reader or valid buffer
|
|
57882
|
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
57883
|
+
*/
|
|
57884
|
+
Frame.decode = function decode(reader, length) {
|
|
57885
|
+
if (!(reader instanceof $Reader))
|
|
57886
|
+
reader = $Reader.create(reader);
|
|
57887
|
+
let end = length === undefined ? reader.len : reader.pos + length, message = new $root.pbbp2.Frame();
|
|
57888
|
+
while (reader.pos < end) {
|
|
57889
|
+
let tag = reader.uint32();
|
|
57890
|
+
switch (tag >>> 3) {
|
|
57891
|
+
case 1: {
|
|
57892
|
+
message.SeqID = reader.uint64();
|
|
57893
|
+
break;
|
|
57894
|
+
}
|
|
57895
|
+
case 2: {
|
|
57896
|
+
message.LogID = reader.uint64();
|
|
57897
|
+
break;
|
|
57898
|
+
}
|
|
57899
|
+
case 3: {
|
|
57900
|
+
message.service = reader.int32();
|
|
57901
|
+
break;
|
|
57902
|
+
}
|
|
57903
|
+
case 4: {
|
|
57904
|
+
message.method = reader.int32();
|
|
57905
|
+
break;
|
|
57906
|
+
}
|
|
57907
|
+
case 5: {
|
|
57908
|
+
if (!(message.headers && message.headers.length))
|
|
57909
|
+
message.headers = [];
|
|
57910
|
+
message.headers.push($root.pbbp2.Header.decode(reader, reader.uint32()));
|
|
57911
|
+
break;
|
|
57912
|
+
}
|
|
57913
|
+
case 6: {
|
|
57914
|
+
message.payloadEncoding = reader.string();
|
|
57915
|
+
break;
|
|
57916
|
+
}
|
|
57917
|
+
case 7: {
|
|
57918
|
+
message.payloadType = reader.string();
|
|
57919
|
+
break;
|
|
57920
|
+
}
|
|
57921
|
+
case 8: {
|
|
57922
|
+
message.payload = reader.bytes();
|
|
57923
|
+
break;
|
|
57924
|
+
}
|
|
57925
|
+
case 9: {
|
|
57926
|
+
message.LogIDNew = reader.string();
|
|
57927
|
+
break;
|
|
57928
|
+
}
|
|
57929
|
+
default:
|
|
57930
|
+
reader.skipType(tag & 7);
|
|
57931
|
+
break;
|
|
57932
|
+
}
|
|
57933
|
+
}
|
|
57934
|
+
if (!message.hasOwnProperty("SeqID"))
|
|
57935
|
+
throw $util.ProtocolError("missing required 'SeqID'", { instance: message });
|
|
57936
|
+
if (!message.hasOwnProperty("LogID"))
|
|
57937
|
+
throw $util.ProtocolError("missing required 'LogID'", { instance: message });
|
|
57938
|
+
if (!message.hasOwnProperty("service"))
|
|
57939
|
+
throw $util.ProtocolError("missing required 'service'", { instance: message });
|
|
57940
|
+
if (!message.hasOwnProperty("method"))
|
|
57941
|
+
throw $util.ProtocolError("missing required 'method'", { instance: message });
|
|
57942
|
+
return message;
|
|
57943
|
+
};
|
|
57944
|
+
|
|
57945
|
+
/**
|
|
57946
|
+
* Decodes a Frame message from the specified reader or buffer, length delimited.
|
|
57947
|
+
* @function decodeDelimited
|
|
57948
|
+
* @memberof pbbp2.Frame
|
|
57949
|
+
* @static
|
|
57950
|
+
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
|
|
57951
|
+
* @returns {pbbp2.Frame} Frame
|
|
57952
|
+
* @throws {Error} If the payload is not a reader or valid buffer
|
|
57953
|
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
57954
|
+
*/
|
|
57955
|
+
Frame.decodeDelimited = function decodeDelimited(reader) {
|
|
57956
|
+
if (!(reader instanceof $Reader))
|
|
57957
|
+
reader = new $Reader(reader);
|
|
57958
|
+
return this.decode(reader, reader.uint32());
|
|
57959
|
+
};
|
|
57960
|
+
|
|
57961
|
+
/**
|
|
57962
|
+
* Verifies a Frame message.
|
|
57963
|
+
* @function verify
|
|
57964
|
+
* @memberof pbbp2.Frame
|
|
57965
|
+
* @static
|
|
57966
|
+
* @param {Object.<string,*>} message Plain object to verify
|
|
57967
|
+
* @returns {string|null} `null` if valid, otherwise the reason why it is not
|
|
57968
|
+
*/
|
|
57969
|
+
Frame.verify = function verify(message) {
|
|
57970
|
+
if (typeof message !== "object" || message === null)
|
|
57971
|
+
return "object expected";
|
|
57972
|
+
if (!$util.isInteger(message.SeqID) && !(message.SeqID && $util.isInteger(message.SeqID.low) && $util.isInteger(message.SeqID.high)))
|
|
57973
|
+
return "SeqID: integer|Long expected";
|
|
57974
|
+
if (!$util.isInteger(message.LogID) && !(message.LogID && $util.isInteger(message.LogID.low) && $util.isInteger(message.LogID.high)))
|
|
57975
|
+
return "LogID: integer|Long expected";
|
|
57976
|
+
if (!$util.isInteger(message.service))
|
|
57977
|
+
return "service: integer expected";
|
|
57978
|
+
if (!$util.isInteger(message.method))
|
|
57979
|
+
return "method: integer expected";
|
|
57980
|
+
if (message.headers != null && message.hasOwnProperty("headers")) {
|
|
57981
|
+
if (!Array.isArray(message.headers))
|
|
57982
|
+
return "headers: array expected";
|
|
57983
|
+
for (let i = 0; i < message.headers.length; ++i) {
|
|
57984
|
+
let error = $root.pbbp2.Header.verify(message.headers[i]);
|
|
57985
|
+
if (error)
|
|
57986
|
+
return "headers." + error;
|
|
57987
|
+
}
|
|
57988
|
+
}
|
|
57989
|
+
if (message.payloadEncoding != null && message.hasOwnProperty("payloadEncoding"))
|
|
57990
|
+
if (!$util.isString(message.payloadEncoding))
|
|
57991
|
+
return "payloadEncoding: string expected";
|
|
57992
|
+
if (message.payloadType != null && message.hasOwnProperty("payloadType"))
|
|
57993
|
+
if (!$util.isString(message.payloadType))
|
|
57994
|
+
return "payloadType: string expected";
|
|
57995
|
+
if (message.payload != null && message.hasOwnProperty("payload"))
|
|
57996
|
+
if (!(message.payload && typeof message.payload.length === "number" || $util.isString(message.payload)))
|
|
57997
|
+
return "payload: buffer expected";
|
|
57998
|
+
if (message.LogIDNew != null && message.hasOwnProperty("LogIDNew"))
|
|
57999
|
+
if (!$util.isString(message.LogIDNew))
|
|
58000
|
+
return "LogIDNew: string expected";
|
|
58001
|
+
return null;
|
|
58002
|
+
};
|
|
58003
|
+
|
|
58004
|
+
/**
|
|
58005
|
+
* Creates a Frame message from a plain object. Also converts values to their respective internal types.
|
|
58006
|
+
* @function fromObject
|
|
58007
|
+
* @memberof pbbp2.Frame
|
|
58008
|
+
* @static
|
|
58009
|
+
* @param {Object.<string,*>} object Plain object
|
|
58010
|
+
* @returns {pbbp2.Frame} Frame
|
|
58011
|
+
*/
|
|
58012
|
+
Frame.fromObject = function fromObject(object) {
|
|
58013
|
+
if (object instanceof $root.pbbp2.Frame)
|
|
58014
|
+
return object;
|
|
58015
|
+
let message = new $root.pbbp2.Frame();
|
|
58016
|
+
if (object.SeqID != null)
|
|
58017
|
+
if ($util.Long)
|
|
58018
|
+
(message.SeqID = $util.Long.fromValue(object.SeqID)).unsigned = true;
|
|
58019
|
+
else if (typeof object.SeqID === "string")
|
|
58020
|
+
message.SeqID = parseInt(object.SeqID, 10);
|
|
58021
|
+
else if (typeof object.SeqID === "number")
|
|
58022
|
+
message.SeqID = object.SeqID;
|
|
58023
|
+
else if (typeof object.SeqID === "object")
|
|
58024
|
+
message.SeqID = new $util.LongBits(object.SeqID.low >>> 0, object.SeqID.high >>> 0).toNumber(true);
|
|
58025
|
+
if (object.LogID != null)
|
|
58026
|
+
if ($util.Long)
|
|
58027
|
+
(message.LogID = $util.Long.fromValue(object.LogID)).unsigned = true;
|
|
58028
|
+
else if (typeof object.LogID === "string")
|
|
58029
|
+
message.LogID = parseInt(object.LogID, 10);
|
|
58030
|
+
else if (typeof object.LogID === "number")
|
|
58031
|
+
message.LogID = object.LogID;
|
|
58032
|
+
else if (typeof object.LogID === "object")
|
|
58033
|
+
message.LogID = new $util.LongBits(object.LogID.low >>> 0, object.LogID.high >>> 0).toNumber(true);
|
|
58034
|
+
if (object.service != null)
|
|
58035
|
+
message.service = object.service | 0;
|
|
58036
|
+
if (object.method != null)
|
|
58037
|
+
message.method = object.method | 0;
|
|
58038
|
+
if (object.headers) {
|
|
58039
|
+
if (!Array.isArray(object.headers))
|
|
58040
|
+
throw TypeError(".pbbp2.Frame.headers: array expected");
|
|
58041
|
+
message.headers = [];
|
|
58042
|
+
for (let i = 0; i < object.headers.length; ++i) {
|
|
58043
|
+
if (typeof object.headers[i] !== "object")
|
|
58044
|
+
throw TypeError(".pbbp2.Frame.headers: object expected");
|
|
58045
|
+
message.headers[i] = $root.pbbp2.Header.fromObject(object.headers[i]);
|
|
58046
|
+
}
|
|
58047
|
+
}
|
|
58048
|
+
if (object.payloadEncoding != null)
|
|
58049
|
+
message.payloadEncoding = String(object.payloadEncoding);
|
|
58050
|
+
if (object.payloadType != null)
|
|
58051
|
+
message.payloadType = String(object.payloadType);
|
|
58052
|
+
if (object.payload != null)
|
|
58053
|
+
if (typeof object.payload === "string")
|
|
58054
|
+
$util.base64.decode(object.payload, message.payload = $util.newBuffer($util.base64.length(object.payload)), 0);
|
|
58055
|
+
else if (object.payload.length >= 0)
|
|
58056
|
+
message.payload = object.payload;
|
|
58057
|
+
if (object.LogIDNew != null)
|
|
58058
|
+
message.LogIDNew = String(object.LogIDNew);
|
|
58059
|
+
return message;
|
|
58060
|
+
};
|
|
58061
|
+
|
|
58062
|
+
/**
|
|
58063
|
+
* Creates a plain object from a Frame message. Also converts values to other types if specified.
|
|
58064
|
+
* @function toObject
|
|
58065
|
+
* @memberof pbbp2.Frame
|
|
58066
|
+
* @static
|
|
58067
|
+
* @param {pbbp2.Frame} message Frame
|
|
58068
|
+
* @param {$protobuf.IConversionOptions} [options] Conversion options
|
|
58069
|
+
* @returns {Object.<string,*>} Plain object
|
|
58070
|
+
*/
|
|
58071
|
+
Frame.toObject = function toObject(message, options) {
|
|
58072
|
+
if (!options)
|
|
58073
|
+
options = {};
|
|
58074
|
+
let object = {};
|
|
58075
|
+
if (options.arrays || options.defaults)
|
|
58076
|
+
object.headers = [];
|
|
58077
|
+
if (options.defaults) {
|
|
58078
|
+
if ($util.Long) {
|
|
58079
|
+
let long = new $util.Long(0, 0, true);
|
|
58080
|
+
object.SeqID = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long;
|
|
58081
|
+
} else
|
|
58082
|
+
object.SeqID = options.longs === String ? "0" : 0;
|
|
58083
|
+
if ($util.Long) {
|
|
58084
|
+
let long = new $util.Long(0, 0, true);
|
|
58085
|
+
object.LogID = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long;
|
|
58086
|
+
} else
|
|
58087
|
+
object.LogID = options.longs === String ? "0" : 0;
|
|
58088
|
+
object.service = 0;
|
|
58089
|
+
object.method = 0;
|
|
58090
|
+
object.payloadEncoding = "";
|
|
58091
|
+
object.payloadType = "";
|
|
58092
|
+
if (options.bytes === String)
|
|
58093
|
+
object.payload = "";
|
|
58094
|
+
else {
|
|
58095
|
+
object.payload = [];
|
|
58096
|
+
if (options.bytes !== Array)
|
|
58097
|
+
object.payload = $util.newBuffer(object.payload);
|
|
58098
|
+
}
|
|
58099
|
+
object.LogIDNew = "";
|
|
58100
|
+
}
|
|
58101
|
+
if (message.SeqID != null && message.hasOwnProperty("SeqID"))
|
|
58102
|
+
if (typeof message.SeqID === "number")
|
|
58103
|
+
object.SeqID = options.longs === String ? String(message.SeqID) : message.SeqID;
|
|
58104
|
+
else
|
|
58105
|
+
object.SeqID = options.longs === String ? $util.Long.prototype.toString.call(message.SeqID) : options.longs === Number ? new $util.LongBits(message.SeqID.low >>> 0, message.SeqID.high >>> 0).toNumber(true) : message.SeqID;
|
|
58106
|
+
if (message.LogID != null && message.hasOwnProperty("LogID"))
|
|
58107
|
+
if (typeof message.LogID === "number")
|
|
58108
|
+
object.LogID = options.longs === String ? String(message.LogID) : message.LogID;
|
|
58109
|
+
else
|
|
58110
|
+
object.LogID = options.longs === String ? $util.Long.prototype.toString.call(message.LogID) : options.longs === Number ? new $util.LongBits(message.LogID.low >>> 0, message.LogID.high >>> 0).toNumber(true) : message.LogID;
|
|
58111
|
+
if (message.service != null && message.hasOwnProperty("service"))
|
|
58112
|
+
object.service = message.service;
|
|
58113
|
+
if (message.method != null && message.hasOwnProperty("method"))
|
|
58114
|
+
object.method = message.method;
|
|
58115
|
+
if (message.headers && message.headers.length) {
|
|
58116
|
+
object.headers = [];
|
|
58117
|
+
for (let j = 0; j < message.headers.length; ++j)
|
|
58118
|
+
object.headers[j] = $root.pbbp2.Header.toObject(message.headers[j], options);
|
|
58119
|
+
}
|
|
58120
|
+
if (message.payloadEncoding != null && message.hasOwnProperty("payloadEncoding"))
|
|
58121
|
+
object.payloadEncoding = message.payloadEncoding;
|
|
58122
|
+
if (message.payloadType != null && message.hasOwnProperty("payloadType"))
|
|
58123
|
+
object.payloadType = message.payloadType;
|
|
58124
|
+
if (message.payload != null && message.hasOwnProperty("payload"))
|
|
58125
|
+
object.payload = options.bytes === String ? $util.base64.encode(message.payload, 0, message.payload.length) : options.bytes === Array ? Array.prototype.slice.call(message.payload) : message.payload;
|
|
58126
|
+
if (message.LogIDNew != null && message.hasOwnProperty("LogIDNew"))
|
|
58127
|
+
object.LogIDNew = message.LogIDNew;
|
|
58128
|
+
return object;
|
|
58129
|
+
};
|
|
58130
|
+
|
|
58131
|
+
/**
|
|
58132
|
+
* Converts this Frame to JSON.
|
|
58133
|
+
* @function toJSON
|
|
58134
|
+
* @memberof pbbp2.Frame
|
|
58135
|
+
* @instance
|
|
58136
|
+
* @returns {Object.<string,*>} JSON object
|
|
58137
|
+
*/
|
|
58138
|
+
Frame.prototype.toJSON = function toJSON() {
|
|
58139
|
+
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
|
|
58140
|
+
};
|
|
58141
|
+
|
|
58142
|
+
/**
|
|
58143
|
+
* Gets the default type url for Frame
|
|
58144
|
+
* @function getTypeUrl
|
|
58145
|
+
* @memberof pbbp2.Frame
|
|
58146
|
+
* @static
|
|
58147
|
+
* @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
|
|
58148
|
+
* @returns {string} The default type url
|
|
58149
|
+
*/
|
|
58150
|
+
Frame.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
|
|
58151
|
+
if (typeUrlPrefix === undefined) {
|
|
58152
|
+
typeUrlPrefix = "type.googleapis.com";
|
|
58153
|
+
}
|
|
58154
|
+
return typeUrlPrefix + "/pbbp2.Frame";
|
|
58155
|
+
};
|
|
58156
|
+
|
|
58157
|
+
return Frame;
|
|
58158
|
+
})();
|
|
58159
|
+
|
|
58160
|
+
return pbbp2;
|
|
58161
|
+
})();
|
|
58162
|
+
|
|
58163
|
+
const decode = (buffer) => {
|
|
58164
|
+
return pbbp2.Frame.decode(buffer);
|
|
58165
|
+
};
|
|
58166
|
+
|
|
58167
|
+
class WSConfig {
|
|
58168
|
+
constructor() {
|
|
58169
|
+
this.client = {
|
|
58170
|
+
appId: '',
|
|
58171
|
+
appSecret: '',
|
|
58172
|
+
domain: exports.Domain.Feishu,
|
|
58173
|
+
};
|
|
58174
|
+
this.ws = {
|
|
58175
|
+
connectUrl: '',
|
|
58176
|
+
pingInterval: 120,
|
|
58177
|
+
reconnectCount: -1,
|
|
58178
|
+
reconnectInterval: 120,
|
|
58179
|
+
reconnectNonce: 30,
|
|
58180
|
+
deviceId: '',
|
|
58181
|
+
serviceId: '',
|
|
58182
|
+
autoReconnect: true
|
|
58183
|
+
};
|
|
58184
|
+
this.wsInstance = null;
|
|
58185
|
+
}
|
|
58186
|
+
updateClient(clientConfig) {
|
|
58187
|
+
Object.assign(this.client, clientConfig);
|
|
58188
|
+
}
|
|
58189
|
+
updateWs(WSConfig) {
|
|
58190
|
+
Object.assign(this.ws, WSConfig);
|
|
58191
|
+
}
|
|
58192
|
+
getClient(key) {
|
|
58193
|
+
if (key === undefined) {
|
|
58194
|
+
return this.client;
|
|
58195
|
+
}
|
|
58196
|
+
return this.client[key];
|
|
58197
|
+
}
|
|
58198
|
+
getWS(key) {
|
|
58199
|
+
if (key === undefined) {
|
|
58200
|
+
return this.ws;
|
|
58201
|
+
}
|
|
58202
|
+
return this.ws[key];
|
|
58203
|
+
}
|
|
58204
|
+
get wsConfigUrl() {
|
|
58205
|
+
return `${this.getClient("domain")}/callback/ws/endpoint`;
|
|
58206
|
+
}
|
|
58207
|
+
setWSInstance(wsInstance) {
|
|
58208
|
+
this.wsInstance = wsInstance;
|
|
58209
|
+
}
|
|
58210
|
+
getWSInstance() {
|
|
58211
|
+
return this.wsInstance;
|
|
58212
|
+
}
|
|
58213
|
+
}
|
|
58214
|
+
|
|
58215
|
+
class DataCache {
|
|
58216
|
+
constructor(params) {
|
|
58217
|
+
this.cache = new Map();
|
|
58218
|
+
this.logger = params.logger;
|
|
58219
|
+
this.clearAtInterval();
|
|
58220
|
+
}
|
|
58221
|
+
mergeData(params) {
|
|
58222
|
+
const { message_id, sum, seq, trace_id, data } = params;
|
|
58223
|
+
const cache = this.cache.get(message_id);
|
|
58224
|
+
if (!cache) {
|
|
58225
|
+
const buffer = new Array(sum).fill(undefined);
|
|
58226
|
+
buffer[seq] = data;
|
|
58227
|
+
this.cache.set(message_id, {
|
|
58228
|
+
buffer,
|
|
58229
|
+
trace_id,
|
|
58230
|
+
message_id,
|
|
58231
|
+
create_time: Date.now()
|
|
58232
|
+
});
|
|
58233
|
+
}
|
|
58234
|
+
else {
|
|
58235
|
+
cache.buffer[seq] = data;
|
|
58236
|
+
}
|
|
58237
|
+
const mergedCache = this.cache.get(message_id);
|
|
58238
|
+
if (mergedCache === null || mergedCache === void 0 ? void 0 : mergedCache.buffer.every(item => !!item)) {
|
|
58239
|
+
const mergedBuffer = mergedCache.buffer.reduce((acc, cur) => {
|
|
58240
|
+
const combined = new Uint8Array(acc.byteLength + cur.byteLength);
|
|
58241
|
+
combined.set(acc, 0);
|
|
58242
|
+
combined.set(cur, acc.length);
|
|
58243
|
+
return combined;
|
|
58244
|
+
}, new Uint8Array([]));
|
|
58245
|
+
const string = new TextDecoder("utf-8").decode(mergedBuffer);
|
|
58246
|
+
const data = JSON.parse(string);
|
|
58247
|
+
this.deleteCache(message_id);
|
|
58248
|
+
return data;
|
|
58249
|
+
}
|
|
58250
|
+
return null;
|
|
58251
|
+
}
|
|
58252
|
+
deleteCache(message_id) {
|
|
58253
|
+
this.cache.delete(message_id);
|
|
58254
|
+
}
|
|
58255
|
+
clearAtInterval() {
|
|
58256
|
+
// magic number,10s expired
|
|
58257
|
+
const clearIntervalMs = 10000;
|
|
58258
|
+
setInterval(() => {
|
|
58259
|
+
const now = Date.now();
|
|
58260
|
+
this.cache.forEach((value, key) => {
|
|
58261
|
+
var _a;
|
|
58262
|
+
const { create_time, trace_id, message_id } = value;
|
|
58263
|
+
if (now - create_time > clearIntervalMs) {
|
|
58264
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug(`${message_id} event data is deleted as expired, trace_id: ${trace_id}`);
|
|
58265
|
+
this.deleteCache(key);
|
|
58266
|
+
}
|
|
58267
|
+
});
|
|
58268
|
+
}, clearIntervalMs);
|
|
58269
|
+
}
|
|
58270
|
+
}
|
|
58271
|
+
|
|
58272
|
+
var ErrorCode;
|
|
58273
|
+
(function (ErrorCode) {
|
|
58274
|
+
ErrorCode[ErrorCode["ok"] = 0] = "ok";
|
|
58275
|
+
ErrorCode[ErrorCode["system_busy"] = 1] = "system_busy";
|
|
58276
|
+
ErrorCode[ErrorCode["forbidden"] = 403] = "forbidden";
|
|
58277
|
+
ErrorCode[ErrorCode["auth_failed"] = 514] = "auth_failed";
|
|
58278
|
+
ErrorCode[ErrorCode["internal_error"] = 1000040343] = "internal_error";
|
|
58279
|
+
ErrorCode[ErrorCode["exceed_conn_limit"] = 1000040350] = "exceed_conn_limit";
|
|
58280
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
58281
|
+
var FrameType;
|
|
58282
|
+
(function (FrameType) {
|
|
58283
|
+
FrameType[FrameType["control"] = 0] = "control";
|
|
58284
|
+
FrameType[FrameType["data"] = 1] = "data";
|
|
58285
|
+
})(FrameType || (FrameType = {}));
|
|
58286
|
+
var HeaderKey;
|
|
58287
|
+
(function (HeaderKey) {
|
|
58288
|
+
HeaderKey["type"] = "type";
|
|
58289
|
+
HeaderKey["message_id"] = "message_id";
|
|
58290
|
+
HeaderKey["sum"] = "sum";
|
|
58291
|
+
HeaderKey["seq"] = "seq";
|
|
58292
|
+
HeaderKey["trace_id"] = "trace_id";
|
|
58293
|
+
HeaderKey["biz_rt"] = "biz_rt";
|
|
58294
|
+
HeaderKey["handshake_status"] = "handshake-status";
|
|
58295
|
+
HeaderKey["handshake_msg"] = "handshake-msg";
|
|
58296
|
+
HeaderKey["handshake_autherrcode"] = "handshake-autherrcode";
|
|
58297
|
+
})(HeaderKey || (HeaderKey = {}));
|
|
58298
|
+
var MessageType;
|
|
58299
|
+
(function (MessageType) {
|
|
58300
|
+
MessageType["event"] = "event";
|
|
58301
|
+
MessageType["card"] = "card";
|
|
58302
|
+
MessageType["ping"] = "ping";
|
|
58303
|
+
MessageType["pong"] = "pong";
|
|
58304
|
+
})(MessageType || (MessageType = {}));
|
|
58305
|
+
|
|
58306
|
+
class WSClient {
|
|
58307
|
+
constructor(params) {
|
|
58308
|
+
this.wsConfig = new WSConfig();
|
|
58309
|
+
const { appId, appSecret, domain = exports.Domain.Feishu, httpInstance = defaultHttpInstance, loggerLevel = exports.LoggerLevel.info, logger = defaultLogger, autoReconnect = true } = params;
|
|
58310
|
+
this.logger = new LoggerProxy(loggerLevel, logger);
|
|
58311
|
+
assert(!appId, () => this.logger.error('appId is needed'));
|
|
58312
|
+
assert(!appSecret, () => this.logger.error('appSecret is needed'));
|
|
58313
|
+
this.dataCache = new DataCache({ logger: this.logger });
|
|
58314
|
+
this.httpInstance = httpInstance;
|
|
58315
|
+
this.wsConfig.updateClient({
|
|
58316
|
+
appId,
|
|
58317
|
+
appSecret,
|
|
58318
|
+
domain: formatDomain(domain),
|
|
58319
|
+
});
|
|
58320
|
+
this.wsConfig.updateWs({
|
|
58321
|
+
autoReconnect
|
|
58322
|
+
});
|
|
58323
|
+
}
|
|
58324
|
+
pullConnectConfig() {
|
|
58325
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58326
|
+
const { appId, appSecret } = this.wsConfig.getClient();
|
|
58327
|
+
try {
|
|
58328
|
+
const { code, data: { URL, ClientConfig }, msg } = yield this.httpInstance.request({
|
|
58329
|
+
method: "post",
|
|
58330
|
+
url: this.wsConfig.wsConfigUrl,
|
|
58331
|
+
data: {
|
|
58332
|
+
AppID: appId,
|
|
58333
|
+
AppSecret: appSecret
|
|
58334
|
+
},
|
|
58335
|
+
// consumed by gateway
|
|
58336
|
+
headers: {
|
|
58337
|
+
"locale": "zh",
|
|
58338
|
+
}
|
|
58339
|
+
});
|
|
58340
|
+
if (code !== ErrorCode.ok) {
|
|
58341
|
+
this.logger.error('[ws]', `code: ${code}, ${code === ErrorCode.system_busy ? msg : 'system busy'}`);
|
|
58342
|
+
if (code === ErrorCode.system_busy || code === ErrorCode.internal_error) {
|
|
58343
|
+
return false;
|
|
58344
|
+
}
|
|
58345
|
+
}
|
|
58346
|
+
const { device_id, service_id } = qs__default["default"].parse(URL);
|
|
58347
|
+
this.wsConfig.updateWs({
|
|
58348
|
+
connectUrl: URL,
|
|
58349
|
+
deviceId: device_id,
|
|
58350
|
+
serviceId: service_id,
|
|
58351
|
+
pingInterval: ClientConfig.PingInterval,
|
|
58352
|
+
reconnectCount: ClientConfig.ReconnectCount,
|
|
58353
|
+
reconnectInterval: ClientConfig.ReconnectInterval,
|
|
58354
|
+
reconnectNonce: ClientConfig.ReconnectNonce
|
|
58355
|
+
});
|
|
58356
|
+
this.logger.debug('[ws]', `get connect config success, ws url: ${URL}`);
|
|
58357
|
+
return true;
|
|
58358
|
+
}
|
|
58359
|
+
catch (e) {
|
|
58360
|
+
this.logger.error('[ws]', get__default["default"](e, 'message', 'system busy'));
|
|
58361
|
+
return false;
|
|
58362
|
+
}
|
|
58363
|
+
});
|
|
58364
|
+
}
|
|
58365
|
+
connect() {
|
|
58366
|
+
const connectUrl = this.wsConfig.getWS('connectUrl');
|
|
58367
|
+
const wsInstance = new WebSocket__default["default"](connectUrl);
|
|
58368
|
+
return new Promise((resolve) => {
|
|
58369
|
+
wsInstance.on('open', () => {
|
|
58370
|
+
this.logger.debug('[ws]', 'ws connect success');
|
|
58371
|
+
this.wsConfig.setWSInstance(wsInstance);
|
|
58372
|
+
this.pingLoop();
|
|
58373
|
+
resolve(true);
|
|
58374
|
+
});
|
|
58375
|
+
wsInstance.on('error', () => {
|
|
58376
|
+
this.logger.error('[ws]', 'ws connect failed');
|
|
58377
|
+
resolve(false);
|
|
58378
|
+
});
|
|
58379
|
+
});
|
|
58380
|
+
}
|
|
58381
|
+
reConnect(isStart = false) {
|
|
58382
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58383
|
+
const tryConnect = () => {
|
|
58384
|
+
return this.pullConnectConfig()
|
|
58385
|
+
.then(isSuccess => isSuccess ? this.connect() : Promise.resolve(false))
|
|
58386
|
+
.then(isSuccess => {
|
|
58387
|
+
if (isSuccess) {
|
|
58388
|
+
this.communicate();
|
|
58389
|
+
return Promise.resolve(true);
|
|
58390
|
+
}
|
|
58391
|
+
return Promise.resolve(false);
|
|
58392
|
+
});
|
|
58393
|
+
};
|
|
58394
|
+
if (isStart) {
|
|
58395
|
+
const isSuccess = yield tryConnect();
|
|
58396
|
+
if (!isSuccess) {
|
|
58397
|
+
this.logger.error('[ws]', 'connect failed');
|
|
58398
|
+
yield this.reConnect();
|
|
58399
|
+
}
|
|
58400
|
+
this.logger.info('[ws]', 'ws client ready');
|
|
58401
|
+
return;
|
|
58402
|
+
}
|
|
58403
|
+
const wsInstance = this.wsConfig.getWSInstance();
|
|
58404
|
+
const { autoReconnect, reconnectNonce, reconnectCount, reconnectInterval } = this.wsConfig.getWS();
|
|
58405
|
+
if (!autoReconnect) {
|
|
58406
|
+
return;
|
|
58407
|
+
}
|
|
58408
|
+
this.logger.info('[ws]', 'reconnect');
|
|
58409
|
+
if (wsInstance) {
|
|
58410
|
+
wsInstance === null || wsInstance === void 0 ? void 0 : wsInstance.terminate();
|
|
58411
|
+
}
|
|
58412
|
+
this.wsConfig.setWSInstance(null);
|
|
58413
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
58414
|
+
(function loopReConnect(count) {
|
|
58415
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58416
|
+
count++;
|
|
58417
|
+
const isSuccess = yield tryConnect();
|
|
58418
|
+
// if reconnectCount < 0, the reconnect time is infinite
|
|
58419
|
+
if (isSuccess) {
|
|
58420
|
+
this.logger.debug('[ws]', 'reconnect success');
|
|
58421
|
+
return;
|
|
58422
|
+
}
|
|
58423
|
+
this.logger.info('ws', `unable to connect to the server after trying ${count} times")`);
|
|
58424
|
+
if (reconnectCount >= 0 && count >= reconnectCount) {
|
|
58425
|
+
return;
|
|
58426
|
+
}
|
|
58427
|
+
setTimeout(() => {
|
|
58428
|
+
loopReConnect.bind(this)(count);
|
|
58429
|
+
}, reconnectInterval);
|
|
58430
|
+
});
|
|
58431
|
+
}).bind(this)(0);
|
|
58432
|
+
}), reconnectNonce ? reconnectNonce * Math.random() : 0);
|
|
58433
|
+
});
|
|
58434
|
+
}
|
|
58435
|
+
pingLoop() {
|
|
58436
|
+
const { serviceId, pingInterval } = this.wsConfig.getWS();
|
|
58437
|
+
const wsInstance = this.wsConfig.getWSInstance();
|
|
58438
|
+
if ((wsInstance === null || wsInstance === void 0 ? void 0 : wsInstance.readyState) === WebSocket__default["default"].OPEN) {
|
|
58439
|
+
const frame = {
|
|
58440
|
+
headers: [{
|
|
58441
|
+
key: HeaderKey.type,
|
|
58442
|
+
value: MessageType.ping
|
|
58443
|
+
}],
|
|
58444
|
+
service: Number(serviceId),
|
|
58445
|
+
method: FrameType.control,
|
|
58446
|
+
SeqID: 0,
|
|
58447
|
+
LogID: 0
|
|
58448
|
+
};
|
|
58449
|
+
this.sendMessage(frame);
|
|
58450
|
+
this.logger.trace('[ws]', 'ping success');
|
|
58451
|
+
}
|
|
58452
|
+
setTimeout(this.pingLoop.bind(this), pingInterval);
|
|
58453
|
+
}
|
|
58454
|
+
communicate() {
|
|
58455
|
+
const wsInstance = this.wsConfig.getWSInstance();
|
|
58456
|
+
wsInstance === null || wsInstance === void 0 ? void 0 : wsInstance.on('message', (buffer) => __awaiter(this, void 0, void 0, function* () {
|
|
58457
|
+
const data = decode(buffer);
|
|
58458
|
+
const { method } = data;
|
|
58459
|
+
if (method === FrameType.control) {
|
|
58460
|
+
yield this.handleControlData(data);
|
|
58461
|
+
}
|
|
58462
|
+
if (method === FrameType.data) {
|
|
58463
|
+
yield this.handleEventData(data);
|
|
58464
|
+
}
|
|
58465
|
+
}));
|
|
58466
|
+
wsInstance === null || wsInstance === void 0 ? void 0 : wsInstance.on('error', (e) => {
|
|
58467
|
+
this.logger.error('[ws]', 'ws error');
|
|
58468
|
+
});
|
|
58469
|
+
wsInstance === null || wsInstance === void 0 ? void 0 : wsInstance.on('close', () => {
|
|
58470
|
+
this.logger.debug('[ws]', 'client closed');
|
|
58471
|
+
this.reConnect();
|
|
58472
|
+
});
|
|
58473
|
+
}
|
|
58474
|
+
handleControlData(data) {
|
|
58475
|
+
var _a;
|
|
58476
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58477
|
+
const type = (_a = data.headers.find(item => item.key === HeaderKey.type)) === null || _a === void 0 ? void 0 : _a.value;
|
|
58478
|
+
const payload = data.payload;
|
|
58479
|
+
if (type === MessageType.ping) {
|
|
58480
|
+
return;
|
|
58481
|
+
}
|
|
58482
|
+
if (type === MessageType.pong && payload) {
|
|
58483
|
+
this.logger.trace('[ws]', 'receive pong');
|
|
58484
|
+
const dataString = new TextDecoder("utf-8").decode(payload);
|
|
58485
|
+
const { PingInterval, ReconnectCount, ReconnectInterval, ReconnectNonce } = JSON.parse(dataString);
|
|
58486
|
+
this.wsConfig.updateWs({
|
|
58487
|
+
pingInterval: PingInterval,
|
|
58488
|
+
reconnectCount: ReconnectCount,
|
|
58489
|
+
reconnectInterval: ReconnectInterval,
|
|
58490
|
+
reconnectNonce: ReconnectNonce,
|
|
58491
|
+
});
|
|
58492
|
+
this.logger.trace('[ws]', 'update wsConfig with pong data');
|
|
58493
|
+
}
|
|
58494
|
+
});
|
|
58495
|
+
}
|
|
58496
|
+
handleEventData(data) {
|
|
58497
|
+
var _a;
|
|
58498
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58499
|
+
const headers = data.headers.reduce((acc, cur) => {
|
|
58500
|
+
acc[cur.key] = cur.value;
|
|
58501
|
+
return acc;
|
|
58502
|
+
}, {});
|
|
58503
|
+
const { message_id, sum, seq, type, trace_id } = headers;
|
|
58504
|
+
const payload = data.payload;
|
|
58505
|
+
if (type !== MessageType.event) {
|
|
58506
|
+
return;
|
|
58507
|
+
}
|
|
58508
|
+
const mergedData = this.dataCache.mergeData({
|
|
58509
|
+
message_id,
|
|
58510
|
+
sum: Number(sum),
|
|
58511
|
+
seq: Number(seq),
|
|
58512
|
+
trace_id,
|
|
58513
|
+
data: payload
|
|
58514
|
+
});
|
|
58515
|
+
if (!mergedData) {
|
|
58516
|
+
return;
|
|
58517
|
+
}
|
|
58518
|
+
this.logger.debug('[ws]', `receive message, message_type: ${type}; message_id: ${message_id}; trace_id: ${trace_id}; data: ${mergedData.data}`);
|
|
58519
|
+
const startTime = Date.now();
|
|
58520
|
+
yield ((_a = this.eventDispatcher) === null || _a === void 0 ? void 0 : _a.invoke(mergedData, { needCheck: false }));
|
|
58521
|
+
const endTime = Date.now();
|
|
58522
|
+
this.sendMessage(Object.assign(Object.assign({}, data), { headers: [...data.headers, { key: HeaderKey.biz_rt, value: String(startTime - endTime) }], payload: new TextEncoder().encode(JSON.stringify({
|
|
58523
|
+
// http code
|
|
58524
|
+
code: 200
|
|
58525
|
+
})) }));
|
|
58526
|
+
});
|
|
58527
|
+
}
|
|
58528
|
+
sendMessage(data) {
|
|
58529
|
+
var _a;
|
|
58530
|
+
const wsInstance = this.wsConfig.getWSInstance();
|
|
58531
|
+
if ((wsInstance === null || wsInstance === void 0 ? void 0 : wsInstance.readyState) === WebSocket__default["default"].OPEN) {
|
|
58532
|
+
const resp = pbbp2.Frame.encode(data).finish();
|
|
58533
|
+
(_a = this.wsConfig.getWSInstance()) === null || _a === void 0 ? void 0 : _a.send(resp, (err) => {
|
|
58534
|
+
if (err) {
|
|
58535
|
+
this.logger.error('[ws]', 'send data failed');
|
|
58536
|
+
}
|
|
58537
|
+
});
|
|
58538
|
+
}
|
|
58539
|
+
}
|
|
58540
|
+
start(params) {
|
|
58541
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58542
|
+
this.logger.info('[ws]', `receive events through persistent connection only available in self-build & Feishu app, Configured in:
|
|
58543
|
+
Developer Console(开发者后台)
|
|
58544
|
+
->
|
|
58545
|
+
Events and Callbacks(事件配置)
|
|
58546
|
+
->
|
|
58547
|
+
Mode of event subscription(配置订阅方式)
|
|
58548
|
+
->
|
|
58549
|
+
Receive events through persistent connection(使用长连接接收事件)`);
|
|
58550
|
+
const { eventDispatcher } = params;
|
|
58551
|
+
if (!eventDispatcher) {
|
|
58552
|
+
this.logger.warn('[ws]', 'client need to start with a eventDispatcher');
|
|
58553
|
+
return;
|
|
58554
|
+
}
|
|
58555
|
+
this.eventDispatcher = eventDispatcher;
|
|
58556
|
+
this.reConnect(true);
|
|
58557
|
+
});
|
|
58558
|
+
}
|
|
58559
|
+
}
|
|
58560
|
+
|
|
57460
58561
|
exports.AESCipher = AESCipher;
|
|
57461
58562
|
exports.CAppTicket = CAppTicket;
|
|
57462
58563
|
exports.CTenantAccessToken = CTenantAccessToken;
|
|
57463
58564
|
exports.CardActionHandler = CardActionHandler;
|
|
57464
58565
|
exports.Client = Client;
|
|
57465
58566
|
exports.EventDispatcher = EventDispatcher;
|
|
58567
|
+
exports.WSClient = WSClient;
|
|
57466
58568
|
exports.adaptDefault = adaptDefault;
|
|
57467
58569
|
exports.adaptExpress = adaptExpress;
|
|
57468
58570
|
exports.adaptKoa = adaptKoa;
|