@jayfong/x-server 2.12.7 → 2.12.15

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 (84) hide show
  1. package/lib/_cjs/cli/api_generator.js +20 -54
  2. package/lib/_cjs/cli/build_util.js +16 -45
  3. package/lib/_cjs/cli/cli.js +6 -27
  4. package/lib/_cjs/cli/deploy_util.js +0 -12
  5. package/lib/_cjs/cli/env_util.js +16 -49
  6. package/lib/_cjs/cli/template_util.js +26 -29
  7. package/lib/_cjs/core/define_bus.js +9 -6
  8. package/lib/_cjs/core/define_cron.js +0 -2
  9. package/lib/_cjs/core/define_handler.js +10 -12
  10. package/lib/_cjs/core/define_hook.js +0 -2
  11. package/lib/_cjs/core/define_server.js +0 -2
  12. package/lib/_cjs/core/define_task.js +7 -13
  13. package/lib/_cjs/core/get_handler_url.js +1 -2
  14. package/lib/_cjs/core/handler.js +8 -29
  15. package/lib/_cjs/core/http_error.js +0 -3
  16. package/lib/_cjs/core/http_header.js +8 -12
  17. package/lib/_cjs/core/server.js +8 -41
  18. package/lib/_cjs/core/types.js +0 -7
  19. package/lib/_cjs/index.js +0 -72
  20. package/lib/_cjs/plugins/cors.js +0 -7
  21. package/lib/_cjs/plugins/file_parser.js +2 -9
  22. package/lib/_cjs/plugins/form_body_parser.js +0 -6
  23. package/lib/_cjs/plugins/ws_parser.js +0 -6
  24. package/lib/_cjs/plugins/xml_parser.js +0 -12
  25. package/lib/_cjs/services/cache.js +18 -58
  26. package/lib/_cjs/services/captcha.js +0 -14
  27. package/lib/_cjs/services/dingtalk.js +0 -14
  28. package/lib/_cjs/services/dispose.js +0 -9
  29. package/lib/_cjs/services/emoji.js +2 -5
  30. package/lib/_cjs/services/jwt.js +0 -21
  31. package/lib/_cjs/services/log.js +0 -17
  32. package/lib/_cjs/services/mail.js +0 -9
  33. package/lib/_cjs/services/pay.js +9 -40
  34. package/lib/_cjs/services/rate_limit.js +0 -12
  35. package/lib/_cjs/services/redis.js +0 -4
  36. package/lib/_cjs/services/request.js +14 -299
  37. package/lib/_cjs/services/sensitive_words.js +13 -19
  38. package/lib/_cjs/x.js +0 -11
  39. package/lib/cli/api_generator.js +20 -42
  40. package/lib/cli/build_util.js +16 -19
  41. package/lib/cli/cli.js +6 -12
  42. package/lib/cli/deploy_util.js +0 -4
  43. package/lib/cli/env_util.js +16 -37
  44. package/lib/cli/template_util.d.ts +1 -0
  45. package/lib/cli/template_util.js +26 -14
  46. package/lib/core/define_bus.js +7 -5
  47. package/lib/core/define_handler.js +10 -9
  48. package/lib/core/define_task.js +7 -6
  49. package/lib/core/get_handler_url.js +2 -1
  50. package/lib/core/handler.js +9 -22
  51. package/lib/core/http_header.js +6 -9
  52. package/lib/core/server.js +8 -31
  53. package/lib/core/types.js +0 -7
  54. package/lib/index.js +4 -3
  55. package/lib/plugins/cors.js +0 -3
  56. package/lib/plugins/file_parser.js +2 -5
  57. package/lib/plugins/form_body_parser.js +0 -3
  58. package/lib/plugins/ws_parser.js +0 -3
  59. package/lib/plugins/xml_parser.js +0 -10
  60. package/lib/services/cache.js +18 -52
  61. package/lib/services/captcha.js +0 -7
  62. package/lib/services/dingtalk.js +0 -7
  63. package/lib/services/dispose.js +0 -5
  64. package/lib/services/emoji.js +2 -3
  65. package/lib/services/jwt.js +0 -13
  66. package/lib/services/log.js +0 -8
  67. package/lib/services/mail.js +0 -3
  68. package/lib/services/pay.js +9 -30
  69. package/lib/services/rate_limit.js +0 -8
  70. package/lib/services/redis.js +0 -1
  71. package/lib/services/request.d.ts +3 -130
  72. package/lib/services/request.js +5 -274
  73. package/lib/services/sensitive_words.js +13 -15
  74. package/package.json +4 -28
  75. package/README.md +0 -51
  76. package/lib/_cjs/cli/register.js +0 -8
  77. package/lib/_cjs/client_helper.js +0 -26
  78. package/lib/_cjs/types/_formstream.js +0 -1
  79. package/lib/cli/register.d.ts +0 -1
  80. package/lib/cli/register.js +0 -5
  81. package/lib/client_helper.d.ts +0 -1
  82. package/lib/client_helper.js +0 -16
  83. package/lib/types/_formstream.d.ts +0 -49
  84. package/lib/types/_formstream.js +0 -0
