@larksuiteoapi/node-sdk 1.35.0 → 1.36.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 CHANGED
@@ -69892,6 +69892,13 @@ var MessageType;
69892
69892
  MessageType["ping"] = "ping";
69893
69893
  MessageType["pong"] = "pong";
69894
69894
  })(MessageType || (MessageType = {}));
69895
+ var HttpStatusCode;
69896
+ (function (HttpStatusCode) {
69897
+ // 2xx Success
69898
+ HttpStatusCode[HttpStatusCode["ok"] = 200] = "ok";
69899
+ // 5xx Server errors
69900
+ HttpStatusCode[HttpStatusCode["internal_server_error"] = 500] = "internal_server_error";
69901
+ })(HttpStatusCode || (HttpStatusCode = {}));
69895
69902
 
69896
69903
  class WSClient {
69897
69904
  constructor(params) {
@@ -70109,13 +70116,22 @@ class WSClient {
70109
70116
  return;
70110
70117
  }
70111
70118
  this.logger.debug('[ws]', `receive message, message_type: ${type}; message_id: ${message_id}; trace_id: ${trace_id}; data: ${mergedData.data}`);
70119
+ const respPayload = {
70120
+ code: HttpStatusCode.ok,
70121
+ };
70112
70122
  const startTime = Date.now();
70113
- yield ((_a = this.eventDispatcher) === null || _a === void 0 ? void 0 : _a.invoke(mergedData, { needCheck: false }));
70123
+ try {
70124
+ const result = yield ((_a = this.eventDispatcher) === null || _a === void 0 ? void 0 : _a.invoke(mergedData, { needCheck: false }));
70125
+ if (result) {
70126
+ respPayload.data = Buffer.from(JSON.stringify(result)).toString("base64");
70127
+ }
70128
+ }
70129
+ catch (error) {
70130
+ respPayload.code = HttpStatusCode.internal_server_error;
70131
+ this.logger.error('[ws]', `invoke event failed, message_type: ${type}; message_id: ${message_id}; trace_id: ${trace_id}; error: ${error}`);
70132
+ }
70114
70133
  const endTime = Date.now();
70115
- this.sendMessage(Object.assign(Object.assign({}, data), { headers: [...data.headers, { key: HeaderKey.biz_rt, value: String(startTime - endTime) }], payload: new TextEncoder().encode(JSON.stringify({
70116
- // http code
70117
- code: 200
70118
- })) }));
70134
+ this.sendMessage(Object.assign(Object.assign({}, data), { headers: [...data.headers, { key: HeaderKey.biz_rt, value: String(startTime - endTime) }], payload: new TextEncoder().encode(JSON.stringify(respPayload)) }));
70119
70135
  });
70120
70136
  }
