@jayfong/x-server 1.14.0 → 1.15.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 +22 -0
- package/lib/_cjs/cli/build_util.js +4 -1
- package/lib/_cjs/cli/env_util.js +10 -1
- package/lib/_cjs/core/handler.js +10 -4
- package/lib/_cjs/services/captcha.js +1 -3
- package/lib/_cjs/x.js +3 -1
- package/lib/cli/build_util.js +4 -1
- package/lib/cli/env_util.js +10 -1
- package/lib/core/handler.d.ts +1 -0
- package/lib/core/handler.js +9 -4
- package/lib/services/captcha.js +1 -3
- package/lib/x.d.ts +2 -0
- package/lib/x.js +3 -1
- package/package.json +1 -1
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.15.1](https://github.com/jfWorks/x-server/compare/v1.15.0...v1.15.1) (2022-04-26)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* env ([4ae102e](https://github.com/jfWorks/x-server/commit/4ae102eabe2fb0f99f6367d75314d9b2db6b556e))
|
|
11
|
+
* envs ([6fe04ee](https://github.com/jfWorks/x-server/commit/6fe04eedcc2875edd5e0b7398b3fe8f7a826c3e1))
|
|
12
|
+
|
|
13
|
+
## [1.15.0](https://github.com/jfWorks/x-server/compare/v1.14.1...v1.15.0) (2022-04-26)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* x.env ([e39771f](https://github.com/jfWorks/x-server/commit/e39771f998f4b952bda528105fb18b6895e0ce81))
|
|
19
|
+
|
|
20
|
+
### [1.14.1](https://github.com/jfWorks/x-server/compare/v1.14.0...v1.14.1) (2022-04-26)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Bug Fixes
|
|
24
|
+
|
|
25
|
+
* requestDataSchema ([8b4f910](https://github.com/jfWorks/x-server/commit/8b4f910b1e9efbc082571b9ef407d7baf31b6319))
|
|
26
|
+
|
|
5
27
|
## [1.14.0](https://github.com/jfWorks/x-server/compare/v1.13.1...v1.14.0) (2022-04-26)
|
|
6
28
|
|
|
7
29
|
|
|
@@ -75,7 +75,10 @@ class BuildUtil {
|
|
|
75
75
|
sourcemap: false,
|
|
76
76
|
treeShaking: true,
|
|
77
77
|
banner: {
|
|
78
|
-
js: `${`;${(_options$inlineEnvs = options.inlineEnvs) == null ? void 0 : _options$inlineEnvs.map(env => `process.env[${JSON.stringify(env.key)}]=${JSON.stringify(env.value)}`).join(';')}` || ''}
|
|
78
|
+
js: `${`;${(_options$inlineEnvs = options.inlineEnvs) == null ? void 0 : _options$inlineEnvs.map(env => `process.env[${JSON.stringify(env.key)}]=${JSON.stringify(env.value)}`).join(';')}` || ''};process.env.X_SERVER_ENVS=${JSON.stringify((options.inlineEnvs || []).reduce((res, item) => {
|
|
79
|
+
res[item.key] = item.value;
|
|
80
|
+
return res;
|
|
81
|
+
}, {}))};`
|
|
79
82
|
},
|
|
80
83
|
plugins: [{
|
|
81
84
|
name: 'extract-assets',
|
package/lib/_cjs/cli/env_util.js
CHANGED
|
@@ -105,9 +105,18 @@ class EnvUtil {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
static async importFile(options) {
|
|
108
|
-
|
|
108
|
+
const envs = await EnvUtil.parseFile(options);
|
|
109
|
+
const envsObj = {};
|
|
110
|
+
|
|
111
|
+
for (const env of envs) {
|
|
112
|
+
envsObj[env.key] = env.value;
|
|
109
113
|
process.env[env.key] = env.value;
|
|
110
114
|
}
|
|
115
|
+
|
|
116
|
+
process.env.X_SERVER_ENVS = JSON.stringify({ // @ts-ignore
|
|
117
|
+
...JSON.parse(process.env.X_SERVER_ENVS || '{}'),
|
|
118
|
+
...envsObj
|
|
119
|
+
});
|
|
111
120
|
}
|
|
112
121
|
|
|
113
122
|
static makeTypes(envs) {
|
package/lib/_cjs/core/handler.js
CHANGED
|
@@ -9,9 +9,12 @@ var _dispose = require("../services/dispose");
|
|
|
9
9
|
|
|
10
10
|
var _http_error = require("../core/http_error");
|
|
11
11
|
|
|
12
|
+
var _validator = require("vtils/validator");
|
|
13
|
+
|
|
12
14
|
class Handler {
|
|
13
15
|
constructor(options) {
|
|
14
16
|
this.options = options;
|
|
17
|
+
this.requestDataSchema = void 0;
|
|
15
18
|
|
|
16
19
|
this.handle = async (data, ctx) => {
|
|
17
20
|
// 前置 hook
|
|
@@ -27,11 +30,10 @@ class Handler {
|
|
|
27
30
|
};
|
|
28
31
|
|
|
29
32
|
this.handleHttp = async (data, ctx) => {
|
|
30
|
-
//
|
|
31
|
-
if (this.
|
|
33
|
+
// 请求数据验证
|
|
34
|
+
if (this.requestDataSchema) {
|
|
32
35
|
try {
|
|
33
|
-
data = await this.
|
|
34
|
-
data, {
|
|
36
|
+
data = await this.requestDataSchema.validate(data, {
|
|
35
37
|
strict: true,
|
|
36
38
|
abortEarly: true,
|
|
37
39
|
stripUnknown: true
|
|
@@ -92,6 +94,10 @@ class Handler {
|
|
|
92
94
|
dispose.dispose();
|
|
93
95
|
});
|
|
94
96
|
};
|
|
97
|
+
|
|
98
|
+
if (options.requestDataSchema) {
|
|
99
|
+
this.requestDataSchema = options.requestDataSchema(_validator.yup);
|
|
100
|
+
}
|
|
95
101
|
}
|
|
96
102
|
|
|
97
103
|
static addHook(hook) {
|
|
@@ -41,9 +41,7 @@ class CaptchaService {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
async verify(options) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (((_options$code = options.code) == null ? void 0 : _options$code.length) !== this.options.size) {
|
|
44
|
+
if (options.code.length !== this.options.size) {
|
|
47
45
|
return false;
|
|
48
46
|
}
|
|
49
47
|
|
package/lib/_cjs/x.js
CHANGED
|
@@ -5,8 +5,10 @@ exports.x = void 0;
|
|
|
5
5
|
|
|
6
6
|
var _dispose = require("./services/dispose");
|
|
7
7
|
|
|
8
|
+
const env = JSON.parse(process.env.X_SERVER_ENVS || '{}');
|
|
8
9
|
const x = {
|
|
9
|
-
appId:
|
|
10
|
+
appId: env.APP_ID,
|
|
11
|
+
env: env,
|
|
10
12
|
register: (...services) => {
|
|
11
13
|
for (const service of services) {
|
|
12
14
|
// @ts-ignore
|
package/lib/cli/build_util.js
CHANGED
|
@@ -51,7 +51,10 @@ export class BuildUtil {
|
|
|
51
51
|
sourcemap: false,
|
|
52
52
|
treeShaking: true,
|
|
53
53
|
banner: {
|
|
54
|
-
js: `${`;${(_options$inlineEnvs = options.inlineEnvs) == null ? void 0 : _options$inlineEnvs.map(env => `process.env[${JSON.stringify(env.key)}]=${JSON.stringify(env.value)}`).join(';')}` || ''}
|
|
54
|
+
js: `${`;${(_options$inlineEnvs = options.inlineEnvs) == null ? void 0 : _options$inlineEnvs.map(env => `process.env[${JSON.stringify(env.key)}]=${JSON.stringify(env.value)}`).join(';')}` || ''};process.env.X_SERVER_ENVS=${JSON.stringify((options.inlineEnvs || []).reduce((res, item) => {
|
|
55
|
+
res[item.key] = item.value;
|
|
56
|
+
return res;
|
|
57
|
+
}, {}))};`
|
|
55
58
|
},
|
|
56
59
|
plugins: [{
|
|
57
60
|
name: 'extract-assets',
|
package/lib/cli/env_util.js
CHANGED
|
@@ -95,9 +95,18 @@ export class EnvUtil {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
static async importFile(options) {
|
|
98
|
-
|
|
98
|
+
const envs = await EnvUtil.parseFile(options);
|
|
99
|
+
const envsObj = {};
|
|
100
|
+
|
|
101
|
+
for (const env of envs) {
|
|
102
|
+
envsObj[env.key] = env.value;
|
|
99
103
|
process.env[env.key] = env.value;
|
|
100
104
|
}
|
|
105
|
+
|
|
106
|
+
process.env.X_SERVER_ENVS = JSON.stringify({ // @ts-ignore
|
|
107
|
+
...JSON.parse(process.env.X_SERVER_ENVS || '{}'),
|
|
108
|
+
...envsObj
|
|
109
|
+
});
|
|
101
110
|
}
|
|
102
111
|
|
|
103
112
|
static makeTypes(envs) {
|
package/lib/core/handler.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { XHandler } from './types';
|
|
2
2
|
export declare class Handler<TReqData extends any = void, TResData extends any = void, TReqMethod extends XHandler.Method = XHandler.Method> {
|
|
3
3
|
readonly options: XHandler.Options<TReqData, TResData, TReqMethod>;
|
|
4
|
+
private requestDataSchema;
|
|
4
5
|
constructor(options: XHandler.Options<TReqData, TResData, TReqMethod>);
|
|
5
6
|
handle: XHandler.Handle<TReqData, TResData, TReqMethod>;
|
|
6
7
|
private handleHttp;
|
package/lib/core/handler.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { DataPacker } from 'vtils';
|
|
2
2
|
import { DisposeService } from "../services/dispose";
|
|
3
3
|
import { HttpError } from "../core/http_error";
|
|
4
|
+
import { yup } from 'vtils/validator';
|
|
4
5
|
export class Handler {
|
|
5
6
|
constructor(options) {
|
|
6
7
|
this.options = options;
|
|
8
|
+
this.requestDataSchema = void 0;
|
|
7
9
|
|
|
8
10
|
this.handle = async (data, ctx) => {
|
|
9
11
|
// 前置 hook
|
|
@@ -19,11 +21,10 @@ export class Handler {
|
|
|
19
21
|
};
|
|
20
22
|
|
|
21
23
|
this.handleHttp = async (data, ctx) => {
|
|
22
|
-
//
|
|
23
|
-
if (this.
|
|
24
|
+
// 请求数据验证
|
|
25
|
+
if (this.requestDataSchema) {
|
|
24
26
|
try {
|
|
25
|
-
data = await this.
|
|
26
|
-
data, {
|
|
27
|
+
data = await this.requestDataSchema.validate(data, {
|
|
27
28
|
strict: true,
|
|
28
29
|
abortEarly: true,
|
|
29
30
|
stripUnknown: true
|
|
@@ -84,6 +85,10 @@ export class Handler {
|
|
|
84
85
|
dispose.dispose();
|
|
85
86
|
});
|
|
86
87
|
};
|
|
88
|
+
|
|
89
|
+
if (options.requestDataSchema) {
|
|
90
|
+
this.requestDataSchema = options.requestDataSchema(yup);
|
|
91
|
+
}
|
|
87
92
|
}
|
|
88
93
|
|
|
89
94
|
static addHook(hook) {
|
package/lib/services/captcha.js
CHANGED
|
@@ -31,9 +31,7 @@ export class CaptchaService {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
async verify(options) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (((_options$code = options.code) == null ? void 0 : _options$code.length) !== this.options.size) {
|
|
34
|
+
if (options.code.length !== this.options.size) {
|
|
37
35
|
return false;
|
|
38
36
|
}
|
|
39
37
|
|
package/lib/x.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { BaseService } from './services/base';
|
|
2
3
|
import './services/dispose';
|
|
3
4
|
export interface X {
|
|
4
5
|
readonly appId: string;
|
|
6
|
+
readonly env: NodeJS.ProcessEnv;
|
|
5
7
|
readonly register: (...services: BaseService[]) => void;
|
|
6
8
|
}
|
|
7
9
|
export declare const x: X;
|
package/lib/x.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { DisposeService } from "./services/dispose";
|
|
2
|
+
const env = JSON.parse(process.env.X_SERVER_ENVS || '{}');
|
|
2
3
|
export const x = {
|
|
3
|
-
appId:
|
|
4
|
+
appId: env.APP_ID,
|
|
5
|
+
env: env,
|
|
4
6
|
register: (...services) => {
|
|
5
7
|
for (const service of services) {
|
|
6
8
|
// @ts-ignore
|