@@ -2,9 +2,7 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
  exports.XmlParserPlugin = void 0;
5
-
6
5
  var _fastXmlParser = require("fast-xml-parser");
7
-
8
6
  /**
9
7
  * XML 解析器插件
10
8
  *
@@ -14,7 +12,6 @@ class XmlParserPlugin {
14
12
  constructor(options) {
15
13
  this.options = options;
16
14
  }
17
-
18
15
  register(fastify) {
19
16
  const {
20
17
  contentType = ['text/xml', 'application/xml'],
@@ -23,38 +20,29 @@ class XmlParserPlugin {
23
20
  const xmlParser = new _fastXmlParser.XMLParser(parseOptions);
24
21
  fastify.addContentTypeParser(contentType, (req, payload, done) => {
25
22
  let body = '';
26
-
27
23
  const handleError = err => done(err);
28
-
29
24
  const handleData = data => body += data;
30
-
31
25
  const handleEnd = () => {
32
26
  let data;
33
27
  let err;
34
-
35
28
  try {
36
29
  data = xmlParser.parse(body);
37
30
  } catch (_err) {
38
31
  err = _err;
39
32
  }
40
-
41
33
  payload.removeListener('error', handleError);
42
34
  payload.removeListener('data', handleData);
43
35
  payload.removeListener('end', handleEnd);
44
-
45
36
  if (err) {
46
37
  done(err);
47
38
  } else {
48
39
  done(null, data);
49
40
  }
50
41
  };
51
-
52
42
  payload.on('error', handleError);
53
43
  payload.on('data', handleData);
54
44
  payload.on('end', handleEnd);
55
45
  });
56
46
  }
57
-
58
47
  }
59
-
60
48
  exports.XmlParserPlugin = XmlParserPlugin;
@@ -1,16 +1,11 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  exports.__esModule = true;
6
5
  exports.CacheService = void 0;
7
-
8
6
  var _cuid = _interopRequireDefault(require("cuid"));
9
-
10
7
  var _vtils = require("vtils");
11
-
12
8
  var _x = require("../x");
13
-
14
9
  class CacheService {
15
10
  constructor(options) {
16
11
  this.options = options;
@@ -18,10 +13,10 @@ class CacheService {
18
13
  this.prefix = void 0;
19
14
  this.prefix = `${_x.x.appId}:`;
20
15
  }
21
-
22
16
  toRedisKey(key) {
23
17
  return `${this.prefix}${Array.isArray(key) ? key.join('_') : String(key)}`;
24
18
  }
19
+
25
20
  /**
26
21
  * 设置缓存内容。对象类内容尽量避免使用,以免造成问题。
27
22
  *
@@ -30,68 +25,59 @@ class CacheService {
30
25
  * @param ttl 缓存时间
31
26
  * @returns 返回设置的缓存内容
32
27
  */
