@jayfong/x-server 1.33.1 → 1.33.4

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,17 @@
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.33.4](https://github.com/jfWorks/x-server/compare/v1.33.3...v1.33.4) (2022-07-17)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * remove console log ([13df7b1](https://github.com/jfWorks/x-server/commit/13df7b1728ab67df8206e79b2742f03143ff5668))
11
+
12
+ ### [1.33.3](https://github.com/jfWorks/x-server/compare/v1.33.2...v1.33.3) (2022-07-07)
13
+
14
+ ### [1.33.2](https://github.com/jfWorks/x-server/compare/v1.33.1...v1.33.2) (2022-06-28)
15
+
5
16
  ### [1.33.1](https://github.com/jfWorks/x-server/compare/v1.33.0...v1.33.1) (2022-06-12)
6
17
 
7
18
  ## [1.33.0](https://github.com/jfWorks/x-server/compare/v1.32.1...v1.33.0) (2022-06-11)
@@ -164,7 +164,12 @@ class BuildUtil {
164
164
 
165
165
  await (0, _execa.default)('tyn', {
166
166
  cwd: distDir,
167
- stdio: 'inherit'
167
+ stdio: 'inherit',
168
+ env: {
169
+ // 禁止 yarn 更新检测,因网络原因容易超时长时间卡住
170
+ // https://classic.yarnpkg.com/lang/en/docs/yarnrc/#toc-disable-self-update-check
171
+ yarn_disable_self_update_check: 'true'
172
+ }
168
173
  }); // 打包为 tgz
169
174
 
170
175
  await _compressing.default.tgz.compressDir(distDir, distBundleFile);
@@ -17,16 +17,19 @@ class CaptchaService {
17
17
  this.serviceName = 'captcha';
18
18
  }
19
19
 
20
- async generate() {
20
+ async generate(scene) {
21
21
  const code = Math.random().toString().slice(0 - this.options.size);
22
- const token = await _x.x.cache.save(code, this.options.ttl);
22
+ const token = await _x.x.cache.save({
23
+ code,
24
+ scene
25
+ }, this.options.ttl);
23
26
  return {
24
27
  token: token,
25
28
  code: code
26
29
  };
27
30
  }
28
31
 
29
- async generateImage() {
32
+ async generateImage(scene) {
30
33
  const {
31
34
  text: code,
32
35
  data: svg
@@ -34,7 +37,10 @@ class CaptchaService {
34
37
  size: this.options.size
35
38
  });
36
39
 
37
- const token = await _x.x.cache.save(code, this.options.ttl);
40
+ const token = await _x.x.cache.save({
41
+ code,
42
+ scene
43
+ }, this.options.ttl);
38
44
  return {
39
45
  token: token,
40
46
  code: code,
@@ -42,12 +48,12 @@ class CaptchaService {
42
48
  };
43
49
  }
44
50
 
45
- async generateDataUrl() {
51
+ async generateDataUrl(scene) {
46
52
  const {
47
53
  token,
48
54
  code,
49
55
  svg
50
- } = await this.generateImage();
56
+ } = await this.generateImage(scene);
51
57
  const dataUrl = (0, _miniSvgDataUri.default)(svg);
52
58
  return {
53
59
  token: token,
@@ -61,14 +67,14 @@ class CaptchaService {
61
67
  return false;
62
68
  }
63
69
 
64
- const expectedCode = await _x.x.cache.get(options.token);
70
+ const expected = await _x.x.cache.get(options.token);
65
71
 
66
- if (expectedCode == null) {
72
+ if (expected == null) {
67
73
  return false;
68
74
  }
69
75
 
70
76
  await _x.x.cache.remove(options.token);
71
- return options.code.toLowerCase() === expectedCode.toLowerCase();
77
+ return expected.scene === options.scene && options.code.toLowerCase() === expected.code.toLowerCase();
72
78
  }
73
79
 
74
80
  }
@@ -29,7 +29,6 @@ class JwtService {
29
29
  ignoreExpiration: false
30
30
  }, (err, data) => {
31
31
  if (err) {
32
- console.log(err);
33
32
  reject(new _http_error.HttpError.Unauthorized());
34
33
  } else {
35
34
  resolve(data);
@@ -138,7 +138,12 @@ export class BuildUtil {
138
138
 
139
139
  await exec('tyn', {
140
140
  cwd: distDir,
141
- stdio: 'inherit'
141
+ stdio: 'inherit',
142
+ env: {
143
+ // 禁止 yarn 更新检测,因网络原因容易超时长时间卡住
144
+ // https://classic.yarnpkg.com/lang/en/docs/yarnrc/#toc-disable-self-update-check
145
+ yarn_disable_self_update_check: 'true'
146
+ }
142
147
  }); // 打包为 tgz
143
148
 
144
149
  await compressing.tgz.compressDir(distDir, distBundleFile);
@@ -27,14 +27,15 @@ export interface CaptchaServiceGenerateDataUrlResult {
27
27
  export interface CaptchaServiceVerifyOptions {
28
28
  token: string;
29
29
  code: string;
30
+ scene: string;
30
31
  }
31
32
  export declare class CaptchaService implements BaseService {
32
33
  private options;
33
34
  serviceName: string;
34
35
  constructor(options: CaptchaServiceOptions);
35
- generate(): Promise<CaptchaServiceGenerateResult>;
36
- generateImage(): Promise<CaptchaServiceGenerateImageResult>;
37
- generateDataUrl(): Promise<CaptchaServiceGenerateDataUrlResult>;
36
+ generate(scene: string): Promise<CaptchaServiceGenerateResult>;
37
+ generateImage(scene: string): Promise<CaptchaServiceGenerateImageResult>;
38
+ generateDataUrl(scene: string): Promise<CaptchaServiceGenerateDataUrlResult>;
38
39
  verify(options: CaptchaServiceVerifyOptions): Promise<boolean>;
39
40
  }
40
41
  declare module '../x' {
@@ -7,23 +7,29 @@ export class CaptchaService {
7
7
  this.serviceName = 'captcha';
8
8
  }
9
9
 
10
- async generate() {
10
+ async generate(scene) {
11
11
  const code = Math.random().toString().slice(0 - this.options.size);
12
- const token = await x.cache.save(code, this.options.ttl);
12
+ const token = await x.cache.save({
13
+ code,
14
+ scene
15
+ }, this.options.ttl);
13
16
  return {
14
17
  token: token,
15
18
  code: code
16
19
  };
17
20
  }
18
21
 
19
- async generateImage() {
22
+ async generateImage(scene) {
20
23
  const {
21
24
  text: code,
22
25
  data: svg
23
26
  } = svgCaptcha.create({
24
27
  size: this.options.size
25
28
  });
26
- const token = await x.cache.save(code, this.options.ttl);
29
+ const token = await x.cache.save({
30
+ code,
31
+ scene
32
+ }, this.options.ttl);
27
33
  return {
28
34
  token: token,
29
35
  code: code,
@@ -31,12 +37,12 @@ export class CaptchaService {
31
37
  };
32
38
  }
33
39
 
34
- async generateDataUrl() {
40
+ async generateDataUrl(scene) {
35
41
  const {
36
42
  token,
37
43
  code,
38
44
  svg
39
- } = await this.generateImage();
45
+ } = await this.generateImage(scene);
40
46
  const dataUrl = svgToDataUrl(svg);
41
47
  return {
42
48
  token: token,
@@ -50,14 +56,14 @@ export class CaptchaService {
50
56
  return false;
51
57
  }
52
58
 
53
- const expectedCode = await x.cache.get(options.token);
59
+ const expected = await x.cache.get(options.token);
54
60
 
55
- if (expectedCode == null) {
61
+ if (expected == null) {
56
62
  return false;
57
63
  }
58
64
 
59
65
  await x.cache.remove(options.token);
60
- return options.code.toLowerCase() === expectedCode.toLowerCase();
66
+ return expected.scene === options.scene && options.code.toLowerCase() === expected.code.toLowerCase();
61
67
  }
62
68
 
63
69
  }
@@ -19,7 +19,6 @@ export class JwtService {
19
19
  ignoreExpiration: false
20
20
  }, (err, data) => {
21
21
  if (err) {
22
- console.log(err);
23
22
  reject(new HttpError.Unauthorized());
24
23
  } else {
25
24
  resolve(data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "1.33.1",
3
+ "version": "1.33.4",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",