@lingxiteam/assets 1.0.9-alpha.2 → 1.0.9-alpha.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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const createHttpSignStr: (url: string, options: any) => string;
|
|
2
2
|
declare const _default: {
|
|
3
3
|
createHttpSignStr: (url: string, options: any) => string;
|
|
4
|
-
getApiPath: (url: string) =>
|
|
4
|
+
getApiPath: (url: string) => string | undefined;
|
|
5
5
|
};
|
|
6
6
|
export default _default;
|
|
@@ -8,6 +8,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
8
8
|
import { sha256 } from 'js-sha256';
|
|
9
9
|
import { obj2QueryString } from '../../utils/url';
|
|
10
10
|
var SIGN_KEY = process.env.LING_XI_HTTP_SIGN_KEY || 'zrT5bi2escXilaH1fs653uZiH9RWfzCS';
|
|
11
|
+
// 注意:修改此文件请跑测试用例, npm run test
|
|
11
12
|
// 1、签名算法:
|
|
12
13
|
// 通过对url、参数、秘钥拼接成字符串,然后对字符串使用算法SHA-256得到64个字符串,放到header, X-SIGN=XXXXXXX。
|
|
13
14
|
// 2、签名字符串拼接规则:
|
|
@@ -28,45 +29,16 @@ var SIGN_KEY = process.env.LING_XI_HTTP_SIGN_KEY || 'zrT5bi2escXilaH1fs653uZiH9R
|
|
|
28
29
|
// 由于X-B 的规则可能被业务网关使用,并往请求头增加内容,导致前后端加密不一致
|
|
29
30
|
// 2022.08.09 使用以下3个固定值 + X-LX-*匹配 方式
|
|
30
31
|
var hKeys = ['X-B-AUTH', 'X-B-TARGET-ID', 'APP-ID'];
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
// http://host.com/api/a/b/c
|
|
40
|
-
// https://host.com/api/a/b/c
|
|
41
|
-
// //host.com/api/a/b/c
|
|
42
|
-
// => /api/a/b/c
|
|
43
|
-
// =========================
|
|
32
|
+
// 配置指定接口前缀,2023-03-16规则调整,不需要使用
|
|
33
|
+
// const apiPrefix =
|
|
34
|
+
// process.env.LING_XI_HTTP_SIGN_API_PERFIX ||
|
|
35
|
+
// process.env.REACT_APP_HTTP_SIGN_API_PERFIX ||
|
|
36
|
+
// process.env.UMI_APP_HTTP_SIGN_API_PERFIX ||
|
|
37
|
+
// process.env.FISHX_APP_HTTP_SIGN_API_PERFIX ||
|
|
38
|
+
// 'portal,asset,rhin,lcdp,ncdp,flow,app';
|
|
39
|
+
// 获取接口路径,2023-03-16调整,只取最后一级
|
|
44
40
|
var getApiPath = function getApiPath(url) {
|
|
45
|
-
|
|
46
|
-
var fixurl = "/".concat(url.replace(/(^(http:\/\/|https:\/\/|\/\/)[^/]*)|(^\.[./]*)/g, '')).replace('//', '/');
|
|
47
|
-
if (apiPrefix) {
|
|
48
|
-
// 配了接口前缀规则,通过前缀匹配
|
|
49
|
-
// =========================
|
|
50
|
-
// /api/a/api/b => /api/b
|
|
51
|
-
// api/c => /api/c
|
|
52
|
-
// /lapi/d => ''
|
|
53
|
-
// =========================
|
|
54
|
-
return apiPrefix.split(',').reduce(function (pre, n) {
|
|
55
|
-
var matchPath = fixurl.split("/".concat(n, "/")).pop();
|
|
56
|
-
if (matchPath !== fixurl) {
|
|
57
|
-
pre.push("/".concat(n, "/").concat(matchPath));
|
|
58
|
-
}
|
|
59
|
-
return pre;
|
|
60
|
-
}, []).sort(function (a, b) {
|
|
61
|
-
return a.length - b.length;
|
|
62
|
-
})[0] || '';
|
|
63
|
-
}
|
|
64
|
-
// 没有配置接口前缀,使用接口最后三级路径,不足三级取最大层级路径
|
|
65
|
-
// =========================
|
|
66
|
-
// /a/b/c/d => /b/c/d
|
|
67
|
-
// a/b => /a/b
|
|
68
|
-
// =========================
|
|
69
|
-
return "".concat(fixurl.split('/').slice(-3).join('/'));
|
|
41
|
+
return url.split('/').pop();
|
|
70
42
|
};
|
|
71
43
|
export var createHttpSignStr = function createHttpSignStr(url, options) {
|
|
72
44
|
if (!url || !options || !options.method) {
|
package/es/security/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ declare const _default: {
|
|
|
20
20
|
};
|
|
21
21
|
sign: {
|
|
22
22
|
createHttpSignStr: (url: string, options: any) => string;
|
|
23
|
-
getApiPath: (url: string) =>
|
|
23
|
+
getApiPath: (url: string) => string | undefined;
|
|
24
24
|
};
|
|
25
25
|
RSAEncrypt: (value: string, publicKey: string, handle?: any) => any;
|
|
26
26
|
RSADecrypt: (value: string, privKey: string, handle?: any) => any;
|
package/es/utils/url.js
CHANGED
|
@@ -74,6 +74,7 @@ export var parseUrlExpression = function parseUrlExpression(urlStr) {
|
|
|
74
74
|
try {
|
|
75
75
|
return Function('context', "\n with(context) {\n return (function(){\n \"use strict\";\n return ".concat(text.slice(2, text.length - 1), ";\n })();\n }\n "))(params);
|
|
76
76
|
} catch (error) {
|
|
77
|
+
console.warn("".concat(text, "\u8868\u8FBE\u5F0F\u6267\u884C\u6709\u8BEF:"), error);
|
|
77
78
|
return text;
|
|
78
79
|
}
|
|
79
80
|
};
|