@lingxiteam/assets 1.0.11 → 1.0.12
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/es/dealDsl/preprocess/common.js +27 -16
- package/es/error/errorDisplay/Web/Drawer/Drawer.less +31 -0
- package/es/error/errorDisplay/Web/Drawer/index.js +12 -4
- package/es/error/errorDisplay/Web/ErrorMsg/index.js +27 -4
- package/es/error/errorDisplay/Web/Notification/index.js +22 -11
- package/es/rootConfig/mobile/BusiComp.js +1 -1
- package/es/rootConfig/mobile/MobileModal.js +1 -1
- package/es/rootConfig/mobile/MobilePopover.js +1 -1
- package/es/rootConfig/pc/BusiComp.js +1 -1
- package/es/rootConfig/pc/Drawer.js +1 -1
- package/es/rootConfig/pc/Modal.js +1 -1
- package/es/rootConfig/pc/Popover.js +1 -1
- package/es/rootConfig/todoActionList.js +1 -1
- package/es/rootConfig/todoOptionList.js +1 -1
- package/es/theme/bin/cucc/theme.js +275 -0
- package/es/theme/bin/cucc/theme.less +272 -0
- package/es/theme/bin/cucc/theme.scss +272 -0
- package/es/theme/bin/default/theme.js +275 -0
- package/es/theme/bin/default/theme.less +272 -0
- package/es/theme/bin/default/theme.scss +272 -0
- package/es/theme/build.js +42 -0
- package/es/theme/src/cucc/index.js +131 -0
- package/es/theme/src/default/index.js +131 -0
- package/es/theme/utils/colorPaletteMixin.js +59 -0
- package/es/theme/utils/px2Num.js +12 -0
- package/es/theme/utils/renderColors.js +16 -0
- package/lib/IconSvg/index.d.ts +6 -0
- package/lib/IconSvg/index.js +30 -0
- package/lib/dealDsl/PropType.d.ts +7 -0
- package/lib/dealDsl/PropType.js +5 -0
- package/lib/dealDsl/events/actionObj.d.ts +3 -0
- package/lib/dealDsl/events/actionObj.js +13 -0
- package/lib/dealDsl/events/index.d.ts +6 -0
- package/lib/dealDsl/events/index.js +21 -0
- package/lib/dealDsl/index.d.ts +2 -0
- package/lib/dealDsl/index.js +31 -0
- package/lib/dealDsl/preprocess/common.d.ts +9 -0
- package/lib/dealDsl/preprocess/common.js +277 -0
- package/lib/dealDsl/preprocess/editor.d.ts +9 -0
- package/lib/dealDsl/preprocess/editor.js +28 -0
- package/lib/dealDsl/preprocess/engine.d.ts +9 -0
- package/lib/dealDsl/preprocess/engine.js +26 -0
- package/lib/dealDsl/preprocessDSL.d.ts +21 -0
- package/lib/dealDsl/preprocessDSL.js +88 -0
- package/lib/dealDsl/utils/index.d.ts +13 -0
- package/lib/dealDsl/utils/index.js +29 -0
- package/lib/error/errorCatch/index.js +48 -0
- package/lib/error/errorDisplay/Mobile/Drawer/Drawer.js +115 -0
- package/lib/error/errorDisplay/Mobile/Drawer/Drawer.less +201 -0
- package/lib/error/errorDisplay/Mobile/Drawer/index.js +140 -0
- package/lib/error/errorDisplay/Mobile/ErrorMsg/index.js +207 -0
- package/lib/error/errorDisplay/Mobile/Modal/Modal.js +53 -0
- package/lib/error/errorDisplay/Mobile/Modal/Modal.less +146 -0
- package/lib/error/errorDisplay/Mobile/Modal/index.js +127 -0
- package/lib/error/errorDisplay/Mobile/defaultGlobalConfig.js +21 -0
- package/lib/error/errorDisplay/SVGstring.js +18 -0
- package/lib/error/errorDisplay/Web/Drawer/Drawer.js +274 -0
- package/lib/error/errorDisplay/Web/Drawer/Drawer.less +420 -0
- package/lib/error/errorDisplay/Web/Drawer/DrawerConnect.js +213 -0
- package/lib/error/errorDisplay/Web/Drawer/index.js +142 -0
- package/lib/error/errorDisplay/Web/ErrorMsg/index.js +301 -0
- package/lib/error/errorDisplay/Web/Notification/Notice.js +161 -0
- package/lib/error/errorDisplay/Web/Notification/Notification.js +149 -0
- package/lib/error/errorDisplay/Web/Notification/Notification.less +137 -0
- package/lib/error/errorDisplay/Web/Notification/index.js +104 -0
- package/lib/error/errorDisplay/Web/defaultGlobalConfig.js +29 -0
- package/lib/error/errorDisplay/animation.less +112 -0
- package/lib/error/errorDisplay/compUtils.js +52 -0
- package/lib/error/errorDisplay/const.js +83 -0
- package/lib/error/errorDisplay/http.js +103 -0
- package/lib/error/errorDisplay/variables.less +1 -0
- package/lib/error/index.js +34 -0
- package/lib/images/ico-back.png +0 -0
- package/lib/index.d.ts +9 -0
- package/lib/rootConfig/index.d.ts +5 -0
- package/lib/rootConfig/index.js +28 -0
- package/lib/rootConfig/mobile/BusiComp.d.ts +66 -0
- package/lib/rootConfig/mobile/BusiComp.js +88 -0
- package/lib/rootConfig/mobile/MobileModal.d.ts +114 -0
- package/lib/rootConfig/mobile/MobileModal.js +140 -0
- package/lib/rootConfig/mobile/MobilePopover.d.ts +81 -0
- package/lib/rootConfig/mobile/MobilePopover.js +89 -0
- package/lib/rootConfig/mobile/index.d.ts +4 -0
- package/lib/rootConfig/mobile/index.js +34 -0
- package/lib/rootConfig/mobile/page.d.ts +157 -0
- package/lib/rootConfig/mobile/page.js +161 -0
- package/lib/rootConfig/pc/BusiComp.d.ts +66 -0
- package/lib/rootConfig/pc/BusiComp.js +88 -0
- package/lib/rootConfig/pc/Drawer.d.ts +150 -0
- package/lib/rootConfig/pc/Drawer.js +203 -0
- package/lib/rootConfig/pc/Modal.d.ts +160 -0
- package/lib/rootConfig/pc/Modal.js +195 -0
- package/lib/rootConfig/pc/Popover.d.ts +90 -0
- package/lib/rootConfig/pc/Popover.js +104 -0
- package/lib/rootConfig/pc/index.d.ts +5 -0
- package/lib/rootConfig/pc/index.js +41 -0
- package/lib/rootConfig/pc/page.d.ts +146 -0
- package/lib/rootConfig/pc/page.js +153 -0
- package/lib/rootConfig/todoActionList.d.ts +3082 -0
- package/lib/rootConfig/todoActionList.js +3600 -0
- package/lib/rootConfig/todoOptionList.d.ts +1466 -0
- package/lib/rootConfig/todoOptionList.js +1685 -0
- package/lib/security/const.d.ts +22 -0
- package/lib/security/const.js +38 -0
- package/lib/security/encipher/aes.d.ts +2 -0
- package/lib/security/encipher/aes.js +35 -0
- package/lib/security/encipher/des.d.ts +2 -0
- package/lib/security/encipher/des.js +34 -0
- package/lib/security/encipher/rsa.d.ts +2 -0
- package/lib/security/encipher/rsa.js +26 -0
- package/lib/security/encipher/sign.d.ts +6 -0
- package/lib/security/encipher/sign.js +102 -0
- package/lib/security/fetch.d.ts +9 -0
- package/lib/security/fetch.js +212 -0
- package/lib/security/httpEncryption.js +83 -0
- package/lib/security/index.d.ts +39 -0
- package/lib/security/index.js +29 -0
- package/lib/svg/check.svg +10 -0
- package/lib/svg/normal-check.svg +10 -0
- package/lib/svg/webViewError.svg +40 -0
- package/lib/theme/bin/cucc/theme.js +277 -0
- package/lib/theme/bin/cucc/theme.less +272 -0
- package/lib/theme/bin/cucc/theme.scss +272 -0
- package/lib/theme/bin/default/theme.js +277 -0
- package/lib/theme/bin/default/theme.less +272 -0
- package/lib/theme/bin/default/theme.scss +272 -0
- package/lib/theme/build.js +44 -0
- package/lib/theme/src/cucc/index.js +133 -0
- package/lib/theme/src/default/index.js +133 -0
- package/lib/theme/utils/colorPaletteMixin.js +61 -0
- package/lib/theme/utils/px2Num.js +14 -0
- package/lib/theme/utils/renderColors.js +18 -0
- package/lib/utils/img.d.ts +1 -0
- package/lib/utils/img.js +10 -0
- package/lib/utils/url.d.ts +16 -0
- package/lib/utils/url.js +111 -0
- package/package.json +6 -3
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const securityHeaderKey = "XA-TYPE";
|
|
2
|
+
export declare const defaultSignKey = "X-SIGN";
|
|
3
|
+
export declare const MODE: {
|
|
4
|
+
SIGN_KEY: string;
|
|
5
|
+
SIGN: string;
|
|
6
|
+
RSA: string;
|
|
7
|
+
AES: string;
|
|
8
|
+
DES: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const signKey: string;
|
|
11
|
+
export declare const rsaPublicKey: string | undefined;
|
|
12
|
+
export declare const rsaPrivKey: string | undefined;
|
|
13
|
+
export declare const aesKey: string;
|
|
14
|
+
export declare const desKey: string;
|
|
15
|
+
declare const _default: {
|
|
16
|
+
signKey: string;
|
|
17
|
+
rsaPublicKey: string | undefined;
|
|
18
|
+
rsaPrivKey: string | undefined;
|
|
19
|
+
aesKey: string;
|
|
20
|
+
desKey: string;
|
|
21
|
+
};
|
|
22
|
+
export default _default;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.signKey = exports.securityHeaderKey = exports.rsaPublicKey = exports.rsaPrivKey = exports.desKey = exports.defaultSignKey = exports.default = exports.aesKey = exports.MODE = void 0;
|
|
7
|
+
var defaultAESKey = 'd86d7bab3d6ac01a';
|
|
8
|
+
var defaultDESKey = '91THRABY';
|
|
9
|
+
var securityHeaderKey = 'XA-TYPE';
|
|
10
|
+
exports.securityHeaderKey = securityHeaderKey;
|
|
11
|
+
var defaultSignKey = 'X-SIGN';
|
|
12
|
+
exports.defaultSignKey = defaultSignKey;
|
|
13
|
+
var MODE = {
|
|
14
|
+
SIGN_KEY: 'signKey',
|
|
15
|
+
SIGN: '1.0',
|
|
16
|
+
RSA: '2.0',
|
|
17
|
+
AES: '3.0',
|
|
18
|
+
DES: '4.0'
|
|
19
|
+
};
|
|
20
|
+
exports.MODE = MODE;
|
|
21
|
+
var signKey = process.env.LINGXI_HTTP_SIGN_HEADER_KEY || process.env.REACT_APP_HTTP_SIGN_HEADER_KEY || process.env.UMI_APP_HTTP_SIGN_HEADER_KEY || process.env.FISHX_APP_HTTP_SIGN_HEADER_KEY || defaultSignKey;
|
|
22
|
+
exports.signKey = signKey;
|
|
23
|
+
var rsaPublicKey = process.env.LINGXI_HTTP_RSA_PUBLIC_KEY || process.env.REACT_APP_HTTP_RSA_PUBLIC_KEY || process.env.UMI_APP_HTTP_RSA_PUBLIC_KEY || process.env.FISHX_APP_HTTP_RSA_PUBLIC_KEY;
|
|
24
|
+
exports.rsaPublicKey = rsaPublicKey;
|
|
25
|
+
var rsaPrivKey = process.env.LINGXI_HTTP_RSA_PRIV_KEY || process.env.REACT_APP_HTTP_RSA_PRIV_KEY || process.env.UMI_APP_HTTP_RSA_PRIV_KEY || process.env.FISHX_APP_HTTP_RSA_PRIV_KEY;
|
|
26
|
+
exports.rsaPrivKey = rsaPrivKey;
|
|
27
|
+
var aesKey = process.env.LINGXI_HTTP_AES_KEY || process.env.REACT_APP_HTTP_AES_KEY || process.env.UMI_APP_HTTP_AES_KEY || process.env.FISHX_APP_HTTP_AES_KEY || defaultAESKey;
|
|
28
|
+
exports.aesKey = aesKey;
|
|
29
|
+
var desKey = process.env.LINGXI_HTTP_DES_KEY || process.env.REACT_APP_HTTP_DES_KEY || process.env.UMI_APP_HTTP_DES_KEY || process.env.FISHX_APP_HTTP_DES_KEY || defaultDESKey;
|
|
30
|
+
exports.desKey = desKey;
|
|
31
|
+
var _default = {
|
|
32
|
+
signKey: signKey,
|
|
33
|
+
rsaPublicKey: rsaPublicKey,
|
|
34
|
+
rsaPrivKey: rsaPrivKey,
|
|
35
|
+
aesKey: aesKey,
|
|
36
|
+
desKey: desKey
|
|
37
|
+
};
|
|
38
|
+
exports.default = _default;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.AESEncrypt = exports.AESDecrypt = void 0;
|
|
7
|
+
var _cryptoJs = _interopRequireDefault(require("crypto-js"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
var AESEncrypt = function AESEncrypt(value, aesKey, handle) {
|
|
10
|
+
if (typeof handle === 'function') {
|
|
11
|
+
return handle(value, aesKey, _cryptoJs.default);
|
|
12
|
+
}
|
|
13
|
+
var key = _cryptoJs.default.enc.Utf8.parse(aesKey);
|
|
14
|
+
var ciphertext = _cryptoJs.default.enc.Utf8.parse(value);
|
|
15
|
+
var encrypted = _cryptoJs.default.AES.encrypt(ciphertext, key, {
|
|
16
|
+
mode: _cryptoJs.default.mode.ECB,
|
|
17
|
+
padding: _cryptoJs.default.pad.Pkcs7
|
|
18
|
+
});
|
|
19
|
+
return encrypted.toString();
|
|
20
|
+
};
|
|
21
|
+
exports.AESEncrypt = AESEncrypt;
|
|
22
|
+
var AESDecrypt = function AESDecrypt(value, aesKey, handle) {
|
|
23
|
+
if (typeof handle === 'function') {
|
|
24
|
+
return handle(value, aesKey, _cryptoJs.default);
|
|
25
|
+
}
|
|
26
|
+
var key = _cryptoJs.default.enc.Utf8.parse(aesKey);
|
|
27
|
+
var ciphertext = _cryptoJs.default.enc.Base64.stringify(_cryptoJs.default.enc.Base64.parse(value));
|
|
28
|
+
// const ciphertext = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Base64.parse(CryptoJS.enc.Utf8.parse(value).toString(CryptoJS.enc.Utf8)));
|
|
29
|
+
var encrypted = _cryptoJs.default.AES.decrypt(ciphertext, key, {
|
|
30
|
+
mode: _cryptoJs.default.mode.ECB,
|
|
31
|
+
padding: _cryptoJs.default.pad.Pkcs7
|
|
32
|
+
});
|
|
33
|
+
return encrypted.toString(_cryptoJs.default.enc.Utf8);
|
|
34
|
+
};
|
|
35
|
+
exports.AESDecrypt = AESDecrypt;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DESEncrypt = exports.DESDecrypt = void 0;
|
|
7
|
+
var _cryptoJs = _interopRequireDefault(require("crypto-js"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
var DESEncrypt = function DESEncrypt(value, aesKey, handle) {
|
|
10
|
+
if (typeof handle === 'function') {
|
|
11
|
+
return handle(value, aesKey, _cryptoJs.default);
|
|
12
|
+
}
|
|
13
|
+
var key = _cryptoJs.default.enc.Utf8.parse(aesKey);
|
|
14
|
+
var ciphertext = _cryptoJs.default.enc.Utf8.parse(value);
|
|
15
|
+
var encrypted = _cryptoJs.default.DES.encrypt(ciphertext, key, {
|
|
16
|
+
mode: _cryptoJs.default.mode.ECB,
|
|
17
|
+
padding: _cryptoJs.default.pad.Pkcs7
|
|
18
|
+
});
|
|
19
|
+
return encrypted.toString();
|
|
20
|
+
};
|
|
21
|
+
exports.DESEncrypt = DESEncrypt;
|
|
22
|
+
var DESDecrypt = function DESDecrypt(value, aesKey, handle) {
|
|
23
|
+
if (typeof handle === 'function') {
|
|
24
|
+
return handle(value, aesKey, _cryptoJs.default);
|
|
25
|
+
}
|
|
26
|
+
var key = _cryptoJs.default.enc.Utf8.parse(aesKey);
|
|
27
|
+
var ciphertext = _cryptoJs.default.enc.Base64.stringify(_cryptoJs.default.enc.Base64.parse(value));
|
|
28
|
+
var encrypted = _cryptoJs.default.DES.decrypt(ciphertext, key, {
|
|
29
|
+
mode: _cryptoJs.default.mode.ECB,
|
|
30
|
+
padding: _cryptoJs.default.pad.Pkcs7
|
|
31
|
+
});
|
|
32
|
+
return encrypted.toString(_cryptoJs.default.enc.Utf8);
|
|
33
|
+
};
|
|
34
|
+
exports.DESDecrypt = DESDecrypt;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.RSAEncrypt = exports.RSADecrypt = void 0;
|
|
7
|
+
var _jsencrypt = _interopRequireDefault(require("jsencrypt"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
var RSAEncrypt = function RSAEncrypt(value, publicKey, handle) {
|
|
10
|
+
if (typeof handle === 'function') {
|
|
11
|
+
return handle(value, publicKey, _jsencrypt.default);
|
|
12
|
+
}
|
|
13
|
+
var encryptor = new _jsencrypt.default();
|
|
14
|
+
encryptor.setPublicKey(publicKey);
|
|
15
|
+
return encryptor.encrypt(value);
|
|
16
|
+
};
|
|
17
|
+
exports.RSAEncrypt = RSAEncrypt;
|
|
18
|
+
var RSADecrypt = function RSADecrypt(value, privKey, handle) {
|
|
19
|
+
if (typeof handle === 'function') {
|
|
20
|
+
return handle(value, privKey, _jsencrypt.default);
|
|
21
|
+
}
|
|
22
|
+
var decrypt = new _jsencrypt.default();
|
|
23
|
+
decrypt.setPrivateKey(privKey);
|
|
24
|
+
return decrypt.decrypt(value);
|
|
25
|
+
};
|
|
26
|
+
exports.RSADecrypt = RSADecrypt;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.createHttpSignStr = void 0;
|
|
7
|
+
var _cryptoJs = require("crypto-js");
|
|
8
|
+
var _url = require("../../utils/url");
|
|
9
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
10
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
11
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
12
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
13
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
14
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) { ; } } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
15
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
16
|
+
var SIGN_KEY = process.env.LING_XI_HTTP_SIGN_KEY || 'zrT5bi2escXilaH1fs653uZiH9RWfzCS';
|
|
17
|
+
// 注意:修改此文件请跑测试用例, npm run test
|
|
18
|
+
// 1、签名算法:
|
|
19
|
+
// 通过对url、参数、秘钥拼接成字符串,然后对字符串使用算法SHA-256得到64个字符串,放到header, X-SIGN=XXXXXXX。
|
|
20
|
+
// 2、签名字符串拼接规则:
|
|
21
|
+
// a.get 请求:url+"#"+header+"#"+参数+"#"+秘钥
|
|
22
|
+
// b.post 请求:url+"#"+header+"#"+body+"#"秘钥
|
|
23
|
+
// 参数说明:
|
|
24
|
+
// ● 如果其中的变量为空,则为空字符串。
|
|
25
|
+
// ● url :不包含参数,(2022.08.08 更改为apiName)
|
|
26
|
+
// ● header :取X-开头的header,或者APP-ID,多个则逗号分隔拼接。比如X-AA=a;APP-ID=88888
|
|
27
|
+
// ● get 参数:就是url 问号后面的串
|
|
28
|
+
// ● body:post 请求体
|
|
29
|
+
/**
|
|
30
|
+
* 组装X-SIGN请求头
|
|
31
|
+
* @param {请求地址} url 接口请求地址
|
|
32
|
+
* @param {请求参数} options
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
// 由于X-B 的规则可能被业务网关使用,并往请求头增加内容,导致前后端加密不一致
|
|
36
|
+
// 2022.08.09 使用以下3个固定值 + X-LX-*匹配 方式
|
|
37
|
+
var hKeys = ['X-B-AUTH', 'X-B-TARGET-ID', 'APP-ID'];
|
|
38
|
+
// 配置指定接口前缀,2023-03-16规则调整,不需要使用
|
|
39
|
+
// const apiPrefix =
|
|
40
|
+
// process.env.LING_XI_HTTP_SIGN_API_PERFIX ||
|
|
41
|
+
// process.env.REACT_APP_HTTP_SIGN_API_PERFIX ||
|
|
42
|
+
// process.env.UMI_APP_HTTP_SIGN_API_PERFIX ||
|
|
43
|
+
// process.env.FISHX_APP_HTTP_SIGN_API_PERFIX ||
|
|
44
|
+
// 'portal,asset,rhin,lcdp,ncdp,flow,app';
|
|
45
|
+
// 获取接口路径,2023-03-16调整,只取最后一级
|
|
46
|
+
var getApiPath = function getApiPath(url) {
|
|
47
|
+
return url.split('/').pop();
|
|
48
|
+
};
|
|
49
|
+
var createHttpSignStr = function createHttpSignStr(url, options) {
|
|
50
|
+
if (!url || !options || !options.method) {
|
|
51
|
+
return '';
|
|
52
|
+
}
|
|
53
|
+
var method = options.method,
|
|
54
|
+
headers = options.headers,
|
|
55
|
+
body = options.body,
|
|
56
|
+
search = options.search;
|
|
57
|
+
// 获取参数1: 接口名称
|
|
58
|
+
var mixUrl = url;
|
|
59
|
+
if (search && search instanceof Object) {
|
|
60
|
+
mixUrl += (url.indexOf('?') !== -1 ? '&' : '?') + (0, _url.obj2QueryString)(search);
|
|
61
|
+
}
|
|
62
|
+
var _mixUrl$split = mixUrl.split('?'),
|
|
63
|
+
_mixUrl$split2 = _slicedToArray(_mixUrl$split, 2),
|
|
64
|
+
urlPath = _mixUrl$split2[0],
|
|
65
|
+
_mixUrl$split2$ = _mixUrl$split2[1],
|
|
66
|
+
urlSearch = _mixUrl$split2$ === void 0 ? '' : _mixUrl$split2$;
|
|
67
|
+
var apiPath = getApiPath(urlPath);
|
|
68
|
+
// 获取参数2: 请求头部参数
|
|
69
|
+
var headerParams = '';
|
|
70
|
+
var headersKeyArr = [];
|
|
71
|
+
if (headers) {
|
|
72
|
+
Object.keys(headers).forEach(function (key) {
|
|
73
|
+
if (key.startsWith('X-LX-') || hKeys.includes(key)) {
|
|
74
|
+
headersKeyArr.push("".concat(key.toLowerCase(), "=").concat(headers[key]));
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
headerParams = headersKeyArr.sort().join(';');
|
|
79
|
+
// 获取参数3: 请求参数
|
|
80
|
+
var params = '';
|
|
81
|
+
if (method.toLowerCase() === 'get') {
|
|
82
|
+
params = urlSearch;
|
|
83
|
+
} else {
|
|
84
|
+
params = _typeof(body) === 'object' ? JSON.stringify(body) : body;
|
|
85
|
+
}
|
|
86
|
+
// 组装加密字符串
|
|
87
|
+
var str = [apiPath, headerParams, params, SIGN_KEY].join('#');
|
|
88
|
+
if (typeof window !== 'undefined' && (window.lxDebug || window.localStorage.getItem('lxDebug'))) {
|
|
89
|
+
console.log(' --- signDebug ---');
|
|
90
|
+
console.log('url', url);
|
|
91
|
+
console.log('str', str);
|
|
92
|
+
console.log('sign', (0, _cryptoJs.SHA256)(str).toString());
|
|
93
|
+
}
|
|
94
|
+
// 生成约定签名
|
|
95
|
+
return (0, _cryptoJs.SHA256)(str).toString();
|
|
96
|
+
};
|
|
97
|
+
exports.createHttpSignStr = createHttpSignStr;
|
|
98
|
+
var _default = {
|
|
99
|
+
createHttpSignStr: createHttpSignStr,
|
|
100
|
+
getApiPath: getApiPath
|
|
101
|
+
};
|
|
102
|
+
exports.default = _default;
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _sign = require("./encipher/sign");
|
|
9
|
+
var _rsa = require("./encipher/rsa");
|
|
10
|
+
var _aes = require("./encipher/aes");
|
|
11
|
+
var _des = require("./encipher/des");
|
|
12
|
+
var _const = require("./const");
|
|
13
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
14
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
15
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
16
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
17
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
18
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
19
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
20
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
21
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
22
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
23
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
24
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
25
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
26
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) { ; } } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
27
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
28
|
+
// import { store } from './store';
|
|
29
|
+
var originFetch = window.fetch;
|
|
30
|
+
// const debugData = store('debugData');
|
|
31
|
+
// (window as any).debugData = debugData;
|
|
32
|
+
var LXREQ = {};
|
|
33
|
+
window.LXREQ = LXREQ;
|
|
34
|
+
function encryptedStr(str, type) {
|
|
35
|
+
var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
36
|
+
if (type === _const.MODE.AES) {
|
|
37
|
+
var _config$aesOptions, _config$aesOptions2;
|
|
38
|
+
return (0, _aes.AESEncrypt)(str, ((_config$aesOptions = config.aesOptions) === null || _config$aesOptions === void 0 ? void 0 : _config$aesOptions.key) || _const.aesKey, (_config$aesOptions2 = config.aesOptions) === null || _config$aesOptions2 === void 0 ? void 0 : _config$aesOptions2.encrypt);
|
|
39
|
+
} else if (type === _const.MODE.RSA) {
|
|
40
|
+
var _config$rsaOptions, _config$rsaOptions2;
|
|
41
|
+
return (0, _rsa.RSAEncrypt)(str, ((_config$rsaOptions = config.rsaOptions) === null || _config$rsaOptions === void 0 ? void 0 : _config$rsaOptions.publicKey) || _const.rsaPublicKey, (_config$rsaOptions2 = config.rsaOptions) === null || _config$rsaOptions2 === void 0 ? void 0 : _config$rsaOptions2.encrypt);
|
|
42
|
+
} else if (type === _const.MODE.DES) {
|
|
43
|
+
var _config$desOptions, _config$desOptions2;
|
|
44
|
+
return (0, _des.DESEncrypt)(str, ((_config$desOptions = config.desOptions) === null || _config$desOptions === void 0 ? void 0 : _config$desOptions.key) || _const.desKey, (_config$desOptions2 = config.desOptions) === null || _config$desOptions2 === void 0 ? void 0 : _config$desOptions2.encrypt);
|
|
45
|
+
}
|
|
46
|
+
return str;
|
|
47
|
+
}
|
|
48
|
+
function decryptedStr(str, type) {
|
|
49
|
+
var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
50
|
+
if (type === _const.MODE.AES) {
|
|
51
|
+
var _config$aesOptions3, _config$aesOptions4;
|
|
52
|
+
return (0, _aes.AESDecrypt)(str, ((_config$aesOptions3 = config.aesOptions) === null || _config$aesOptions3 === void 0 ? void 0 : _config$aesOptions3.key) || _const.aesKey, (_config$aesOptions4 = config.aesOptions) === null || _config$aesOptions4 === void 0 ? void 0 : _config$aesOptions4.decrypt);
|
|
53
|
+
} else if (type === _const.MODE.RSA) {
|
|
54
|
+
var _config$rsaOptions3, _config$rsaOptions4;
|
|
55
|
+
return (0, _rsa.RSADecrypt)(str, ((_config$rsaOptions3 = config.rsaOptions) === null || _config$rsaOptions3 === void 0 ? void 0 : _config$rsaOptions3.privKey) || _const.rsaPrivKey, (_config$rsaOptions4 = config.rsaOptions) === null || _config$rsaOptions4 === void 0 ? void 0 : _config$rsaOptions4.decrypt) || '';
|
|
56
|
+
} else if (type === _const.MODE.DES) {
|
|
57
|
+
var _config$desOptions3, _config$desOptions4;
|
|
58
|
+
return (0, _des.DESDecrypt)(str, ((_config$desOptions3 = config.desOptions) === null || _config$desOptions3 === void 0 ? void 0 : _config$desOptions3.key) || _const.desKey, (_config$desOptions4 = config.desOptions) === null || _config$desOptions4 === void 0 ? void 0 : _config$desOptions4.decrypt);
|
|
59
|
+
}
|
|
60
|
+
return str;
|
|
61
|
+
}
|
|
62
|
+
// 统一请求参数加密
|
|
63
|
+
function encrypted(url, opts, type) {
|
|
64
|
+
var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
65
|
+
var reqId = arguments.length > 4 ? arguments[4] : undefined;
|
|
66
|
+
var isFormData = opts.body instanceof FormData;
|
|
67
|
+
var headerReqId = reqId ? {
|
|
68
|
+
'LX-REQ-ID': "LXREQ.".concat(reqId)
|
|
69
|
+
} : {};
|
|
70
|
+
// search 部分加密
|
|
71
|
+
var encryptedUrl = url.indexOf('?') !== -1 ? url.replace(/[^?]+$/g, function (search) {
|
|
72
|
+
var params = search.split('&').map(function (param) {
|
|
73
|
+
var _param$split = param.split('='),
|
|
74
|
+
_param$split2 = _slicedToArray(_param$split, 2),
|
|
75
|
+
k = _param$split2[0],
|
|
76
|
+
v = _param$split2[1];
|
|
77
|
+
return "".concat(encodeURIComponent(k), "=").concat(encodeURIComponent(encryptedStr(v, type, config)));
|
|
78
|
+
});
|
|
79
|
+
return params.join('&');
|
|
80
|
+
}) : url;
|
|
81
|
+
// body参数加密
|
|
82
|
+
var encryptedOpts = Object.assign({}, opts);
|
|
83
|
+
encryptedOpts.headers = _objectSpread(_objectSpread(_objectSpread({}, opts.headers), headerReqId), {}, _defineProperty({}, _const.securityHeaderKey, type));
|
|
84
|
+
if (isFormData) {
|
|
85
|
+
// formData 加密
|
|
86
|
+
var formData = new FormData();
|
|
87
|
+
var reqBody = opts.body;
|
|
88
|
+
var _iterator = _createForOfIteratorHelper(reqBody.keys()),
|
|
89
|
+
_step;
|
|
90
|
+
try {
|
|
91
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
92
|
+
var key = _step.value;
|
|
93
|
+
var value = reqBody.get(key);
|
|
94
|
+
formData.append(key, encryptedStr(value, type, config));
|
|
95
|
+
}
|
|
96
|
+
} catch (err) {
|
|
97
|
+
_iterator.e(err);
|
|
98
|
+
} finally {
|
|
99
|
+
_iterator.f();
|
|
100
|
+
}
|
|
101
|
+
encryptedOpts.body = formData;
|
|
102
|
+
} else if (opts.body) {
|
|
103
|
+
// 文本加密
|
|
104
|
+
encryptedOpts.body = encryptedStr(opts.body, type, config);
|
|
105
|
+
}
|
|
106
|
+
return [encryptedUrl, encryptedOpts];
|
|
107
|
+
}
|
|
108
|
+
// 将解密数据
|
|
109
|
+
// function debugRecords(id: string, value: any) {
|
|
110
|
+
// // sessionStorage.setItem(id, JSON.stringify(value));
|
|
111
|
+
// Object.defineProperty(LXREQ, id, {
|
|
112
|
+
// get() {
|
|
113
|
+
// // debugData.show(id)
|
|
114
|
+
// return '';
|
|
115
|
+
// },
|
|
116
|
+
// });
|
|
117
|
+
// }
|
|
118
|
+
var fetch = function fetch(url) {
|
|
119
|
+
var fetchOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
120
|
+
var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
121
|
+
var opts = _objectSpread({}, fetchOptions);
|
|
122
|
+
var optSecurityHeaderKey = (opts.headers || {})[_const.securityHeaderKey];
|
|
123
|
+
var isDebug = (config === null || config === void 0 ? void 0 : config.debug) || window.lxDebug || !!window.localStorage.getItem('lxDebug') || true;
|
|
124
|
+
// ------ 参数签名(默认) ------
|
|
125
|
+
if (
|
|
126
|
+
// 配置开启加密
|
|
127
|
+
(config.mode === _const.MODE.SIGN_KEY || config.mode === _const.MODE.SIGN) && (fetchOptions === null || fetchOptions === void 0 ? void 0 : fetchOptions.disabledSignKey) !== true ||
|
|
128
|
+
// 请求头开启加密
|
|
129
|
+
optSecurityHeaderKey === '1.0') {
|
|
130
|
+
var _config$signKeyOption;
|
|
131
|
+
opts.headers = _objectSpread(_objectSpread({}, opts.headers), {}, _defineProperty({}, (config === null || config === void 0 ? void 0 : (_config$signKeyOption = config.signKeyOptions) === null || _config$signKeyOption === void 0 ? void 0 : _config$signKeyOption.key) || _const.signKey, (0, _sign.createHttpSignStr)(url, fetchOptions)));
|
|
132
|
+
return originFetch(url, opts);
|
|
133
|
+
}
|
|
134
|
+
// ------ 参数加密 ------
|
|
135
|
+
if ((config.mode === _const.MODE.RSA || config.mode === _const.MODE.AES) && (fetchOptions === null || fetchOptions === void 0 ? void 0 : fetchOptions.disabledEncrypted) !== true || optSecurityHeaderKey === '2.0' || optSecurityHeaderKey === '3.0' || optSecurityHeaderKey === '4.0') {
|
|
136
|
+
// 标记请求ID,用于获取解密数据
|
|
137
|
+
var reqId = "XA".concat(+new Date());
|
|
138
|
+
// search和body加密
|
|
139
|
+
var _encrypted = encrypted(url, opts, config.mode || optSecurityHeaderKey, config, reqId),
|
|
140
|
+
_encrypted2 = _slicedToArray(_encrypted, 2),
|
|
141
|
+
encryptedUrl = _encrypted2[0],
|
|
142
|
+
encryptedOpts = _encrypted2[1];
|
|
143
|
+
return originFetch(encryptedUrl, encryptedOpts).then( /*#__PURE__*/function () {
|
|
144
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(response) {
|
|
145
|
+
var securityType, respResult, result, json, blob;
|
|
146
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
147
|
+
while (1) {
|
|
148
|
+
switch (_context.prev = _context.next) {
|
|
149
|
+
case 0:
|
|
150
|
+
// 响应解密
|
|
151
|
+
securityType = response.headers.get(_const.securityHeaderKey);
|
|
152
|
+
if (!(securityType && response.body)) {
|
|
153
|
+
_context.next = 22;
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
_context.next = 4;
|
|
157
|
+
return response.text();
|
|
158
|
+
case 4:
|
|
159
|
+
respResult = _context.sent;
|
|
160
|
+
_context.prev = 5;
|
|
161
|
+
result = decryptedStr(respResult, securityType, config);
|
|
162
|
+
_context.next = 18;
|
|
163
|
+
break;
|
|
164
|
+
case 9:
|
|
165
|
+
_context.prev = 9;
|
|
166
|
+
_context.t0 = _context["catch"](5);
|
|
167
|
+
console.error('--------解密失败--------');
|
|
168
|
+
console.error("\u8BF7\u6C42ID\uFF1A".concat(reqId));
|
|
169
|
+
console.error("\u8BF7\u6C42\u5730\u5740\uFF1A".concat(url));
|
|
170
|
+
console.error("\u89E3\u5BC6\u65B9\u5F0F\uFF1A".concat(securityType));
|
|
171
|
+
console.error("\u89E3\u5BC6\u62A5\u6587\uFF1A".concat(respResult));
|
|
172
|
+
console.error("\u5931\u8D25\u539F\u56E0\uFF1A".concat(_context.t0));
|
|
173
|
+
return _context.abrupt("return", new Response(null, {
|
|
174
|
+
status: 400,
|
|
175
|
+
statusText: String(_context.t0)
|
|
176
|
+
}));
|
|
177
|
+
case 18:
|
|
178
|
+
// 开启调试模式,记录解密数据
|
|
179
|
+
if (isDebug || true) {
|
|
180
|
+
// debugRecords(reqId, result);
|
|
181
|
+
}
|
|
182
|
+
// 覆盖响应值
|
|
183
|
+
|
|
184
|
+
try {
|
|
185
|
+
json = JSON.parse(result);
|
|
186
|
+
} catch (e) {
|
|
187
|
+
json = result;
|
|
188
|
+
console.warn("reqId: ".concat(reqId, " \u8F6C\u6362JSON\u5931\u8D25, \u5185\u5BB9\u4E3A"), result);
|
|
189
|
+
}
|
|
190
|
+
blob = new Blob([JSON.stringify(json, null, 2)], {
|
|
191
|
+
type: 'application/json'
|
|
192
|
+
});
|
|
193
|
+
return _context.abrupt("return", new Response(blob));
|
|
194
|
+
case 22:
|
|
195
|
+
return _context.abrupt("return", response);
|
|
196
|
+
case 23:
|
|
197
|
+
case "end":
|
|
198
|
+
return _context.stop();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}, _callee, null, [[5, 9]]);
|
|
202
|
+
}));
|
|
203
|
+
return function (_x2) {
|
|
204
|
+
return _ref.apply(this, arguments);
|
|
205
|
+
};
|
|
206
|
+
}());
|
|
207
|
+
}
|
|
208
|
+
// 其他
|
|
209
|
+
return originFetch(url, opts);
|
|
210
|
+
};
|
|
211
|
+
var _default = fetch;
|
|
212
|
+
exports.default = _default;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _sign = require("./encipher/sign");
|
|
8
|
+
var _fetch = _interopRequireDefault(require("./fetch"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
/* eslint-disable no-console */
|
|
11
|
+
/*
|
|
12
|
+
* @Author: 张国永 zhang.guoyong2@iwhalecloud.com
|
|
13
|
+
* @Date: 2022-08-08 15:08:58
|
|
14
|
+
* @Description: 一个简单的http请求安全加密处理
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// TODO 支持XMLHttpRequest拦截、参数混淆、响应拦截
|
|
18
|
+
|
|
19
|
+
// 使用方式1: 使用fetch请求模块,start({ mode: signKey }),适应经过封装的fetch模块
|
|
20
|
+
// 使用方式2: 使用fetch请求模块,将window.fetch 替换成 fetch,适应自己封装的fetch模块
|
|
21
|
+
// 使用方式3: 不使用fetch请求模块,使用createHttpSignStr自己获取签名,自行在header上添加参数
|
|
22
|
+
|
|
23
|
+
// eslint-disable-next-line import/no-named-as-default, import/no-named-as-default-member
|
|
24
|
+
|
|
25
|
+
var isHttpEncryption = false;
|
|
26
|
+
var originFetch = window.fetch;
|
|
27
|
+
function start(_ref) {
|
|
28
|
+
var _ref$mode = _ref.mode,
|
|
29
|
+
mode = _ref$mode === void 0 ? '1.0' : _ref$mode,
|
|
30
|
+
_ref$signKeyOptions = _ref.signKeyOptions,
|
|
31
|
+
signKeyOptions = _ref$signKeyOptions === void 0 ? {} : _ref$signKeyOptions,
|
|
32
|
+
_ref$aesOptions = _ref.aesOptions,
|
|
33
|
+
aesOptions = _ref$aesOptions === void 0 ? {} : _ref$aesOptions,
|
|
34
|
+
_ref$desOptions = _ref.desOptions,
|
|
35
|
+
desOptions = _ref$desOptions === void 0 ? {} : _ref$desOptions,
|
|
36
|
+
_ref$rsaOptions = _ref.rsaOptions,
|
|
37
|
+
rsaOptions = _ref$rsaOptions === void 0 ? {} : _ref$rsaOptions;
|
|
38
|
+
if (!mode) {
|
|
39
|
+
console.error('http加密开启失败,缺少mode参数');
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
if (isHttpEncryption) return true;
|
|
43
|
+
switch (mode) {
|
|
44
|
+
case 'signKey': // 兼容旧数据
|
|
45
|
+
case '1.0':
|
|
46
|
+
case '2.0':
|
|
47
|
+
case '3.0':
|
|
48
|
+
case '4.0':
|
|
49
|
+
{
|
|
50
|
+
if (typeof window.fetch === 'function') {
|
|
51
|
+
isHttpEncryption = true;
|
|
52
|
+
window.fetch = function (url) {
|
|
53
|
+
var fetchOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
54
|
+
return (0, _fetch.default)(url, fetchOptions, {
|
|
55
|
+
mode: mode,
|
|
56
|
+
signKeyOptions: signKeyOptions,
|
|
57
|
+
aesOptions: aesOptions,
|
|
58
|
+
desOptions: desOptions,
|
|
59
|
+
rsaOptions: rsaOptions
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
} else {
|
|
63
|
+
console.error('http加密开启失败,目前仅支持window.fetch方式');
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
default:
|
|
68
|
+
console.error("http\u52A0\u5BC6\u5F00\u542F\u5931\u8D25\uFF0C\u4E0D\u652F\u6301".concat(mode, "\u6A21\u5F0F"));
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
return isHttpEncryption;
|
|
72
|
+
}
|
|
73
|
+
function stop() {
|
|
74
|
+
isHttpEncryption = false;
|
|
75
|
+
window.fetch = originFetch;
|
|
76
|
+
}
|
|
77
|
+
var _default = {
|
|
78
|
+
start: start,
|
|
79
|
+
stop: stop,
|
|
80
|
+
fetch: _fetch.default,
|
|
81
|
+
createHttpSignStr: _sign.createHttpSignStr
|
|
82
|
+
};
|
|
83
|
+
exports.default = _default;
|