@jayfong/x-server 1.24.2 → 1.26.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,28 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.26.1](https://github.com/jfWorks/x-server/compare/v1.26.0...v1.26.1) (2022-05-03)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * defineTask ([7d5a5d2](https://github.com/jfWorks/x-server/commit/7d5a5d247a63301dc46042238a6d31f7f4cb5423))
11
+
12
+ ## [1.26.0](https://github.com/jfWorks/x-server/compare/v1.25.0...v1.26.0) (2022-05-02)
13
+
14
+
15
+ ### Features
16
+
17
+ * add SensitiveWordsService ([ee03592](https://github.com/jfWorks/x-server/commit/ee03592f5acd795b03fa65717ea276db66f453c1))
18
+
19
+ ## [1.25.0](https://github.com/jfWorks/x-server/compare/v1.24.2...v1.25.0) (2022-05-02)
20
+
21
+
22
+ ### Features
23
+
24
+ * add FormBodyParserPlugin ([b51392c](https://github.com/jfWorks/x-server/commit/b51392c5dce6480f9f5250192f676421c6a1cad2))
25
+ * ctx add req res ([ccd1ea0](https://github.com/jfWorks/x-server/commit/ccd1ea08f9d10e0b29ff235b1b6572b180798d8d))
26
+
5
27
  ### [1.24.2](https://github.com/jfWorks/x-server/compare/v1.24.1...v1.24.2) (2022-05-02)
6
28
 
7
29
 
@@ -9,7 +9,7 @@ var _bull = _interopRequireDefault(require("bull"));
9
9
 
10
10
  var _x = require("../x");
11
11
 
12
- async function defineTask(options) {
12
+ function defineTask(options) {
13
13
  const queue = new _bull.default(options.name, {
14
14
  redis: _x.x.redis.options,
15
15
  prefix: `${_x.x.appId}_task`
@@ -104,7 +104,9 @@ class Server {
104
104
  headers: req.headers,
105
105
  setHeader: (k, v) => res.header(k, v),
106
106
  redirect: undefined,
107
- ws: req
107
+ ws: req,
108
+ req: req,
109
+ res: res
108
110
  });
109
111
  return;
110
112
  }
@@ -132,7 +134,9 @@ class Server {
132
134
  headers: req.headers,
133
135
  setHeader: (k, v) => res.header(k, v),
134
136
  redirect: url => res.redirect(url),
135
- ws: undefined
137
+ ws: undefined,
138
+ req: req,
139
+ res: res
136
140
  });
137
141
  return data;
138
142
  }
package/lib/_cjs/index.js CHANGED
@@ -114,6 +114,14 @@ Object.keys(_file_parser).forEach(function (key) {
114
114
  exports[key] = _file_parser[key];
115
115
  });
116
116
 
117
+ var _form_body_parser = require("./plugins/form_body_parser");
118
+
119
+ Object.keys(_form_body_parser).forEach(function (key) {
120
+ if (key === "default" || key === "__esModule") return;
121
+ if (key in exports && exports[key] === _form_body_parser[key]) return;
122
+ exports[key] = _form_body_parser[key];
123
+ });
124
+
117
125
  var _ws_parser = require("./plugins/ws_parser");
118
126
 
119
127
  Object.keys(_ws_parser).forEach(function (key) {
@@ -202,6 +210,14 @@ Object.keys(_redis).forEach(function (key) {
202
210
  exports[key] = _redis[key];
203
211
  });
204
212
 
213
+ var _sensitive_words = require("./services/sensitive_words");
214
+
215
+ Object.keys(_sensitive_words).forEach(function (key) {
216
+ if (key === "default" || key === "__esModule") return;
217
+ if (key in exports && exports[key] === _sensitive_words[key]) return;
218
+ exports[key] = _sensitive_words[key];
219
+ });
220
+
205
221
  var _x = require("./x");
206
222
 
207
223
  Object.keys(_x).forEach(function (key) {
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ exports.__esModule = true;
6
+ exports.FormBodyParserPlugin = void 0;
7
+
8
+ var _formbody = _interopRequireDefault(require("@fastify/formbody"));
9
+
10
+ /**
11
+ * POST application/x-www-form-urlencoded 解析器插件
12
+ */
13
+ class FormBodyParserPlugin {
14
+ constructor(options) {
15
+ this.options = options;
16
+ }
17
+
18
+ register(fastify) {
19
+ fastify.register(_formbody.default, this.options);
20
+ }
21
+
22
+ }
23
+
24
+ exports.FormBodyParserPlugin = FormBodyParserPlugin;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ exports.__esModule = true;
6
+ exports.SensitiveWordsService = void 0;
7
+
8
+ var _mintFilter = _interopRequireDefault(require("mint-filter"));
9
+
10
+ class SensitiveWordsService {
11
+ constructor(options) {
12
+ this.options = options;
13
+ this.serviceName = 'sensitiveWords';
14
+ this.mint = void 0;
15
+ }
16
+
17
+ async filter(text) {
18
+ if (!this.mint) {
19
+ this.mint = new _mintFilter.default(this.options.words);
20
+ }
21
+
22
+ const res = await this.mint.filter(text, {
23
+ every: true,
24
+ replace: true,
25
+ words: false
26
+ });
27
+ return res.text;
28
+ }
29
+
30
+ }
31
+
32
+ exports.SensitiveWordsService = SensitiveWordsService;
@@ -1,2 +1,2 @@
1
1
  import type { XTask } from './types';
2
- export declare function defineTask<T>(options: XTask.Options<T>): Promise<XTask.Task<T>>;
2
+ export declare function defineTask<T>(options: XTask.Options<T>): XTask.Task<T>;
@@ -1,6 +1,6 @@
1
1
  import Queue from 'bull';
2
2
  import { x } from "../x";
3
- export async function defineTask(options) {
3
+ export function defineTask(options) {
4
4
  const queue = new Queue(options.name, {
5
5
  redis: x.redis.options,
6
6
  prefix: `${x.appId}_task`
@@ -89,7 +89,9 @@ export class Server {
89
89
  headers: req.headers,
90
90
  setHeader: (k, v) => res.header(k, v),
91
91
  redirect: undefined,
92
- ws: req
92
+ ws: req,
93
+ req: req,
94
+ res: res
93
95
  });
94
96
  return;
95
97
  }
@@ -117,7 +119,9 @@ export class Server {
117
119
  headers: req.headers,
118
120
  setHeader: (k, v) => res.header(k, v),
119
121
  redirect: url => res.redirect(url),
120
- ws: undefined
122
+ ws: undefined,
123
+ req: req,
124
+ res: res
121
125
  });
122
126
  return data;
123
127
  }
@@ -1,6 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { BasePlugin } from '../plugins/base';
3
3
  import { BaseService } from '../services/base';
4
+ import { FastifyReply, FastifyRequest } from 'fastify';
4
5
  import { yup } from 'vtils/validator';
5
6
  import type { AsyncOrSync, LiteralUnion, OneOrMore, RequiredDeep } from 'vtils/types';
6
7
  import type { DisposeService } from '../services/dispose';
@@ -65,6 +66,14 @@ export declare namespace XHandler {
65
66
  * WS
66
67
  */
67
68
  ws: SocketStream;
69
+ /**
70
+ * Fastify Request
71
+ */
72
+ req: FastifyRequest;
73
+ /**
74
+ * Fastify Response
75
+ */
76
+ res: FastifyReply;
68
77
  }
69
78
  type Handle<TReqData extends any = void, TResData extends any = void, TReqMethod extends Method = Method> = (
70
79
  /**
package/lib/index.d.ts CHANGED
@@ -12,6 +12,7 @@ export * from './core/types';
12
12
  export * from './plugins/base';
13
13
  export * from './plugins/cors';
14
14
  export * from './plugins/file_parser';
15
+ export * from './plugins/form_body_parser';
15
16
  export * from './plugins/ws_parser';
16
17
  export * from './plugins/xml_parser';
17
18
  export * from './services/base';
@@ -23,5 +24,6 @@ export * from './services/mail';
23
24
  export * from './services/pay';
24
25
  export * from './services/rate_limit';
25
26
  export * from './services/redis';
27
+ export * from './services/sensitive_words';
26
28
  export * from './x';
27
29
  export * from '.x/models';
package/lib/index.js CHANGED
@@ -13,6 +13,7 @@ export * from "./core/types";
13
13
  export * from "./plugins/base";
14
14
  export * from "./plugins/cors";
15
15
  export * from "./plugins/file_parser";
16
+ export * from "./plugins/form_body_parser";
16
17
  export * from "./plugins/ws_parser";
17
18
  export * from "./plugins/xml_parser";
18
19
  export * from "./services/base";
@@ -24,6 +25,7 @@ export * from "./services/mail";
24
25
  export * from "./services/pay";
25
26
  export * from "./services/rate_limit";
26
27
  export * from "./services/redis";
28
+ export * from "./services/sensitive_words";
27
29
  export * from "./x"; // @endindex
28
30
  // @ts-ignore
29
31
 
@@ -0,0 +1,13 @@
1
+ import { FormBodyPluginOptions } from '@fastify/formbody';
2
+ import { BasePlugin } from './base';
3
+ import { FastifyInstance } from 'fastify';
4
+ export interface FormBodyParserPluginOptions extends FormBodyPluginOptions {
5
+ }
6
+ /**
7
+ * POST application/x-www-form-urlencoded 解析器插件
8
+ */
9
+ export declare class FormBodyParserPlugin implements BasePlugin {
10
+ private options?;
11
+ constructor(options?: FormBodyParserPluginOptions);
12
+ register(fastify: FastifyInstance): void;
13
+ }
@@ -0,0 +1,15 @@
1
+ import FastifyFormBody from '@fastify/formbody';
2
+
3
+ /**
4
+ * POST application/x-www-form-urlencoded 解析器插件
5
+ */
6
+ export class FormBodyParserPlugin {
7
+ constructor(options) {
8
+ this.options = options;
9
+ }
10
+
11
+ register(fastify) {
12
+ fastify.register(FastifyFormBody, this.options);
13
+ }
14
+
15
+ }
@@ -0,0 +1,16 @@
1
+ import { BaseService } from './base';
2
+ export interface SensitiveWordsOptions {
3
+ words: string[];
4
+ }
5
+ export declare class SensitiveWordsService implements BaseService {
6
+ private options;
7
+ serviceName: string;
8
+ private mint;
9
+ constructor(options: SensitiveWordsOptions);
10
+ filter(text: string): Promise<string>;
11
+ }
12
+ declare module '../x' {
13
+ interface X {
14
+ sensitiveWords: SensitiveWordsService;
15
+ }
16
+ }
@@ -0,0 +1,22 @@
1
+ import Mint from 'mint-filter';
2
+ export class SensitiveWordsService {
3
+ constructor(options) {
4
+ this.options = options;
5
+ this.serviceName = 'sensitiveWords';
6
+ this.mint = void 0;
7
+ }
8
+
9
+ async filter(text) {
10
+ if (!this.mint) {
11
+ this.mint = new Mint(this.options.words);
12
+ }
13
+
14
+ const res = await this.mint.filter(text, {
15
+ every: true,
16
+ replace: true,
17
+ words: false
18
+ });
19
+ return res.text;
20
+ }
21
+
22
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "1.24.2",
3
+ "version": "1.26.1",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",
@@ -26,6 +26,7 @@
26
26
  }
27
27
  },
28
28
  "dependencies": {
29
+ "@fastify/formbody": "^6.0.0",
29
30
  "@prisma/client": "^3.12.0",
30
31
  "@types/bull": "^3.15.8",
31
32
  "@types/busboy": "^0.3.2",
@@ -56,6 +57,7 @@
56
57
  "ioredis": "^4.28.5",
57
58
  "jsonwebtoken": "^8.5.1",
58
59
  "mini-svg-data-uri": "^1.4.4",
60
+ "mint-filter": "^3.0.1",
59
61
  "node-ssh": "^12.0.4",
60
62
  "nodemailer": "^6.7.3",
61
63
  "pino-pretty": "^7.6.1",