node-easywechat 3.0.0-beta.4 → 3.0.0-beta.5

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/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
3
 
4
+ ## v3.0.0-beta.5 (2022-06-29)
5
+
6
+ - Fix: 修复服务端获取消息异常的问题
7
+
4
8
  ## v3.0.0-beta.4 (2022-06-24)
5
9
 
6
10
  - Feat: 请求接口数据增加 FormData 实例的支持
@@ -63,8 +63,7 @@ class MessageMixin {
63
63
  }
64
64
  withBody(body) {
65
65
  if (Buffer.isBuffer(body)) {
66
- this.content = Buffer.from('');
67
- this.content.copy(body);
66
+ this.content = body;
68
67
  }
69
68
  else if (typeof body === 'string') {
70
69
  this.content = Buffer.from(body);
@@ -43,7 +43,7 @@ declare class ServerRequest implements ServerRequestInterface {
43
43
  * @param body 支持 Buffer、object对象、JSON字符串、XML字符串、QueryString格式的 body 内容字符串
44
44
  * @returns
45
45
  */
46
- static createFromIncomingMessage(req: IncomingMessage, body?: Buffer | Record<string, any> | string): ServerRequest;
46
+ static createFromIncomingMessage(req: IncomingMessage, body?: Buffer | Record<string, any> | string): Promise<ServerRequest>;
47
47
  }
48
48
  interface ServerRequest extends MessageMixin, RequestMixin {
49
49
  }
@@ -1,4 +1,13 @@
1
1
  'use strict';
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
@@ -124,13 +133,14 @@ class ServerRequest {
124
133
  * @returns
125
134
  */
126
135
  static createFromIncomingMessage(req, body = null) {
127
- let request = new ServerRequest(req.method, req.url, req.headers || {}, body, req.httpVersion, (0, url_1.parse)(req.url, true).query || {});
128
- if (!body) {
129
- (0, raw_body_1.default)(req).then(res => {
136
+ return __awaiter(this, void 0, void 0, function* () {
137
+ let request = new ServerRequest(req.method, req.url, req.headers || {}, body, req.httpVersion);
138
+ if (!body) {
139
+ let res = yield (0, raw_body_1.default)(req);
130
140
  request.withBody(res);
131
- });
132
- }
133
- return request;
141
+ }
142
+ return request;
143
+ });
134
144
  }
135
145
  }
136
146
  ;
@@ -49,7 +49,11 @@ class Message {
49
49
  */
50
50
  static createFromRequest(request) {
51
51
  return __awaiter(this, void 0, void 0, function* () {
52
- let originContent = request.getBody().toString();
52
+ let originContent = '';
53
+ let body = request.getBody();
54
+ if (body) {
55
+ originContent = body.toString();
56
+ }
53
57
  let attributes = {};
54
58
  if ('<' === originContent.substring(0, 1)) {
55
59
  attributes = yield (0, Utils_1.parseXml)(originContent);
@@ -75,11 +75,6 @@ class Application {
75
75
  }
76
76
  getServer() {
77
77
  if (!this.server) {
78
- let token = this.getAccount().getToken();
79
- let aesKey = this.getAccount().getAesKey();
80
- if (!token || !aesKey) {
81
- throw new Error('token or aes_key cannot be empty.');
82
- }
83
78
  this.server = new Server_1.default(this.getRequest(), this.getAccount().getAesKey() ? this.getEncryptor() : null);
84
79
  }
85
80
  return this.server;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-easywechat",
3
- "version": "3.0.0-beta.4",
3
+ "version": "3.0.0-beta.5",
4
4
  "description": "EasyWechat SDK for Node.js (NOT OFFICIAL)",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {