node-easywechat 3.7.0 → 3.7.1

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.
Files changed (53) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/Channel/Application.js +1 -1
  3. package/dist/Core/Cache/FileCache.js +46 -63
  4. package/dist/Core/Contracts/AccessTokenInterface.js +2 -15
  5. package/dist/Core/Contracts/CacheInterface.js +4 -21
  6. package/dist/Core/Contracts/RefreshableAccessTokenInterface.js +1 -12
  7. package/dist/Core/Contracts/ServerInterface.js +1 -12
  8. package/dist/Core/Http/ServerRequest.js +34 -49
  9. package/dist/Core/HttpClient/AccessTokenAwareClient.js +6 -17
  10. package/dist/Core/HttpClient/Contracts/HttpClientInterface.js +1 -12
  11. package/dist/Core/HttpClient/HttpClient.js +74 -85
  12. package/dist/Core/HttpClient/HttpClientResponse.js +35 -50
  13. package/dist/Core/HttpClient/Mixins/HttpClientMethodsMixin.js +34 -59
  14. package/dist/Core/HttpClient/Mixins/PresetMixin.js +8 -11
  15. package/dist/Core/Message.js +20 -31
  16. package/dist/Core/Mixins/DecryptMessageMixin.js +13 -24
  17. package/dist/Core/Mixins/HandlersMixin.js +18 -31
  18. package/dist/Core/Mixins/ResponseMessageMixin.js +31 -44
  19. package/dist/Core/Support/Utils.js +8 -19
  20. package/dist/MiniApp/Application.js +1 -1
  21. package/dist/MiniApp/Utils.js +13 -24
  22. package/dist/OfficialAccount/AccessToken.js +42 -59
  23. package/dist/OfficialAccount/Application.js +1 -1
  24. package/dist/OfficialAccount/JsApiTicket.js +31 -44
  25. package/dist/OfficialAccount/Server.js +25 -40
  26. package/dist/OfficialAccount/Utils.js +6 -17
  27. package/dist/OpenPlatform/Application.js +62 -86
  28. package/dist/OpenPlatform/Authorizer/MiniApp/Utils.js +14 -25
  29. package/dist/OpenPlatform/AuthorizerAccessToken.js +6 -19
  30. package/dist/OpenPlatform/ComponentAccessToken.js +27 -42
  31. package/dist/OpenPlatform/Server.js +31 -54
  32. package/dist/OpenPlatform/VerifyTicket.js +14 -27
  33. package/dist/OpenWork/Application.js +61 -84
  34. package/dist/OpenWork/AuthorizerAccessToken.js +32 -47
  35. package/dist/OpenWork/JsApiTicket.js +64 -81
  36. package/dist/OpenWork/ProviderAccessToken.js +26 -41
  37. package/dist/OpenWork/Server.js +50 -94
  38. package/dist/OpenWork/SuiteAccessToken.js +27 -42
  39. package/dist/OpenWork/SuiteTicket.js +14 -27
  40. package/dist/Pay/Application.js +1 -2
  41. package/dist/Pay/Client.js +63 -77
  42. package/dist/Pay/LegacySignature.js +2 -3
  43. package/dist/Pay/Merchant.js +36 -52
  44. package/dist/Pay/Server.js +55 -70
  45. package/dist/Pay/Utils.js +13 -26
  46. package/dist/Pay/Validator.js +28 -39
  47. package/dist/Work/AccessToken.js +26 -41
  48. package/dist/Work/Application.js +21 -32
  49. package/dist/Work/JsApiTicket.js +60 -77
  50. package/dist/Work/Server.js +47 -86
  51. package/dist/Work/Utils.js +12 -25
  52. package/package.json +1 -1
  53. package/tsconfig.json +2 -2
@@ -1,13 +1,4 @@
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
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -52,47 +43,41 @@ class AuthorizerAccessToken {
52
43
  this.key = key;
53
44
  return this;
54
45
  }
55
- getToken() {
56
- return __awaiter(this, void 0, void 0, function* () {
57
- if (!this.suiteAccessToken) {
58
- return this.permanentCodeOrAccessToken;
59
- }
60
- let token = '';
61
- if (this.cache) {
62
- token = yield this.cache.get(this.getKey());
63
- }
64
- if (!!token && typeof token === 'string') {
65
- return token;
66
- }
67
- return this.refresh();
68
- });
46
+ async getToken() {
47
+ if (!this.suiteAccessToken) {
48
+ return this.permanentCodeOrAccessToken;
49
+ }
50
+ let token = '';
51
+ if (this.cache) {
52
+ token = await this.cache.get(this.getKey());
53
+ }
54
+ if (!!token && typeof token === 'string') {
55
+ return token;
56
+ }
57
+ return this.refresh();
69
58
  }
70
- toQuery() {
71
- return __awaiter(this, void 0, void 0, function* () {
72
- return {
73
- access_token: yield this.getToken(),
74
- };
75
- });
59
+ async toQuery() {
60
+ return {
61
+ access_token: await this.getToken(),
62
+ };
76
63
  }
77
- refresh() {
78
- return __awaiter(this, void 0, void 0, function* () {
79
- let response = (yield this.httpClient.request('post', 'cgi-bin/service/get_corp_token', {
80
- params: {
81
- suite_access_token: yield this.suiteAccessToken.getToken(),
82
- },
83
- json: {
84
- auth_corpid: this.corpId,
85
- permanent_code: this.permanentCodeOrAccessToken,
86
- }
87
- })).toObject();
88
- if (!response['access_token']) {
89
- throw new Error('Failed to get access_token: ' + JSON.stringify(response));
90
- }
91
- if (this.cache) {
92
- yield this.cache.set(this.getKey(), response['access_token'], parseInt(response['expires_in']) - 100);
64
+ async refresh() {
65
+ let response = (await this.httpClient.request('post', 'cgi-bin/service/get_corp_token', {
66
+ params: {
67
+ suite_access_token: await this.suiteAccessToken.getToken(),
68
+ },
69
+ json: {
70
+ auth_corpid: this.corpId,
71
+ permanent_code: this.permanentCodeOrAccessToken,
93
72
  }
94
- return response['access_token'];
95
- });
73
+ })).toObject();
74
+ if (!response['access_token']) {
75
+ throw new Error('Failed to get access_token: ' + JSON.stringify(response));
76
+ }
77
+ if (this.cache) {
78
+ await this.cache.set(this.getKey(), response['access_token'], parseInt(response['expires_in']) - 100);
79
+ }
80
+ return response['access_token'];
96
81
  }
97
82
  /**
98
83
  * 转为字符串
@@ -1,13 +1,4 @@
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
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -32,22 +23,20 @@ class JsApiTicket {
32
23
  * @param timestamp 时间长,默认:当前时间
33
24
  * @returns
34
25
  */
35
- createConfigSignature(url_1) {
36
- return __awaiter(this, arguments, void 0, function* (url, nonce = null, timestamp = null, jsApiList = [], debug = false, beta = true) {
37
- nonce = nonce || (0, Utils_1.randomString)(10);
38
- timestamp = timestamp || (0, Utils_1.getTimestamp)();
39
- let ticket = yield this.getTicket();
40
- return {
41
- appId: this.corpId,
42
- nonceStr: nonce,
43
- timestamp,
44
- url,
45
- signature: this.getTicketSignature(ticket, nonce, timestamp, url),
46
- jsApiList,
47
- debug,
48
- beta,
49
- };
50
- });
26
+ async createConfigSignature(url, nonce = null, timestamp = null, jsApiList = [], debug = false, beta = true) {
27
+ nonce = nonce || (0, Utils_1.randomString)(10);
28
+ timestamp = timestamp || (0, Utils_1.getTimestamp)();
29
+ let ticket = await this.getTicket();
30
+ return {
31
+ appId: this.corpId,
32
+ nonceStr: nonce,
33
+ timestamp,
34
+ url,
35
+ signature: this.getTicketSignature(ticket, nonce, timestamp, url),
36
+ jsApiList,
37
+ debug,
38
+ beta,
39
+ };
51
40
  }
52
41
  getTicketSignature(ticket, nonce, timestamp, url) {
53
42
  return (0, Utils_1.createHash)(`jsapi_ticket=${ticket}&noncestr=${nonce}&timestamp=${timestamp}&url=${url}`, 'sha1');
@@ -66,25 +55,23 @@ class JsApiTicket {
66
55
  * 获取签名凭证jsapi_ticket
67
56
  * @returns
68
57
  */
69
- getTicket() {
70
- return __awaiter(this, void 0, void 0, function* () {
71
- let key = this.getKey();
72
- let ticket = '';
73
- if (this.cache) {
74
- ticket = yield this.cache.get(key);
75
- }
76
- if (!!ticket && typeof ticket === 'string') {
77
- return ticket;
78
- }
79
- let response = (yield this.httpClient.request('get', '/cgi-bin/get_jsapi_ticket', {})).toObject();
80
- if (!response['ticket']) {
81
- throw new Error('Failed to get jssdk_ticket: ' + JSON.stringify(response));
82
- }
83
- if (this.cache) {
84
- yield this.cache.set(key, response['ticket'], parseInt(response['expires_in']));
85
- }
86
- return response['ticket'];
87
- });
58
+ async getTicket() {
59
+ let key = this.getKey();
60
+ let ticket = '';
61
+ if (this.cache) {
62
+ ticket = await this.cache.get(key);
63
+ }
64
+ if (!!ticket && typeof ticket === 'string') {
65
+ return ticket;
66
+ }
67
+ let response = (await this.httpClient.request('get', '/cgi-bin/get_jsapi_ticket', {})).toObject();
68
+ if (!response['ticket']) {
69
+ throw new Error('Failed to get jssdk_ticket: ' + JSON.stringify(response));
70
+ }
71
+ if (this.cache) {
72
+ await this.cache.set(key, response['ticket'], parseInt(response['expires_in']));
73
+ }
74
+ return response['ticket'];
88
75
  }
89
76
  /**
90
77
  * 获取代理应用的签名配置
@@ -94,50 +81,46 @@ class JsApiTicket {
94
81
  * @param timestamp 时间长,默认:当前时间
95
82
  * @returns
96
83
  */
97
- createAgentConfigSignature(agentId_1, url_1) {
98
- return __awaiter(this, arguments, void 0, function* (agentId, url, nonce = null, timestamp = null, jsApiList = []) {
99
- nonce = nonce || (0, Utils_1.randomString)(10);
100
- timestamp = timestamp || (0, Utils_1.getTimestamp)();
101
- let ticket = yield this.getTicket();
102
- return {
103
- corpid: this.corpId,
104
- agentid: agentId,
105
- url,
106
- nonceStr: nonce,
107
- timestamp,
108
- signature: this.getTicketSignature(ticket, nonce, timestamp, url),
109
- jsApiList,
110
- };
111
- });
84
+ async createAgentConfigSignature(agentId, url, nonce = null, timestamp = null, jsApiList = []) {
85
+ nonce = nonce || (0, Utils_1.randomString)(10);
86
+ timestamp = timestamp || (0, Utils_1.getTimestamp)();
87
+ let ticket = await this.getTicket();
88
+ return {
89
+ corpid: this.corpId,
90
+ agentid: agentId,
91
+ url,
92
+ nonceStr: nonce,
93
+ timestamp,
94
+ signature: this.getTicketSignature(ticket, nonce, timestamp, url),
95
+ jsApiList,
96
+ };
112
97
  }
113
98
  /**
114
99
  * 获取代理应用的签名凭证jsapi_ticket
115
100
  * @param agentId 代理应用的id
116
101
  * @returns
117
102
  */
118
- getAgentTicket(agentId) {
119
- return __awaiter(this, void 0, void 0, function* () {
120
- let key = this.getAgentKey(agentId);
121
- let ticket = '';
122
- if (this.cache) {
123
- ticket = yield this.cache.get(key);
124
- }
125
- if (!!ticket && typeof ticket === 'string') {
126
- return ticket;
127
- }
128
- let response = (yield this.httpClient.request('get', '/cgi-bin/ticket/get', {
129
- params: {
130
- type: 'agent_config',
131
- }
132
- })).toObject();
133
- if (!response['ticket']) {
134
- throw new Error('Failed to get jssdk agentTicket: ' + JSON.stringify(response));
135
- }
136
- if (this.cache) {
137
- yield this.cache.set(key, response['ticket'], parseInt(response['expires_in']));
103
+ async getAgentTicket(agentId) {
104
+ let key = this.getAgentKey(agentId);
105
+ let ticket = '';
106
+ if (this.cache) {
107
+ ticket = await this.cache.get(key);
108
+ }
109
+ if (!!ticket && typeof ticket === 'string') {
110
+ return ticket;
111
+ }
112
+ let response = (await this.httpClient.request('get', '/cgi-bin/ticket/get', {
113
+ params: {
114
+ type: 'agent_config',
138
115
  }
139
- return response['ticket'];
140
- });
116
+ })).toObject();
117
+ if (!response['ticket']) {
118
+ throw new Error('Failed to get jssdk agentTicket: ' + JSON.stringify(response));
119
+ }
120
+ if (this.cache) {
121
+ await this.cache.set(key, response['ticket'], parseInt(response['expires_in']));
122
+ }
123
+ return response['ticket'];
141
124
  }
142
125
  /**
143
126
  * 获取代理应用的jsapi_ticket的缓存名称
@@ -1,13 +1,4 @@
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
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -44,41 +35,35 @@ class ProviderAccessToken {
44
35
  this.key = key;
45
36
  return this;
46
37
  }
47
- getToken() {
48
- return __awaiter(this, void 0, void 0, function* () {
49
- let token = '';
50
- if (this.cache) {
51
- token = yield this.cache.get(this.getKey());
52
- }
53
- if (!!token && typeof token === 'string') {
54
- return token;
55
- }
56
- return this.refresh();
57
- });
38
+ async getToken() {
39
+ let token = '';
40
+ if (this.cache) {
41
+ token = await this.cache.get(this.getKey());
42
+ }
43
+ if (!!token && typeof token === 'string') {
44
+ return token;
45
+ }
46
+ return this.refresh();
58
47
  }
59
- toQuery() {
60
- return __awaiter(this, void 0, void 0, function* () {
61
- return {
62
- provider_access_token: yield this.getToken(),
63
- };
64
- });
48
+ async toQuery() {
49
+ return {
50
+ provider_access_token: await this.getToken(),
51
+ };
65
52
  }
66
- refresh() {
67
- return __awaiter(this, void 0, void 0, function* () {
68
- let response = (yield this.httpClient.request('post', 'cgi-bin/service/get_provider_token', {
69
- json: {
70
- corpid: this.corpId,
71
- provider_secret: this.providerSecret,
72
- }
73
- })).toObject();
74
- if (!response['provider_access_token']) {
75
- throw new Error('Failed to get provider_access_token: ' + JSON.stringify(response));
76
- }
77
- if (this.cache) {
78
- yield this.cache.set(this.getKey(), response['provider_access_token'], parseInt(response['expires_in']) - 100);
53
+ async refresh() {
54
+ let response = (await this.httpClient.request('post', 'cgi-bin/service/get_provider_token', {
55
+ json: {
56
+ corpid: this.corpId,
57
+ provider_secret: this.providerSecret,
79
58
  }
80
- return response['provider_access_token'];
81
- });
59
+ })).toObject();
60
+ if (!response['provider_access_token']) {
61
+ throw new Error('Failed to get provider_access_token: ' + JSON.stringify(response));
62
+ }
63
+ if (this.cache) {
64
+ await this.cache.set(this.getKey(), response['provider_access_token'], parseInt(response['expires_in']) - 100);
65
+ }
66
+ return response['provider_access_token'];
82
67
  }
83
68
  }
84
69
  module.exports = ProviderAccessToken;
@@ -1,13 +1,4 @@
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
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -26,22 +17,19 @@ class Server extends ServerInterface_1.default {
26
17
  * 服务端消息处理
27
18
  * @returns
28
19
  */
29
- serve() {
30
- return __awaiter(this, void 0, void 0, function* () {
31
- var _a, _b, _c;
32
- let query = this.request.getQueryParams();
33
- if (!!query['echostr']) {
34
- let echostr = this.providerEncryptor.decrypt(query['echostr'], (_a = query['msg_signature']) !== null && _a !== void 0 ? _a : '', (_b = query['nonce']) !== null && _b !== void 0 ? _b : '', (_c = query['timestamp']) !== null && _c !== void 0 ? _c : '');
35
- return new Response_1.default(200, { 'Content-Type': 'text/html' }, echostr);
36
- }
37
- let message = yield this.getRequestMessage(this.request);
38
- this.prepend(this.decryptRequestMessage(query));
39
- let response = yield this.handle(new Response_1.default(200, {}, 'success'), message);
40
- if (!(response instanceof Response_1.default)) {
41
- response = yield this.transformToReply(response, message, this.encryptor);
42
- }
43
- return response;
44
- });
20
+ async serve() {
21
+ let query = this.request.getQueryParams();
22
+ if (!!query['echostr']) {
23
+ let echostr = this.providerEncryptor.decrypt(query['echostr'], query['msg_signature'] ?? '', query['nonce'] ?? '', query['timestamp'] ?? '');
24
+ return new Response_1.default(200, { 'Content-Type': 'text/html' }, echostr);
25
+ }
26
+ let message = await this.getRequestMessage(this.request);
27
+ this.prepend(this.decryptRequestMessage(query));
28
+ let response = await this.handle(new Response_1.default(200, {}, 'success'), message);
29
+ if (!(response instanceof Response_1.default)) {
30
+ response = await this.transformToReply(response, message, this.encryptor);
31
+ }
32
+ return response;
45
33
  }
46
34
  withDefaultSuiteTicketHandler(handler) {
47
35
  this.defaultSuiteTicketHandler = function () {
@@ -57,10 +45,8 @@ class Server extends ServerInterface_1.default {
57
45
  if (this.defaultSuiteTicketHandler) {
58
46
  this.withoutHandler(this.defaultSuiteTicketHandler);
59
47
  }
60
- return this.with(function (message, next) {
61
- return __awaiter(this, void 0, void 0, function* () {
62
- return message.InfoType === 'suite_ticket' ? handler(message, next) : next(message);
63
- });
48
+ return this.with(async function (message, next) {
49
+ return message.InfoType === 'suite_ticket' ? handler(message, next) : next(message);
64
50
  });
65
51
  }
66
52
  /**
@@ -68,10 +54,8 @@ class Server extends ServerInterface_1.default {
68
54
  * @param handler
69
55
  */
70
56
  handleAuthCreated(handler) {
71
- return this.with(function (message, next) {
72
- return __awaiter(this, void 0, void 0, function* () {
73
- return message.InfoType === 'create_auth' ? handler(message, next) : next(message);
74
- });
57
+ return this.with(async function (message, next) {
58
+ return message.InfoType === 'create_auth' ? handler(message, next) : next(message);
75
59
  });
76
60
  }
77
61
  /**
@@ -79,10 +63,8 @@ class Server extends ServerInterface_1.default {
79
63
  * @param handler
80
64
  */
81
65
  handleAuthUpdated(handler) {
82
- return this.with(function (message, next) {
83
- return __awaiter(this, void 0, void 0, function* () {
84
- return message.InfoType === 'change_auth' ? handler(message, next) : next(message);
85
- });
66
+ return this.with(async function (message, next) {
67
+ return message.InfoType === 'change_auth' ? handler(message, next) : next(message);
86
68
  });
87
69
  }
88
70
  /**
@@ -90,10 +72,8 @@ class Server extends ServerInterface_1.default {
90
72
  * @param handler
91
73
  */
92
74
  handleAuthCancelled(handler) {
93
- return this.with(function (message, next) {
94
- return __awaiter(this, void 0, void 0, function* () {
95
- return message.InfoType === 'cancel_auth' ? handler(message, next) : next(message);
96
- });
75
+ return this.with(async function (message, next) {
76
+ return message.InfoType === 'cancel_auth' ? handler(message, next) : next(message);
97
77
  });
98
78
  }
99
79
  /**
@@ -101,10 +81,8 @@ class Server extends ServerInterface_1.default {
101
81
  * @param handler
102
82
  */
103
83
  handleUserCreated(handler) {
104
- return this.with(function (message, next) {
105
- return __awaiter(this, void 0, void 0, function* () {
106
- return message.InfoType === 'change_contact' && message.ChangeType === 'create_user' ? handler(message, next) : next(message);
107
- });
84
+ return this.with(async function (message, next) {
85
+ return message.InfoType === 'change_contact' && message.ChangeType === 'create_user' ? handler(message, next) : next(message);
108
86
  });
109
87
  }
110
88
  /**
@@ -112,10 +90,8 @@ class Server extends ServerInterface_1.default {
112
90
  * @param handler
113
91
  */
114
92
  handleUserUpdated(handler) {
115
- return this.with(function (message, next) {
116
- return __awaiter(this, void 0, void 0, function* () {
117
- return message.InfoType === 'change_contact' && message.ChangeType === 'update_user' ? handler(message, next) : next(message);
118
- });
93
+ return this.with(async function (message, next) {
94
+ return message.InfoType === 'change_contact' && message.ChangeType === 'update_user' ? handler(message, next) : next(message);
119
95
  });
120
96
  }
121
97
  /**
@@ -123,10 +99,8 @@ class Server extends ServerInterface_1.default {
123
99
  * @param handler
124
100
  */
125
101
  handleUserDeleted(handler) {
126
- return this.with(function (message, next) {
127
- return __awaiter(this, void 0, void 0, function* () {
128
- return message.InfoType === 'change_contact' && message.ChangeType === 'delete_user' ? handler(message, next) : next(message);
129
- });
102
+ return this.with(async function (message, next) {
103
+ return message.InfoType === 'change_contact' && message.ChangeType === 'delete_user' ? handler(message, next) : next(message);
130
104
  });
131
105
  }
132
106
  /**
@@ -134,10 +108,8 @@ class Server extends ServerInterface_1.default {
134
108
  * @param handler
135
109
  */
136
110
  handlePartyCreated(handler) {
137
- return this.with(function (message, next) {
138
- return __awaiter(this, void 0, void 0, function* () {
139
- return message.InfoType === 'change_contact' && message.ChangeType === 'create_party' ? handler(message, next) : next(message);
140
- });
111
+ return this.with(async function (message, next) {
112
+ return message.InfoType === 'change_contact' && message.ChangeType === 'create_party' ? handler(message, next) : next(message);
141
113
  });
142
114
  }
143
115
  /**
@@ -145,10 +117,8 @@ class Server extends ServerInterface_1.default {
145
117
  * @param handler
146
118
  */
147
119
  handlePartyUpdated(handler) {
148
- return this.with(function (message, next) {
149
- return __awaiter(this, void 0, void 0, function* () {
150
- return message.InfoType === 'change_contact' && message.ChangeType === 'update_party' ? handler(message, next) : next(message);
151
- });
120
+ return this.with(async function (message, next) {
121
+ return message.InfoType === 'change_contact' && message.ChangeType === 'update_party' ? handler(message, next) : next(message);
152
122
  });
153
123
  }
154
124
  /**
@@ -156,10 +126,8 @@ class Server extends ServerInterface_1.default {
156
126
  * @param handler
157
127
  */
158
128
  handlePartyDeleted(handler) {
159
- return this.with(function (message, next) {
160
- return __awaiter(this, void 0, void 0, function* () {
161
- return message.InfoType === 'change_contact' && message.ChangeType === 'delete_party' ? handler(message, next) : next(message);
162
- });
129
+ return this.with(async function (message, next) {
130
+ return message.InfoType === 'change_contact' && message.ChangeType === 'delete_party' ? handler(message, next) : next(message);
163
131
  });
164
132
  }
165
133
  /**
@@ -167,10 +135,8 @@ class Server extends ServerInterface_1.default {
167
135
  * @param handler
168
136
  */
169
137
  handleUserTagUpdated(handler) {
170
- return this.with(function (message, next) {
171
- return __awaiter(this, void 0, void 0, function* () {
172
- return message.InfoType === 'change_contact' && message.ChangeType === 'update_tag' ? handler(message, next) : next(message);
173
- });
138
+ return this.with(async function (message, next) {
139
+ return message.InfoType === 'change_contact' && message.ChangeType === 'update_tag' ? handler(message, next) : next(message);
174
140
  });
175
141
  }
176
142
  /**
@@ -178,10 +144,8 @@ class Server extends ServerInterface_1.default {
178
144
  * @param handler
179
145
  */
180
146
  handleShareAgentChanged(handler) {
181
- return this.with(function (message, next) {
182
- return __awaiter(this, void 0, void 0, function* () {
183
- return message.InfoType === 'share_agent_change' ? handler(message, next) : next(message);
184
- });
147
+ return this.with(async function (message, next) {
148
+ return message.InfoType === 'share_agent_change' ? handler(message, next) : next(message);
185
149
  });
186
150
  }
187
151
  /**
@@ -189,10 +153,8 @@ class Server extends ServerInterface_1.default {
189
153
  * @param handler
190
154
  */
191
155
  handleResetPermanentCode(handler) {
192
- return this.with(function (message, next) {
193
- return __awaiter(this, void 0, void 0, function* () {
194
- return message.InfoType === 'reset_permanent_code' ? handler(message, next) : next(message);
195
- });
156
+ return this.with(async function (message, next) {
157
+ return message.InfoType === 'reset_permanent_code' ? handler(message, next) : next(message);
196
158
  });
197
159
  }
198
160
  /**
@@ -200,10 +162,8 @@ class Server extends ServerInterface_1.default {
200
162
  * @param handler
201
163
  */
202
164
  handleChangeAppAdmin(handler) {
203
- return this.with(function (message, next) {
204
- return __awaiter(this, void 0, void 0, function* () {
205
- return message.MsgType === 'event' && message.Event === 'change_app_admin' ? handler(message, next) : next(message);
206
- });
165
+ return this.with(async function (message, next) {
166
+ return message.MsgType === 'event' && message.Event === 'change_app_admin' ? handler(message, next) : next(message);
207
167
  });
208
168
  }
209
169
  /**
@@ -212,30 +172,26 @@ class Server extends ServerInterface_1.default {
212
172
  * @returns
213
173
  */
214
174
  getRequestMessage(request = null) {
215
- return Message_1.default.createFromRequest(request !== null && request !== void 0 ? request : this.request);
175
+ return Message_1.default.createFromRequest(request ?? this.request);
216
176
  }
217
177
  decryptRequestMessage(query) {
218
- return (message, next) => __awaiter(this, void 0, void 0, function* () {
219
- var _a, _b, _c;
178
+ return async (message, next) => {
220
179
  if (!this.encryptor)
221
180
  return null;
222
- yield this.decryptMessage(message, this.encryptor, (_a = query['msg_signature']) !== null && _a !== void 0 ? _a : '', (_b = query['timestamp']) !== null && _b !== void 0 ? _b : '', (_c = query['nonce']) !== null && _c !== void 0 ? _c : '');
181
+ await this.decryptMessage(message, this.encryptor, query['msg_signature'] ?? '', query['timestamp'] ?? '', query['nonce'] ?? '');
223
182
  return next(message);
224
- });
183
+ };
225
184
  }
226
185
  /**
227
186
  * 获取解密后的消息
228
187
  * @param request 未设置该参数时,则从当前服务端收到的请求中获取
229
188
  * @returns
230
189
  */
231
- getDecryptedMessage() {
232
- return __awaiter(this, arguments, void 0, function* (request = null) {
233
- var _a, _b, _c;
234
- request = request !== null && request !== void 0 ? request : this.request;
235
- let message = yield this.getRequestMessage(request);
236
- let query = request.getQueryParams();
237
- return yield this.decryptMessage(message, this.encryptor, (_a = query['msg_signature']) !== null && _a !== void 0 ? _a : '', (_b = query['timestamp']) !== null && _b !== void 0 ? _b : '', (_c = query['nonce']) !== null && _c !== void 0 ? _c : '');
238
- });
190
+ async getDecryptedMessage(request = null) {
191
+ request = request ?? this.request;
192
+ let message = await this.getRequestMessage(request);
193
+ let query = request.getQueryParams();
194
+ return await this.decryptMessage(message, this.encryptor, query['msg_signature'] ?? '', query['timestamp'] ?? '', query['nonce'] ?? '');
239
195
  }
240
196
  }
241
197
  ;