70121
70137
  sendMessage(data) {
@@ -70132,14 +70148,14 @@ class WSClient {
70132
70148
  }
70133
70149
  start(params) {
70134
70150
  return __awaiter(this, void 0, void 0, function* () {
70135
- this.logger.info('[ws]', `receive events through persistent connection only available in self-build & Feishu app, Configured in:
70151
+ this.logger.info('[ws]', `receive events or callbacks through persistent connection only available in self-build & Feishu app, Configured in:
70136
70152
  Developer Console(开发者后台)
70137
70153
  ->
70138
- Events and Callbacks(事件配置)
70154
+ Events and Callbacks(事件与回调)
70139
70155
  ->
70140
- Mode of event subscription(配置订阅方式)
70156
+ Mode of event/callback subscription(订阅方式)
70141
70157
  ->
70142
- Receive events through persistent connection(使用长连接接收事件)`);
70158
+ Receive events/callbacks through persistent connection(使用 长连接 接收事件/回调)`);
70143
70159
  const { eventDispatcher } = params;
70144
70160
  if (!eventDispatcher) {
70145
70161
  this.logger.warn('[ws]', 'client need to start with a eventDispatcher');
package/lib/index.js CHANGED
@@ -69909,6 +69909,13 @@ var MessageType;
69909
69909
  MessageType["ping"] = "ping";
69910
69910
  MessageType["pong"] = "pong";
69911
69911
  })(MessageType || (MessageType = {}));
69912
+ var HttpStatusCode;
69913
+ (function (HttpStatusCode) {
69914
+ // 2xx Success
69915
+ HttpStatusCode[HttpStatusCode["ok"] = 200] = "ok";
69916
+ // 5xx Server errors
69917
+ HttpStatusCode[HttpStatusCode["internal_server_error"] = 500] = "internal_server_error";
69918
+ })(HttpStatusCode || (HttpStatusCode = {}));
69912
69919
 
69913
69920
  class WSClient {
69914
69921
  constructor(params) {
@@ -70126,13 +70133,22 @@ class WSClient {
70126
70133
  return;
70127
70134
  }
70128
70135
  this.logger.debug('[ws]', `receive message, message_type: ${type}; message_id: ${message_id}; trace_id: ${trace_id}; data: ${mergedData.data}`);
70136
+ const respPayload = {
70137
+ code: HttpStatusCode.ok,
70138
+ };
70129
70139
  const startTime = Date.now();
70130
- yield ((_a = this.eventDispatcher) === null || _a === void 0 ? void 0 : _a.invoke(mergedData, { needCheck: false }));
70140
+ try {
70141
+ const result = yield ((_a = this.eventDispatcher) === null || _a === void 0 ? void 0 : _a.invoke(mergedData, { needCheck: false }));
70142
+ if (result) {
70143
+ respPayload.data = Buffer.from(JSON.stringify(result)).toString("base64");
70144
+ }
70145
+ }
70146
+ catch (error) {
70147
+ respPayload.code = HttpStatusCode.internal_server_error;
70148
+ this.logger.error('[ws]', `invoke event failed, message_type: ${type}; message_id: ${message_id}; trace_id: ${trace_id}; error: ${error}`);
70149
+ }
70131
70150
  const endTime = Date.now();
70132
- this.sendMessage(Object.assign(Object.assign({}, data), { headers: [...data.headers, { key: HeaderKey.biz_rt, value: String(startTime - endTime) }], payload: new TextEncoder().encode(JSON.stringify({
70133
- // http code
70134
- code: 200
70135
- })) }));
70151
+ this.sendMessage(Object.assign(Object.assign({}, data), { headers: [...data.headers, { key: HeaderKey.biz_rt, value: String(startTime - endTime) }], payload: new TextEncoder().encode(JSON.stringify(respPayload)) }));
70136
70152
  });
70137
70153
  }
70138
70154
  sendMessage(data) {
@@ -70149,14 +70165,14 @@ class WSClient {
70149
70165
  }
70150
70166
  start(params) {
70151
70167
  return __awaiter(this, void 0, void 0, function* () {
70152
- this.logger.info('[ws]', `receive events through persistent connection only available in self-build & Feishu app, Configured in:
70168
+ this.logger.info('[ws]', `receive events or callbacks through persistent connection only available in self-build & Feishu app, Configured in:
70153
70169
  Developer Console(开发者后台)
70154
70170
  ->
70155
- Events and Callbacks(事件配置)
70171
+ Events and Callbacks(事件与回调)
70156
70172
  ->
70157
- Mode of event subscription(配置订阅方式)
70173
+ Mode of event/callback subscription(订阅方式)
70158
70174
  ->
70159
- Receive events through persistent connection(使用长连接接收事件)`);
70175
+ Receive events/callbacks through persistent connection(使用 长连接 接收事件/回调)`);
70160
70176
  const { eventDispatcher } = params;
70161
70177
  if (!eventDispatcher) {
70162
70178
  this.logger.warn('[ws]', 'client need to start with a eventDispatcher');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@larksuiteoapi/node-sdk",
3
- "version": "1.35.0",
3
+ "version": "1.36.0",
4
4
  "description": "larksuite open sdk for nodejs",
5
5
  "keywords": [
6
6
  "feishu",