@jayfong/x-server 1.29.0 → 1.30.2

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.30.2](https://github.com/jfWorks/x-server/compare/v1.30.1...v1.30.2) (2022-05-26)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * use lz-string ([bf0e9af](https://github.com/jfWorks/x-server/commit/bf0e9af411c86ebd2b6527fc75be1476559c25fa))
11
+
12
+ ### [1.30.1](https://github.com/jfWorks/x-server/compare/v1.30.0...v1.30.1) (2022-05-26)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * deflate <-> inflate ([e7c5f63](https://github.com/jfWorks/x-server/commit/e7c5f631a6a5165bbecf20b5b5923bbef4b6db1e))
18
+
19
+ ## [1.30.0](https://github.com/jfWorks/x-server/compare/v1.29.0...v1.30.0) (2022-05-26)
20
+
21
+
22
+ ### Features
23
+
24
+ * add responseDataObfuscate ([2f1a70d](https://github.com/jfWorks/x-server/commit/2f1a70dae70c4359fbb6430ce5391f9d80ec0d17))
25
+ * client_helper ([00146d1](https://github.com/jfWorks/x-server/commit/00146d133167ba8f535bff2acef4ef33412678ba))
26
+
5
27
  ## [1.29.0](https://github.com/jfWorks/x-server/compare/v1.28.2...v1.29.0) (2022-05-19)
6
28
 
7
29
 
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ exports.__esModule = true;
6
+ exports.processXServerResponse = processXServerResponse;
7
+
8
+ var _lzString = _interopRequireDefault(require("lz-string"));
9
+
10
+ var _vtils = require("vtils");
11
+
12
+ // _#
13
+ const obfuscateKey = [90, 30].map(v => String.fromCharCode(v + 5)).join('');
14
+
15
+ function processXServerResponse(data) {
16
+ // 处理混淆
17
+ if (data && typeof data === 'object' && data[obfuscateKey] != null) {
18
+ try {
19
+ data = JSON.parse(_lzString.default.decompress(data[obfuscateKey]));
20
+ } catch {}
21
+ } // 处理数组打包
22
+
23
+
24
+ data = _vtils.DataPacker.unpackIfNeeded(data);
25
+ return data;
26
+ }
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
3
5
  exports.__esModule = true;
4
6
  exports.Handler = void 0;
5
7
 
8
+ var _lzString = _interopRequireDefault(require("lz-string"));
9
+
6
10
  var _vtils = require("vtils");
7
11
 
8
12
  var _dispose = require("../services/dispose");
@@ -52,6 +56,13 @@ class Handler {
52
56
 
53
57
  if (this.options.responseDataPack) {
54
58
  res = _vtils.DataPacker.packAsRawType(res);
59
+ } // 混淆返回数据
60
+
61
+
62
+ if (this.options.responseDataObfuscate) {
63
+ res = {
64
+ '_#': _lzString.default.compress(JSON.stringify(res))
65
+ };
55
66
  }
56
67
 
57
68
  return res == null ? {} : res;
@@ -0,0 +1 @@
1
+ export declare function processXServerResponse<T>(data: any): T;
@@ -0,0 +1,16 @@
1
+ import LZString from 'lz-string';
2
+ import { DataPacker } from 'vtils'; // _#
3
+
4
+ const obfuscateKey = [90, 30].map(v => String.fromCharCode(v + 5)).join('');
5
+ export function processXServerResponse(data) {
6
+ // 处理混淆
7
+ if (data && typeof data === 'object' && data[obfuscateKey] != null) {
8
+ try {
9
+ data = JSON.parse(LZString.decompress(data[obfuscateKey]));
10
+ } catch {}
11
+ } // 处理数组打包
12
+
13
+
14
+ data = DataPacker.unpackIfNeeded(data);
15
+ return data;
16
+ }
@@ -1,3 +1,4 @@
1
+ import LZString from 'lz-string';
1
2
  import { DataPacker } from 'vtils';
2
3
  import { DisposeService } from "../services/dispose";
3
4
  import { HttpError } from "../core/http_error";
@@ -43,6 +44,13 @@ export class Handler {
43
44
 
44
45
  if (this.options.responseDataPack) {
45
46
  res = DataPacker.packAsRawType(res);
47
+ } // 混淆返回数据
48
+
49
+
50
+ if (this.options.responseDataObfuscate) {
51
+ res = {
52
+ '_#': LZString.compress(JSON.stringify(res))
53
+ };
46
54
  }
47
55
 
48
56
  return res == null ? {} : res;
@@ -111,6 +111,12 @@ export declare namespace XHandler {
111
111
  * @default false
112
112
  */
113
113
  responseDataPack?: boolean;
114
+ /**
115
+ * 是否混淆返回数据
116
+ *
117
+ * @default false
118
+ */
119
+ responseDataObfuscate?: boolean;
114
120
  /**
115
121
  * 响应的 Content-Type 头
116
122
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "1.29.0",
3
+ "version": "1.30.2",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",
@@ -16,7 +16,7 @@
16
16
  "bootstrap": "tyn --frozen-lockfile",
17
17
  "build": "haoma compile",
18
18
  "dev": "rm -rf lib && tsc -w -p ./tsconfig.build.json",
19
- "release": "tyn test && standard-version -a && tyn build && npm publish && git push --follow-tags origin master",
19
+ "release": "tyn test && standard-version -a && tyn build && npm publish && haoma run ./scripts/publish_client_helper_package.ts && git push --follow-tags origin master",
20
20
  "test": "tsc --noEmit && jest",
21
21
  "updeps": "tnpx npm-check-updates --target minor --upgrade"
22
22
  },
@@ -56,6 +56,7 @@
56
56
  "http-errors": "^1.8.1",
57
57
  "ioredis": "^4.28.5",
58
58
  "jsonwebtoken": "^8.5.1",
59
+ "lz-string": "^1.4.4",
59
60
  "mini-svg-data-uri": "^1.4.4",
60
61
  "mint-filter": "^3.0.1",
61
62
  "node-ssh": "^12.0.4",
@@ -76,6 +77,7 @@
76
77
  "@types/fs-extra": "^9.0.13",
77
78
  "@types/ioredis": "^4.28.10",
78
79
  "@types/json-schema": "^7.0.11",
80
+ "@types/lz-string": "^1.3.34",
79
81
  "eslint": "^7.32.0",
80
82
  "haoma": "^3.6.4",
81
83
  "husky": "^4.3.8",