33
-
34
-
35
28
  async set(key, value, ttl = this.options.ttl) {
36
29
  const redisTtl = typeof ttl === 'function' ? ttl(value, this.options.ttl) : ttl;
37
-
38
30
  if (redisTtl) {
39
31
  const redisKey = this.toRedisKey(key);
40
32
  const redisValue = JSON.stringify(value);
41
- await _x.x.redis.set(redisKey, redisValue, // 毫秒
33
+ await _x.x.redis.set(redisKey, redisValue,
34
+ // 毫秒
42
35
  'PX', (0, _vtils.ms)(redisTtl));
43
36
  }
44
-
45
37
  return value;
46
38
  }
39
+
47
40
  /**
48
41
  * 存储值然后返回其对应的键,该键 URL 友好。
49
42
  *
50
43
  * @param value 值
51
44
  * @param ttl 存活时间
52
45
  */
53
-
54
-
55
46
  async save(value, ttl = this.options.ttl) {
56
47
  const key = `X__${(0, _cuid.default)()}`;
57
48
  await this.set(key, typeof value === 'function' ? await value(key) : value, ttl);
58
49
  return key;
59
50
  }
51
+
60
52
  /**
61
53
  * 获取缓存内容。
62
54
  *
63
55
  * @param key 键
64
56
  * @returns 返回获取到的缓存内容
65
57
  */
66
-
67
-
68
58
  async get(key) {
69
59
  const redisKey = this.toRedisKey(key);
70
60
  const gotValue = await _x.x.redis.get(redisKey);
71
-
72
61
  if (gotValue) {
73
62
  try {
74
63
  return JSON.parse(gotValue);
75
64
  } catch {}
76
65
  }
77
-
78
66
  return null;
79
67
  }
68
+
80
69
  /**
81
70
  * 获取多个缓存内容。
82
71
  *
83
72
  * @param keys 键
84
73
  * @returns 返回获取到的缓存内容
85
74
  */
86
-
87
-
88
75
  async getMany(...keys) {
89
76
  const redisKeys = keys.map(key => this.toRedisKey(key));
90
77
  if (!redisKeys.length) return [];
91
78
  const gotValues = await _x.x.redis.mget(...redisKeys);
92
79
  return gotValues.map(value => {
93
80
  if (value == null) return null;
94
-
95
81
  try {
96
82
  return JSON.parse(value);
97
83
  } catch {
@@ -99,18 +85,18 @@ class CacheService {
99
85
  }
100
86
  });
101
87
  }
88
+
102
89
  /**
103
90
  * 获取距离过期时间的毫秒数(未设置过期时间返回-1,键不存在返回-2)。
104
91
  *
105
92
  * @param key 键
106
93
  * @returns 返回距离过期时间的毫秒数
107
94
  */
108
-
109
-
110
95
  async ttl(key) {
111
96
  const redisKey = this.toRedisKey(key);
112
97
  return _x.x.redis.pttl(redisKey);
113
98
  }
99
+
114
100
  /**
115
101
  * 缓存内容。
116
102
  *
@@ -119,30 +105,23 @@ class CacheService {
119
105
  * @param ttl 缓存时间
120
106
  * @returns 返回获取到的内容
121
107
  */
122
-
123
-
124
108
  async remember(key, action, ttl = this.options.ttl) {
125
109
  let value = await this.get(key);
126
-
127
110
  if (value === null) {
128
111
  value = await action();
129
112
  await this.set(key, value, ttl);
130
113
  }
131
-
132
114
  return value;
133
115
  }
134
-
135
116
  async rememberMany(raws, key, action, ttl = this.options.ttl) {
136
117
  const keys = raws.map(key);
137
118
  const values = await this.getMany(...keys);
138
119
  const shouldUpdateIndexes = [];
139
-
140
120
  for (let i = 0, len = values.length; i < len; i++) {
141
121
  if (values[i] === null) {
142
122
  shouldUpdateIndexes.push(i);
143
123
  }
144
124
  }
145
-
146
125
  if (shouldUpdateIndexes.length) {
147
126
  const nextValues = await action(shouldUpdateIndexes.map(i => raws[i]));
148
127
  await Promise.all(nextValues.map(async (nextValue, index) => {
@@ -150,125 +129,106 @@ class CacheService {
150
129
  await this.set(keys[shouldUpdateIndexes[index]], nextValue, ttl);
151
130
  }));
152
131
  }
153
-
154
132
  return values;
155
133
  }
134
+
156
135
  /**
157
136
  * 自增。
158
137
  *
159
138
  * @param key 键
160
139
  * @param increment 增量
161
140
  */
162
-
163
-
164
141
  async increase(key, increment = 1) {
165
142
  const redisKey = this.toRedisKey(key);
166
143
  return _x.x.redis.incrby(redisKey, increment);
167
144
  }
145
+
168
146
  /**
169
147
  * 自减。
170
148
  *
171
149
  * @param key 键
172
150
  * @param decrement 减量
173
151
  */
174
-
175
-
176
152
  async decrease(key, decrement = 1) {
177
153
  return this.increase(key, -decrement);
178
154
  }
155
+
179
156
  /**
180
157
  * 新增元素。
181
158
  *
182
159
  * @param key 键
183
160
  * @param values 元素列表
184
161
  */
185
-
186
-
187
162
  async push(key, ...values) {
188
163
  const redisKey = this.toRedisKey(key);
189
164
  return _x.x.redis.rpush(redisKey, ...values.map(value => JSON.stringify(value)));
190
165
  }
166
+
191
167
  /**
192
168
  * 从头部弹出元素并返回。
193
169
  *
194
170
  * @param key 键
195
171
  * @param count 弹出元素个数
196
172
  */
197
-
198
-
199
173
  async shift(key, count = 1) {
200
174
  const redisKey = this.toRedisKey(key);
201
175
  const res = [];
202
-
203
176
  for (let i = 0; i < count; i++) {
204
177
  const item = await _x.x.redis.lpop(redisKey);
205
-
206
178
  if (item) {
207
179
  res.push(JSON.parse(item));
208
180
  } else {
209
181
  break;
210
182
  }
211
183
  }
212
-
213
184
  return res;
214
185
  }
186
+
215
187
  /**
216
188
  * 删除缓存。
217
189
  *
218
190
  * @param keys 键列表
219
191
  */
220
-
221
-
222
192
  async remove(...keys) {
223
193
  if (!keys.length) {
224
194
  return 0;
225
195
  }
226
-
227
196
  return _x.x.redis.del(...keys.map(key => this.toRedisKey(key)));
228
197
  }
198
+
229
199
  /**
230
200
  * 清空全部缓存。
231
201
  */
232
-
233
-
234
202
  async clearAll() {
235
203
  const keys = await _x.x.redis.keys(`${this.prefix}*`);
236
-
237
204
  if (keys.length) {
238
205
  return _x.x.redis.del(...keys);
239
206
  }
240
-
241
207
  return 0;
242
208
  }
209
+
243
210
  /**
244
211
  * 清空指定前缀的缓存。
245
212
  */
246
-
247
-
248
213
  async clear(...prefixes) {
249
214
  if (!prefixes.length) {
250
215
  return 0;
251
216
  }
252
-
253
217
  const keys = (await Promise.all(prefixes.map(prefix => _x.x.redis.keys(`${this.toRedisKey(prefix)}*`)))).flat();
254
-
255
218
  if (keys.length) {
256
219
  return _x.x.redis.del(...keys);
257
220
  }
258
-
259
221
  return 0;
260
222
  }
223
+
261
224
  /**
262
225
  * 派生出一个指定类型的缓存服务。
263
226
  */
264
-
265
-
266
227
  fork(options) {
267
- return options ? new CacheService({ ...this.options,
228
+ return options ? new CacheService({
229
+ ...this.options,
268
230
  ...options
269
231
  }) : this;
270
232
  }
271
-
272
233
  }
273
-
274
234
  exports.CacheService = CacheService;
@@ -1,22 +1,16 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  exports.__esModule = true;
6
5
  exports.CaptchaService = void 0;
7
-
8
6
  var _svgCaptcha = _interopRequireDefault(require("svg-captcha"));
9
-
10
7
  var _miniSvgDataUri = _interopRequireDefault(require("mini-svg-data-uri"));
11
-
12
8
  var _x = require("../x");
13
-
14
9
  class CaptchaService {
15
10
  constructor(options) {
16
11
  this.options = options;
17
12
  this.serviceName = 'captcha';
18
13
  }
19
-
20
14
  async generate(scene) {
21
15
  const code = Math.random().toString().slice(0 - this.options.size);
22
16
  const token = await _x.x.cache.save({
@@ -28,7 +22,6 @@ class CaptchaService {
28
22
  code: code
29
23
  };
30
24
  }
31
-
32
25
  async generateDataUrl(scene) {
33
26
  const {
34
27
  text: code,
@@ -36,7 +29,6 @@ class CaptchaService {
36
29
  } = _svgCaptcha.default.create({
37
30
  size: this.options.size
38
31
  });
39
-
40
32
  const token = await _x.x.cache.save({
41
33
  code,
42
34
  scene
@@ -48,22 +40,16 @@ class CaptchaService {
48
40
  dataUrl: dataUrl
49
41
  };
50
42
  }
51
-
52
43
  async verify(options) {
53
44
  if (options.code.length !== this.options.size) {
54
45
  return false;
55
46
  }
56
-
57
47
  const expected = await _x.x.cache.get(options.token);
58
-
59
48
  if (expected == null) {
60
49
  return false;
61
50
  }
62
-
63
51
  await _x.x.cache.remove(options.token);
64
52
  return expected.scene === options.scene && options.code.toLowerCase() === expected.code.toLowerCase();
65
53
  }
66
-
67
54
  }
68
-
69
55
  exports.CaptchaService = CaptchaService;
@@ -1,25 +1,18 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  exports.__esModule = true;
6
5
  exports.DingtalkService = void 0;
7
-
8
6
  var _crypto = _interopRequireDefault(require("crypto"));
9
-
10
7
  var _got = _interopRequireDefault(require("got"));
11
-
12
8
  class DingtalkService {
13
9
  constructor(options) {
14
10
  this.options = options;
15
11
  this.serviceName = 'dingtalk';
16
12
  }
17
-
18
13
  async send(options) {
19
14
  const timestamp = Date.now();
20
-
21
15
  const sign = _crypto.default.createHmac('sha256', this.options.secret).update(`${timestamp}\n${this.options.secret}`).digest('base64');
22
-
23
16
  const data = {
24
17
  msgtype: 'markdown',
25
18
  markdown: {
@@ -31,16 +24,13 @@ class DingtalkService {
31
24
  isAtAll: options.at === 'all'
32
25
  }
33
26
  };
34
-
35
27
  if (!data.at.isAtAll && data.at.atMobiles.length) {
36
28
  const atMobiles = data.at.atMobiles.filter(mobile => !data.markdown.text.includes(`@${mobile}`));
37
-
38
29
  if (atMobiles.length) {
39
30
  const atMobilesText = atMobiles.map(mobile => `@${mobile}`).join(' ');
40
31
  data.markdown.text += `<!-- ${atMobilesText} -->`;
41
32
  }
42
33
  }
43
-
44
34
  const {
45
35
  body
46
36
  } = await _got.default.post('https://oapi.dingtalk.com/robot/send', {
@@ -52,14 +42,10 @@ class DingtalkService {
52
42
  },
53
43
  json: data
54
44
  });
55
-
56
45
  if (body.errcode !== 0) {
57
46
  throw new Error(body.errmsg);
58
47
  }
59
-
60
48
  return body;
61
49
  }
62
-
63
50
  }
64
-
65
51
  exports.DingtalkService = DingtalkService;
@@ -1,33 +1,24 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  exports.__esModule = true;
6
5
  exports.DisposeService = void 0;
7
-
8
6
  var _exitHook = _interopRequireDefault(require("exit-hook"));
9
-
10
7
  class DisposeService {
11
8
  constructor(options) {
12
9
  var _this$options;
13
-
14
10
  this.options = options;
15
11
  this.serviceName = 'dispose';
16
12
  this.disposes = [];
17
-
18
13
  if ((_this$options = this.options) != null && _this$options.disposeOnExit) {
19
14
  (0, _exitHook.default)(() => this.dispose());
20
15
  }
21
16
  }
22
-
23
17
  add(fn) {
24
18
  this.disposes.push(fn);
25
19
  }
26
-
27
20
  dispose() {
28
21
  return Promise.all(this.disposes.map(dispose => dispose()));
29
22
  }
30
-
31
23
  }
32
-
33
24
  exports.DisposeService = DisposeService;
@@ -2019,19 +2019,16 @@ const softbankOrDocomoOrAuOrGoogleToUnified = {
2019
2019
  "󾬫": "㊙️",
2020
2020
  "": "㊙️",
2021
2021
  "": "㊙️"
2022
- }; // softbankOrDocomoOrAuOrGoogleToUnified
2022
+ };
2023
+ // softbankOrDocomoOrAuOrGoogleToUnified
2023
2024
 
2024
2025
  const softbankOrDocomoOrGoogleRegExp = new RegExp(Object.keys(softbankOrDocomoOrAuOrGoogleToUnified).join('|'), 'g');
2025
-
2026
2026
  class EmojiService {
2027
2027
  constructor() {
2028
2028
  this.serviceName = 'emoji';
2029
2029
  }
2030
-
2031
2030
  unify(text) {
2032
2031
  return text.replace(softbankOrDocomoOrGoogleRegExp, v => softbankOrDocomoOrAuOrGoogleToUnified[v]);
2033
2032
  }
2034
-
2035
2033
  }
2036
-
2037
2034
  exports.EmojiService = EmojiService;
@@ -1,48 +1,35 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  exports.__esModule = true;
6
5
  exports.JwtService = void 0;
7
-
8
6
  var _jsonwebtoken = _interopRequireDefault(require("jsonwebtoken"));
9
-
10
7
  var _date = require("vtils/date");
11
-
12
8
  var _http_error = require("../core/http_error");
13
-
14
9
  var _lruCache = require("lru-cache");
15
-
16
10
  var _vtils = require("vtils");
17
-
18
11
  class JwtService {
19
12
  constructor(options) {
20
13
  this.options = options;
21
14
  this.serviceName = 'jwt';
22
15
  this.cache = void 0;
23
-
24
16
  if (options.cache) {
25
17
  this.cache = new _lruCache.LRUCache(options.cache);
26
18
  }
27
19
  }
28
-
29
20
  sign(payload, ttl = this.options.ttl) {
30
21
  const token = _jsonwebtoken.default.sign(payload, this.options.secret, {
31
22
  expiresIn: (0, _vtils.ms)(ttl, true)
32
23
  });
33
-
34
24
  if (this.cache) {
35
25
  this.cache.set(token, payload, {
36
26
  ttl: (0, _vtils.ms)(ttl)
37
27
  });
38
28
  }
39
-
40
29
  return token;
41
30
  }
42
-
43
31
  async verify(token) {
44
32
  var _this$options$onVerif, _this$options;
45
-
46
33
  const data = await new Promise((resolve, reject) => {
47
34
  if (this.cache && this.cache.has(token)) {
48
35
  resolve(this.cache.get(token));
@@ -58,7 +45,6 @@ class JwtService {
58
45
  ttl: (0, _date.differenceInMilliseconds)((0, _date.fromUnixTime)(data.exp), new Date())
59
46
  });
60
47
  }
61
-
62
48
  resolve(data);
63
49
  }
64
50
  });
@@ -67,23 +53,16 @@ class JwtService {
67
53
  await ((_this$options$onVerif = (_this$options = this.options).onVerify) == null ? void 0 : _this$options$onVerif.call(_this$options, data));
68
54
  return data;
69
55
  }
70
-
71
56
  async verifyFromHttpHeaders(headers) {
72
57
  const authorization = headers.authorization || headers['sec-websocket-protocol'] && `Bearer ${headers['sec-websocket-protocol']}` || '';
73
-
74
58
  if (!authorization) {
75
59
  throw new _http_error.HttpError.Unauthorized('header');
76
60
  }
77
-
78
61
  const [scheme, token] = authorization.split(' ');
79
-
80
62
  if (scheme.toLowerCase() !== 'bearer') {
81
63
  throw new _http_error.HttpError.Unauthorized('bearer');
82
64
  }
83
-
84
65
  return this.verify(token);
85
66
  }
86
-
87
67
  }
88
-
89
68
  exports.JwtService = JwtService;
@@ -1,43 +1,32 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  exports.__esModule = true;
6
5
  exports.LogService = void 0;
7
-
8
6
  var _fsExtra = _interopRequireDefault(require("fs-extra"));
9
-
10
7
  var _path = _interopRequireDefault(require("path"));
11
-
12
8
  var _date = require("vtils/date");
13
-
14
9
  var _vtils = require("vtils");
15
-
16
10
  var _x = require("../x");
17
-
18
11
  class LogService {
19
12
  constructor() {
20
13
  this.serviceName = 'log';
21
14
  this.separator = '\t\t\t';
22
15
  this.getLogWriter = (0, _vtils.memoize)(logFile => {
23
16
  _fsExtra.default.ensureFileSync(logFile);
24
-
25
17
  return _fsExtra.default.createWriteStream(logFile, {
26
18
  flags: 'a'
27
19
  });
28
20
  }, logFile => logFile);
29
21
  }
30
-
31
22
  getLogFile(date) {
32
23
  const year = date.getFullYear();
33
24
  const month = date.getMonth() + 1;
34
25
  return _path.default.join(_x.x.dataDir, `log/${year}/${month < 10 ? `0${month}` : month}.log`);
35
26
  }
36
-
37
27
  get logFile() {
38
28
  return this.getLogFile(new Date());
39
29
  }
40
-
41
30
  parseLogLineText(text) {
42
31
  const [time, level, title, ...desc] = text.split(this.separator);
43
32
  return {
@@ -51,11 +40,9 @@ class LogService {
51
40
  }, {})
52
41
  };
53
42
  }
54
-
55
43
  log(payload) {
56
44
  this.getLogWriter(this.logFile).write(`${[(0, _date.formatDate)(new Date(), 'yyyy-mm-dd hh:ii:ss'), payload.level, payload.title, ...Object.keys(payload.desc || {}).map(key => `${key}:${payload.desc[key]}`)].join(this.separator).replace(/[\r\n]+/g, ' ')}\n`);
57
45
  }
58
-
59
46
  info(title, desc) {
60
47
  this.log({
61
48
  level: 'info',
@@ -63,7 +50,6 @@ class LogService {
63
50
  desc
64
51
  });
65
52
  }
66
-
67
53
  success(title, desc) {
68
54
  this.log({
69
55
  level: 'success',
@@ -71,7 +57,6 @@ class LogService {
71
57
  desc
72
58
  });
73
59
  }
74
-
75
60
  error(title, desc) {
76
61
  this.log({
77
62
  level: 'error',
@@ -79,7 +64,5 @@ class LogService {
79
64
  desc
80
65
  });
81
66
  }
82
-
83
67
  }
84
-
85
68
  exports.LogService = LogService;
@@ -1,21 +1,16 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  exports.__esModule = true;
6
5
  exports.MailService = void 0;
7
-
8
6
  var _nodemailer = _interopRequireDefault(require("nodemailer"));
9
-
10
7
  var _x = require("../x");
11
-
12
8
  class MailService {
13
9
  constructor(options) {
14
10
  this.options = options;
15
11
  this.serviceName = 'mail';
16
12
  this.transporter = void 0;
17
13
  }
18
-
19
14
  async send(options) {
20
15
  if (!this.transporter) {
21
16
  this.transporter = _nodemailer.default.createTransport({
@@ -28,13 +23,9 @@ class MailService {
28
23
  }
29
24
  });
30
25
  await this.transporter.verify();
31
-
32
26
  _x.x.dispose.add(() => this.transporter.close());
33
27
  }
34
-
35
28
  return this.transporter.sendMail(options);
36
29
  }
37
-
38
30
  }
39
-
40
31
  exports.MailService = MailService;