@jayfong/x-server 1.26.3 → 1.26.6
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 +21 -0
- package/lib/_cjs/cli/build_util.js +1 -1
- package/lib/_cjs/services/mail.js +2 -2
- package/lib/_cjs/services/sensitive_words.js +8 -1
- package/lib/cli/build_util.js +1 -1
- package/lib/services/cache.d.ts +8 -9
- package/lib/services/captcha.d.ts +10 -10
- package/lib/services/dispose.d.ts +2 -2
- package/lib/services/mail.d.ts +3 -1
- package/lib/services/mail.js +2 -2
- package/lib/services/pay.d.ts +8 -8
- package/lib/services/rate_limit.d.ts +2 -2
- package/lib/services/redis.d.ts +2 -0
- package/lib/services/sensitive_words.d.ts +10 -3
- package/lib/services/sensitive_words.js +9 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,27 @@
|
|
|
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.6](https://github.com/jfWorks/x-server/compare/v1.26.5...v1.26.6) (2022-05-07)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* ServiceOptions ([bd86e66](https://github.com/jfWorks/x-server/commit/bd86e6618a5e115cbba26b56dfbeba2a427bfda7))
|
|
11
|
+
|
|
12
|
+
### [1.26.5](https://github.com/jfWorks/x-server/compare/v1.26.4...v1.26.5) (2022-05-06)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* export MailServiceSendOptions type ([7c47c23](https://github.com/jfWorks/x-server/commit/7c47c23a0d2f4d9a08f49e66a0155e282518257f))
|
|
18
|
+
|
|
19
|
+
### [1.26.4](https://github.com/jfWorks/x-server/compare/v1.26.3...v1.26.4) (2022-05-03)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
* bull ([5c92fc2](https://github.com/jfWorks/x-server/commit/5c92fc2f54c6e7ddcc237553d840b72af27d8630))
|
|
25
|
+
|
|
5
26
|
### [1.26.3](https://github.com/jfWorks/x-server/compare/v1.26.2...v1.26.3) (2022-05-03)
|
|
6
27
|
|
|
7
28
|
|
|
@@ -108,7 +108,7 @@ class BuildUtil {
|
|
|
108
108
|
filter: /\/bull\/lib\/commands\/index\.js$/
|
|
109
109
|
}, async args => {
|
|
110
110
|
let js = await _fsExtra.default.readFile(args.path, 'utf-8');
|
|
111
|
-
js = js.replace(
|
|
111
|
+
js = js.replace(/__dirname/g, '"./assets/bull/commands"');
|
|
112
112
|
await _fsExtra.default.copy(_nodePath.default.dirname(require.resolve('bull/lib/commands/index.js')), _nodePath.default.join(distDir, 'assets/bull/commands'));
|
|
113
113
|
return {
|
|
114
114
|
contents: js,
|
|
@@ -16,7 +16,7 @@ class MailService {
|
|
|
16
16
|
this.transporter = void 0;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
async send(
|
|
19
|
+
async send(options) {
|
|
20
20
|
if (!this.transporter) {
|
|
21
21
|
this.transporter = _nodemailer.default.createTransport({
|
|
22
22
|
host: this.options.host,
|
|
@@ -32,7 +32,7 @@ class MailService {
|
|
|
32
32
|
_x.x.dispose.add(() => this.transporter.close());
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
return this.transporter.sendMail(
|
|
35
|
+
return this.transporter.sendMail(options);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
}
|
|
@@ -7,14 +7,21 @@ exports.SensitiveWordsService = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _mintFilter = _interopRequireDefault(require("mint-filter"));
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* 敏感词服务。
|
|
12
|
+
*/
|
|
10
13
|
class SensitiveWordsService {
|
|
11
14
|
constructor(options) {
|
|
12
15
|
this.options = options;
|
|
13
16
|
this.serviceName = 'sensitiveWords';
|
|
14
17
|
this.mint = void 0;
|
|
15
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* 处理文本,敏感词将被替换为 * 号。
|
|
21
|
+
*/
|
|
16
22
|
|
|
17
|
-
|
|
23
|
+
|
|
24
|
+
async process(text) {
|
|
18
25
|
if (!this.mint) {
|
|
19
26
|
this.mint = new _mintFilter.default(this.options.words);
|
|
20
27
|
}
|
package/lib/cli/build_util.js
CHANGED
|
@@ -84,7 +84,7 @@ export class BuildUtil {
|
|
|
84
84
|
filter: /\/bull\/lib\/commands\/index\.js$/
|
|
85
85
|
}, async args => {
|
|
86
86
|
let js = await fs.readFile(args.path, 'utf-8');
|
|
87
|
-
js = js.replace(
|
|
87
|
+
js = js.replace(/__dirname/g, '"./assets/bull/commands"');
|
|
88
88
|
await fs.copy(path.dirname(require.resolve('bull/lib/commands/index.js')), path.join(distDir, 'assets/bull/commands'));
|
|
89
89
|
return {
|
|
90
90
|
contents: js,
|
package/lib/services/cache.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { AsyncOrSync, IsEmptyArray, NonEmptyArray } from 'vtils/types';
|
|
2
2
|
import { BaseService } from './base';
|
|
3
3
|
import { MsValue } from 'vtils/date';
|
|
4
|
-
export
|
|
5
|
-
export interface CacheOptions {
|
|
4
|
+
export interface CacheServiceOptions {
|
|
6
5
|
/** 默认过期时间 */
|
|
7
|
-
ttl:
|
|
6
|
+
ttl: MsValue;
|
|
8
7
|
}
|
|
9
8
|
declare type Data = {
|
|
10
9
|
[K in string]: (...args: any[]) => any;
|
|
@@ -18,10 +17,10 @@ declare type KeyPathForNumberValue<T extends Data> = {
|
|
|
18
17
|
}[keyof T];
|
|
19
18
|
declare type Value<T extends Data, P extends KeyPath<T>> = ReturnType<T[P extends any[] ? P[0] : P]>;
|
|
20
19
|
export declare class CacheService<TData extends Data = Data, TKey extends Key<TData> = any, TKeyPath extends KeyPath<TData> = any, TKeyPathForNumberValue extends KeyPathForNumberValue<TData> = any> implements BaseService {
|
|
21
|
-
options:
|
|
20
|
+
options: CacheServiceOptions;
|
|
22
21
|
serviceName: string;
|
|
23
22
|
private prefix;
|
|
24
|
-
constructor(options:
|
|
23
|
+
constructor(options: CacheServiceOptions);
|
|
25
24
|
private toRedisKey;
|
|
26
25
|
/**
|
|
27
26
|
* 设置缓存内容。对象类内容尽量避免使用,以免造成问题。
|
|
@@ -31,14 +30,14 @@ export declare class CacheService<TData extends Data = Data, TKey extends Key<TD
|
|
|
31
30
|
* @param ttl 缓存时间(单位:时)
|
|
32
31
|
* @returns 返回设置的缓存内容
|
|
33
32
|
*/
|
|
34
|
-
set<K extends TKeyPath, V extends Value<TData, K>>(key: K, value: V, ttl?:
|
|
33
|
+
set<K extends TKeyPath, V extends Value<TData, K>>(key: K, value: V, ttl?: MsValue | ((data: V, defaultTTL: MsValue) => MsValue)): Promise<V>;
|
|
35
34
|
/**
|
|
36
35
|
* 存储值然后返回其对应的键,该键 URL 友好。
|
|
37
36
|
*
|
|
38
37
|
* @param value 值
|
|
39
38
|
* @param ttl 存活时间
|
|
40
39
|
*/
|
|
41
|
-
save<T>(value: T | ((key: string) => AsyncOrSync<T>), ttl?:
|
|
40
|
+
save<T>(value: T | ((key: string) => AsyncOrSync<T>), ttl?: MsValue): Promise<string>;
|
|
42
41
|
/**
|
|
43
42
|
* 获取缓存内容。
|
|
44
43
|
*
|
|
@@ -61,7 +60,7 @@ export declare class CacheService<TData extends Data = Data, TKey extends Key<TD
|
|
|
61
60
|
* @param ttl 缓存时间(单位:时)
|
|
62
61
|
* @returns 返回获取到的内容
|
|
63
62
|
*/
|
|
64
|
-
remember<K extends TKeyPath, V extends Value<TData, K>>(key: K, action: () => V | Promise<V>, ttl?:
|
|
63
|
+
remember<K extends TKeyPath, V extends Value<TData, K>>(key: K, action: () => V | Promise<V>, ttl?: MsValue | ((data: V, defaultTTL: MsValue) => MsValue)): Promise<V>;
|
|
65
64
|
/**
|
|
66
65
|
* 自增。
|
|
67
66
|
*
|
|
@@ -107,7 +106,7 @@ export declare class CacheService<TData extends Data = Data, TKey extends Key<TD
|
|
|
107
106
|
/**
|
|
108
107
|
* 派生出一个指定类型的缓存服务。
|
|
109
108
|
*/
|
|
110
|
-
fork<TNextData extends Data>(options?: Partial<
|
|
109
|
+
fork<TNextData extends Data>(options?: Partial<CacheServiceOptions>): CacheService<TNextData, Key<TNextData>, KeyPath<TNextData>, KeyPathForNumberValue<TNextData>>;
|
|
111
110
|
}
|
|
112
111
|
declare module '../x' {
|
|
113
112
|
interface X {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseService } from './base';
|
|
2
2
|
import type { MsValue } from 'vtils/date';
|
|
3
|
-
export interface
|
|
3
|
+
export interface CaptchaServiceOptions {
|
|
4
4
|
/**
|
|
5
5
|
* 验证码长度
|
|
6
6
|
*/
|
|
@@ -10,32 +10,32 @@ export interface CaptchaOptions {
|
|
|
10
10
|
*/
|
|
11
11
|
ttl: MsValue;
|
|
12
12
|
}
|
|
13
|
-
export interface
|
|
13
|
+
export interface CaptchaServiceGenerateResult {
|
|
14
14
|
token: string;
|
|
15
15
|
code: string;
|
|
16
16
|
}
|
|
17
|
-
export interface
|
|
17
|
+
export interface CaptchaServiceGenerateImageResult {
|
|
18
18
|
token: string;
|
|
19
19
|
code: string;
|
|
20
20
|
svg: string;
|
|
21
21
|
}
|
|
22
|
-
export interface
|
|
22
|
+
export interface CaptchaServiceGenerateDataUrlResult {
|
|
23
23
|
token: string;
|
|
24
24
|
code: string;
|
|
25
25
|
dataUrl: string;
|
|
26
26
|
}
|
|
27
|
-
export interface
|
|
27
|
+
export interface CaptchaServiceVerifyOptions {
|
|
28
28
|
token: string;
|
|
29
29
|
code: string;
|
|
30
30
|
}
|
|
31
31
|
export declare class CaptchaService implements BaseService {
|
|
32
32
|
private options;
|
|
33
33
|
serviceName: string;
|
|
34
|
-
constructor(options:
|
|
35
|
-
generate(): Promise<
|
|
36
|
-
generateImage(): Promise<
|
|
37
|
-
generateDataUrl(): Promise<
|
|
38
|
-
verify(options:
|
|
34
|
+
constructor(options: CaptchaServiceOptions);
|
|
35
|
+
generate(): Promise<CaptchaServiceGenerateResult>;
|
|
36
|
+
generateImage(): Promise<CaptchaServiceGenerateImageResult>;
|
|
37
|
+
generateDataUrl(): Promise<CaptchaServiceGenerateDataUrlResult>;
|
|
38
|
+
verify(options: CaptchaServiceVerifyOptions): Promise<boolean>;
|
|
39
39
|
}
|
|
40
40
|
declare module '../x' {
|
|
41
41
|
interface X {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { BaseService } from './base';
|
|
2
|
-
export interface
|
|
2
|
+
export interface DisposeServiceOptions {
|
|
3
3
|
disposeOnExit?: boolean;
|
|
4
4
|
}
|
|
5
5
|
export declare class DisposeService implements BaseService {
|
|
6
6
|
private options?;
|
|
7
7
|
serviceName: string;
|
|
8
|
-
constructor(options?:
|
|
8
|
+
constructor(options?: DisposeServiceOptions);
|
|
9
9
|
private disposes;
|
|
10
10
|
add(fn: () => any): void;
|
|
11
11
|
dispose(): Promise<any[]>;
|
package/lib/services/mail.d.ts
CHANGED
|
@@ -7,12 +7,14 @@ export interface MailServiceOptions {
|
|
|
7
7
|
user: string;
|
|
8
8
|
pass: string;
|
|
9
9
|
}
|
|
10
|
+
export interface MailServiceSendOptions extends nodemailer.SendMailOptions {
|
|
11
|
+
}
|
|
10
12
|
export declare class MailService implements BaseService {
|
|
11
13
|
private options;
|
|
12
14
|
serviceName: string;
|
|
13
15
|
private transporter;
|
|
14
16
|
constructor(options: MailServiceOptions);
|
|
15
|
-
send(
|
|
17
|
+
send(options: MailServiceSendOptions): Promise<any>;
|
|
16
18
|
}
|
|
17
19
|
declare module '../x' {
|
|
18
20
|
interface X {
|
package/lib/services/mail.js
CHANGED
|
@@ -7,7 +7,7 @@ export class MailService {
|
|
|
7
7
|
this.transporter = void 0;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
async send(
|
|
10
|
+
async send(options) {
|
|
11
11
|
if (!this.transporter) {
|
|
12
12
|
this.transporter = nodemailer.createTransport({
|
|
13
13
|
host: this.options.host,
|
|
@@ -22,7 +22,7 @@ export class MailService {
|
|
|
22
22
|
x.dispose.add(() => this.transporter.close());
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
return this.transporter.sendMail(
|
|
25
|
+
return this.transporter.sendMail(options);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
}
|
package/lib/services/pay.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseService } from './base';
|
|
2
|
-
export interface
|
|
2
|
+
export interface PayServiceOptions {
|
|
3
3
|
/** 支付宝 */
|
|
4
4
|
alipay?: {
|
|
5
5
|
/** 应用 ID */
|
|
@@ -23,7 +23,7 @@ export interface PayOptions {
|
|
|
23
23
|
secretKey: string;
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
-
export interface
|
|
26
|
+
export interface PayServicePrepareAlipayOptions {
|
|
27
27
|
/** 商品名称 */
|
|
28
28
|
goodsName: string;
|
|
29
29
|
/** 交易单号 */
|
|
@@ -35,11 +35,11 @@ export interface PayPrepareAlipayOptions {
|
|
|
35
35
|
/** 返回地址 */
|
|
36
36
|
returnUrl?: string;
|
|
37
37
|
}
|
|
38
|
-
export interface
|
|
38
|
+
export interface PayServicePrepareAlipayResult {
|
|
39
39
|
/** 支付地址,需跳转过去 */
|
|
40
40
|
payUrl: string;
|
|
41
41
|
}
|
|
42
|
-
export interface
|
|
42
|
+
export interface PayServicePrepareWepayOptions {
|
|
43
43
|
/** 商品名称 */
|
|
44
44
|
goodsName: string;
|
|
45
45
|
/** 交易单号 */
|
|
@@ -51,7 +51,7 @@ export interface PayPrepareWepayOptions {
|
|
|
51
51
|
/** 对应公众号用户的 openid */
|
|
52
52
|
openid: string;
|
|
53
53
|
}
|
|
54
|
-
export interface
|
|
54
|
+
export interface PayServicePrepareWepayResult {
|
|
55
55
|
/** 支付参数,可直接传给 JSSDK 调用 */
|
|
56
56
|
payParams: {
|
|
57
57
|
appId: string;
|
|
@@ -66,9 +66,9 @@ export declare class PayService implements BaseService {
|
|
|
66
66
|
private options;
|
|
67
67
|
serviceName: string;
|
|
68
68
|
private alipaySdk;
|
|
69
|
-
constructor(options:
|
|
70
|
-
prepareAlipay(options:
|
|
71
|
-
prepareWepay(options:
|
|
69
|
+
constructor(options: PayServiceOptions);
|
|
70
|
+
prepareAlipay(options: PayServicePrepareAlipayOptions): Promise<PayServicePrepareAlipayResult>;
|
|
71
|
+
prepareWepay(options: PayServicePrepareWepayOptions): Promise<PayServicePrepareWepayResult>;
|
|
72
72
|
verifyNotifyData(data: any): boolean;
|
|
73
73
|
verifyNotifyDataOrFail(data: any, message?: string): void;
|
|
74
74
|
private wepaySign;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { BaseService } from './base';
|
|
2
2
|
import { MsValue } from 'vtils/date';
|
|
3
|
-
export interface
|
|
3
|
+
export interface RateLimitServiceLimitByCountOptions {
|
|
4
4
|
key: string;
|
|
5
5
|
count: number;
|
|
6
6
|
ttl: MsValue;
|
|
7
7
|
}
|
|
8
8
|
export declare class RateLimitService implements BaseService {
|
|
9
9
|
serviceName: string;
|
|
10
|
-
limitByCount(options:
|
|
10
|
+
limitByCount(options: RateLimitServiceLimitByCountOptions): Promise<number>;
|
|
11
11
|
}
|
|
12
12
|
declare module '../x' {
|
|
13
13
|
interface X {
|
package/lib/services/redis.d.ts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { BaseService } from './base';
|
|
2
|
-
export interface
|
|
2
|
+
export interface SensitiveWordsServiceOptions {
|
|
3
|
+
/** 敏感词列表 */
|
|
3
4
|
words: string[];
|
|
4
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* 敏感词服务。
|
|
8
|
+
*/
|
|
5
9
|
export declare class SensitiveWordsService implements BaseService {
|
|
6
10
|
private options;
|
|
7
11
|
serviceName: string;
|
|
8
12
|
private mint;
|
|
9
|
-
constructor(options:
|
|
10
|
-
|
|
13
|
+
constructor(options: SensitiveWordsServiceOptions);
|
|
14
|
+
/**
|
|
15
|
+
* 处理文本,敏感词将被替换为 * 号。
|
|
16
|
+
*/
|
|
17
|
+
process(text: string): Promise<string>;
|
|
11
18
|
}
|
|
12
19
|
declare module '../x' {
|
|
13
20
|
interface X {
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import Mint from 'mint-filter';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 敏感词服务。
|
|
5
|
+
*/
|
|
2
6
|
export class SensitiveWordsService {
|
|
3
7
|
constructor(options) {
|
|
4
8
|
this.options = options;
|
|
5
9
|
this.serviceName = 'sensitiveWords';
|
|
6
10
|
this.mint = void 0;
|
|
7
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* 处理文本,敏感词将被替换为 * 号。
|
|
14
|
+
*/
|
|
15
|
+
|
|
8
16
|
|
|
9
|
-
async
|
|
17
|
+
async process(text) {
|
|
10
18
|
if (!this.mint) {
|
|
11
19
|
this.mint = new Mint(this.options.words);
|
|
12
20
|
}
|