@freelog/tools-lib 0.1.89 → 0.1.93
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/LICENSE +20 -20
- package/README.md +103 -103
- package/dist/service-API/activities.d.ts +12 -0
- package/dist/service-API/informalNodes.d.ts +15 -45
- package/dist/service-API/policies.d.ts +2 -6
- package/dist/tools-lib.cjs.development.js +536 -926
- package/dist/tools-lib.cjs.development.js.map +1 -1
- package/dist/tools-lib.cjs.production.min.js +1 -1
- package/dist/tools-lib.cjs.production.min.js.map +1 -1
- package/dist/tools-lib.esm.js +536 -926
- package/dist/tools-lib.esm.js.map +1 -1
- package/dist/utils/axios.d.ts +1 -4
- package/package.json +1 -1
- package/src/index.ts +7 -7
- package/src/service-API/activities.ts +32 -0
- package/src/service-API/captcha.ts +30 -30
- package/src/service-API/collections.ts +81 -81
- package/src/service-API/contracts.ts +84 -84
- package/src/service-API/events.ts +18 -18
- package/src/service-API/index.ts +29 -29
- package/src/service-API/informalNodes.ts +238 -238
- package/src/service-API/nodes.ts +65 -65
- package/src/service-API/policies.ts +39 -39
- package/src/service-API/presentables.ts +282 -282
- package/src/service-API/resources.ts +496 -496
- package/src/service-API/storages.ts +345 -345
- package/src/service-API/tools/index.ts +10 -10
- package/src/service-API/transactions.ts +109 -109
- package/src/service-API/user.ts +188 -188
- package/src/utils/axios.ts +8 -3
- package/src/utils/format.ts +89 -89
- package/src/utils/index.ts +18 -18
- package/src/utils/linkTo.ts +332 -332
- package/src/utils/predefined.ts +37 -37
- package/src/utils/regexp.ts +52 -52
- package/src/utils/tools.ts +72 -72
package/src/utils/predefined.ts
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
// export const apiHost = `${window.location.protocol}//qi.${(window.location.host.match(/(?<=\.).*/) || [''])[0]}`;
|
|
2
|
-
|
|
3
|
-
// 预设资源类型
|
|
4
|
-
export const resourceTypes: string[] = ['json', 'widget', 'image', 'audio', 'markdown', 'theme', 'reveal_slide', 'license', 'video', 'catalog'];
|
|
5
|
-
|
|
6
|
-
// 全局列表加载条目数
|
|
7
|
-
export const pageSize: number = 100;
|
|
8
|
-
|
|
9
|
-
// Moment 日期时间格式
|
|
10
|
-
export const momentDateFormat: string = 'YYYY-MM-DD'
|
|
11
|
-
export const momentDateTimeFormat: string = 'YYYY-MM-DD HH:mm';
|
|
12
|
-
|
|
13
|
-
// 签约方用户的身份类型定义
|
|
14
|
-
export enum EnumContractPartyIdentityType {
|
|
15
|
-
resource = 1,
|
|
16
|
-
node,
|
|
17
|
-
consumer,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// 标的物类型定义
|
|
21
|
-
export enum EnumSubjectType {
|
|
22
|
-
resource = 1,
|
|
23
|
-
exhibit,
|
|
24
|
-
user,
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// 合约状态定义
|
|
28
|
-
export enum EnumContractStatus {
|
|
29
|
-
pending,
|
|
30
|
-
authorized,
|
|
31
|
-
stopped,
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// 合约授权状态定义
|
|
35
|
-
// export enum ContractAuthStatus {
|
|
36
|
-
//
|
|
37
|
-
// }
|
|
1
|
+
// export const apiHost = `${window.location.protocol}//qi.${(window.location.host.match(/(?<=\.).*/) || [''])[0]}`;
|
|
2
|
+
|
|
3
|
+
// 预设资源类型
|
|
4
|
+
export const resourceTypes: string[] = ['json', 'widget', 'image', 'audio', 'markdown', 'theme', 'reveal_slide', 'license', 'video', 'catalog'];
|
|
5
|
+
|
|
6
|
+
// 全局列表加载条目数
|
|
7
|
+
export const pageSize: number = 100;
|
|
8
|
+
|
|
9
|
+
// Moment 日期时间格式
|
|
10
|
+
export const momentDateFormat: string = 'YYYY-MM-DD'
|
|
11
|
+
export const momentDateTimeFormat: string = 'YYYY-MM-DD HH:mm';
|
|
12
|
+
|
|
13
|
+
// 签约方用户的身份类型定义
|
|
14
|
+
export enum EnumContractPartyIdentityType {
|
|
15
|
+
resource = 1,
|
|
16
|
+
node,
|
|
17
|
+
consumer,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// 标的物类型定义
|
|
21
|
+
export enum EnumSubjectType {
|
|
22
|
+
resource = 1,
|
|
23
|
+
exhibit,
|
|
24
|
+
user,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// 合约状态定义
|
|
28
|
+
export enum EnumContractStatus {
|
|
29
|
+
pending,
|
|
30
|
+
authorized,
|
|
31
|
+
stopped,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// 合约授权状态定义
|
|
35
|
+
// export enum ContractAuthStatus {
|
|
36
|
+
//
|
|
37
|
+
// }
|
package/src/utils/regexp.ts
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
// 展品名称
|
|
2
|
-
export const EXHIBIT_NAME: RegExp = new RegExp(/^(?!.*(\\|\/|:|\*|\?|"|<|>|\||\s|@|\$|#)).{1,60}$/);
|
|
3
|
-
|
|
4
|
-
// 资源名称
|
|
5
|
-
export const RESOURCE_NAME: RegExp = new RegExp(/^(?!.*(\\|\/|:|\*|\?|"|<|>|\||\s|@|\$|#)).{1,60}$/);
|
|
6
|
-
|
|
7
|
-
// 资源类型
|
|
8
|
-
// export const RESOURCE_TYPE: RegExp = new RegExp(/^(?!_)[a-z0-9_]{3,20}(?<!_)$/);
|
|
9
|
-
export const RESOURCE_TYPE: RegExp = new RegExp(/^[a-z0-9][a-z0-9_]{1,18}[a-z0-9]$/);
|
|
10
|
-
|
|
11
|
-
// 自定义属性键
|
|
12
|
-
export const CUSTOM_KEY: RegExp = new RegExp(/^[a-zA-Z0-9_]{1,20}$/);
|
|
13
|
-
|
|
14
|
-
// 节点名称
|
|
15
|
-
export const NODE_NAME: RegExp = new RegExp(/^[\u4E00-\u9FA5|a-zA-Z0-9]{2,24}$/);
|
|
16
|
-
|
|
17
|
-
// 节点地址
|
|
18
|
-
// export const NODE_DOMAIN: RegExp = new RegExp(/^(?!-)[a-z0-9-]{4,24}(?<!-)$/);
|
|
19
|
-
export const NODE_DOMAIN: RegExp = new RegExp(/^[a-z0-9][a-z0-9-]{2,22}[a-z0-9]$/);
|
|
20
|
-
|
|
21
|
-
// 支付密码
|
|
22
|
-
export const PAY_PASSWORD: RegExp = new RegExp(/^\d{6}$/);
|
|
23
|
-
|
|
24
|
-
// 手机号码
|
|
25
|
-
export const MOBILE_PHONE_NUMBER = new RegExp(/^1[345789]\d{9}$/);
|
|
26
|
-
// export const TELEPHONE_NUMBER = /^((13[0-9])|(14[5-9])|(15([0-3]|[5-9]))|(16[6-7])|(17[1-8])|(18[0-9])|(19[1|3])|(19[5|6])|(19[8|9]))\d{8}$/
|
|
27
|
-
|
|
28
|
-
// 邮箱地址
|
|
29
|
-
export const EMAIL_ADDRESS: RegExp = new RegExp(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/);
|
|
30
|
-
|
|
31
|
-
// 用户名
|
|
32
|
-
// export const USERNAME: RegExp = new RegExp(/^(?!-)[A-Za-z0-9-]{1,30}(?<!-)$/);
|
|
33
|
-
export const USERNAME: RegExp = new RegExp(/^([A-Za-z0-9][A-Za-z0-9-]{0,28})?[A-Za-z0-9]$/);
|
|
34
|
-
|
|
35
|
-
// 用户密码
|
|
36
|
-
// export const PASSWORD = /^(?=.*[a-zA-Z])(?=.*[0-9]).{6,24}$/;
|
|
37
|
-
export const PASSWORD: RegExp = new RegExp(/^(?=.*[0-9])(?=.*[a-zA-Z])(.{6,24})$/);
|
|
38
|
-
|
|
39
|
-
// 自然数
|
|
40
|
-
export const NATURAL_NUMBER: RegExp = new RegExp(/^[0-9]*$/);
|
|
41
|
-
|
|
42
|
-
// 正整数
|
|
43
|
-
export const POSITIVE_INTEGER = new RegExp(/^[1-9]\d*$/);
|
|
44
|
-
|
|
45
|
-
// 最多两位小数的正数
|
|
46
|
-
export const MAX_2_DECIMAL_POSITIVE_NUMBER = new RegExp(/^\d+(.\d{1,2})?$/);
|
|
47
|
-
|
|
48
|
-
// 对象的Bucket名称
|
|
49
|
-
export const BUCKET_NAME: RegExp = new RegExp(/^([a-z0-9][a-z0-9-]{0,61})?[a-z0-9]$/);
|
|
50
|
-
|
|
51
|
-
// JS变量名称
|
|
52
|
-
export const JS_VARIABLE_NAME: RegExp = new RegExp(/^[A-Za-z$_][\w$_]*$/);
|
|
1
|
+
// 展品名称
|
|
2
|
+
export const EXHIBIT_NAME: RegExp = new RegExp(/^(?!.*(\\|\/|:|\*|\?|"|<|>|\||\s|@|\$|#)).{1,60}$/);
|
|
3
|
+
|
|
4
|
+
// 资源名称
|
|
5
|
+
export const RESOURCE_NAME: RegExp = new RegExp(/^(?!.*(\\|\/|:|\*|\?|"|<|>|\||\s|@|\$|#)).{1,60}$/);
|
|
6
|
+
|
|
7
|
+
// 资源类型
|
|
8
|
+
// export const RESOURCE_TYPE: RegExp = new RegExp(/^(?!_)[a-z0-9_]{3,20}(?<!_)$/);
|
|
9
|
+
export const RESOURCE_TYPE: RegExp = new RegExp(/^[a-z0-9][a-z0-9_]{1,18}[a-z0-9]$/);
|
|
10
|
+
|
|
11
|
+
// 自定义属性键
|
|
12
|
+
export const CUSTOM_KEY: RegExp = new RegExp(/^[a-zA-Z0-9_]{1,20}$/);
|
|
13
|
+
|
|
14
|
+
// 节点名称
|
|
15
|
+
export const NODE_NAME: RegExp = new RegExp(/^[\u4E00-\u9FA5|a-zA-Z0-9]{2,24}$/);
|
|
16
|
+
|
|
17
|
+
// 节点地址
|
|
18
|
+
// export const NODE_DOMAIN: RegExp = new RegExp(/^(?!-)[a-z0-9-]{4,24}(?<!-)$/);
|
|
19
|
+
export const NODE_DOMAIN: RegExp = new RegExp(/^[a-z0-9][a-z0-9-]{2,22}[a-z0-9]$/);
|
|
20
|
+
|
|
21
|
+
// 支付密码
|
|
22
|
+
export const PAY_PASSWORD: RegExp = new RegExp(/^\d{6}$/);
|
|
23
|
+
|
|
24
|
+
// 手机号码
|
|
25
|
+
export const MOBILE_PHONE_NUMBER = new RegExp(/^1[345789]\d{9}$/);
|
|
26
|
+
// export const TELEPHONE_NUMBER = /^((13[0-9])|(14[5-9])|(15([0-3]|[5-9]))|(16[6-7])|(17[1-8])|(18[0-9])|(19[1|3])|(19[5|6])|(19[8|9]))\d{8}$/
|
|
27
|
+
|
|
28
|
+
// 邮箱地址
|
|
29
|
+
export const EMAIL_ADDRESS: RegExp = new RegExp(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/);
|
|
30
|
+
|
|
31
|
+
// 用户名
|
|
32
|
+
// export const USERNAME: RegExp = new RegExp(/^(?!-)[A-Za-z0-9-]{1,30}(?<!-)$/);
|
|
33
|
+
export const USERNAME: RegExp = new RegExp(/^([A-Za-z0-9][A-Za-z0-9-]{0,28})?[A-Za-z0-9]$/);
|
|
34
|
+
|
|
35
|
+
// 用户密码
|
|
36
|
+
// export const PASSWORD = /^(?=.*[a-zA-Z])(?=.*[0-9]).{6,24}$/;
|
|
37
|
+
export const PASSWORD: RegExp = new RegExp(/^(?=.*[0-9])(?=.*[a-zA-Z])(.{6,24})$/);
|
|
38
|
+
|
|
39
|
+
// 自然数
|
|
40
|
+
export const NATURAL_NUMBER: RegExp = new RegExp(/^[0-9]*$/);
|
|
41
|
+
|
|
42
|
+
// 正整数
|
|
43
|
+
export const POSITIVE_INTEGER = new RegExp(/^[1-9]\d*$/);
|
|
44
|
+
|
|
45
|
+
// 最多两位小数的正数
|
|
46
|
+
export const MAX_2_DECIMAL_POSITIVE_NUMBER = new RegExp(/^\d+(.\d{1,2})?$/);
|
|
47
|
+
|
|
48
|
+
// 对象的Bucket名称
|
|
49
|
+
export const BUCKET_NAME: RegExp = new RegExp(/^([a-z0-9][a-z0-9-]{0,61})?[a-z0-9]$/);
|
|
50
|
+
|
|
51
|
+
// JS变量名称
|
|
52
|
+
export const JS_VARIABLE_NAME: RegExp = new RegExp(/^[A-Za-z$_][\w$_]*$/);
|
package/src/utils/tools.ts
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
import * as CryptoJS from 'crypto-js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 根据 File 获取 SHA1 Hash 字符串
|
|
5
|
-
* @param file
|
|
6
|
-
* @return {Promise<string>}
|
|
7
|
-
*/
|
|
8
|
-
export function getSHA1Hash(file: File): Promise<string> {
|
|
9
|
-
return new Promise((resolve) => {
|
|
10
|
-
const reader: FileReader = new FileReader();
|
|
11
|
-
reader.onload = function () {
|
|
12
|
-
const wordArray = CryptoJS.lib.WordArray.create(reader.result as any);
|
|
13
|
-
const hash = CryptoJS.SHA1(wordArray).toString();
|
|
14
|
-
resolve(hash);
|
|
15
|
-
};
|
|
16
|
-
reader.readAsArrayBuffer(file);
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* 生成随机码
|
|
22
|
-
*/
|
|
23
|
-
export function generateRandomCode(strLen: number = 5): string {
|
|
24
|
-
const allStr: string = 'ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
|
|
25
|
-
const newStrArr: string[] = [];
|
|
26
|
-
for (let i = 0; i < strLen; i++) {
|
|
27
|
-
newStrArr.push(allStr[Math.floor(Math.random() * 61)]);
|
|
28
|
-
}
|
|
29
|
-
return newStrArr.join('');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* 通过读取 cookies 获取用户 ID
|
|
34
|
-
*/
|
|
35
|
-
export function getUserIDByCookies(): number {
|
|
36
|
-
const uid: string | undefined = document.cookie.split('; ').find((co) => co.startsWith('uid='));
|
|
37
|
-
if (!uid) {
|
|
38
|
-
return -1;
|
|
39
|
-
}
|
|
40
|
-
return Number(uid.replace('uid=', ''));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* 将服务端的合约状态转换成前端需要的状态
|
|
46
|
-
*/
|
|
47
|
-
interface TransformServerAPIContractStateParams {
|
|
48
|
-
status: 0 | 1 | 2; // 合同综合状态: 0:正常 1:已终止(不接受任何事件,也不给授权,事实上无效的合约) 2:异常
|
|
49
|
-
authStatus: 1 | 2 | 128 | number; // 合同授权状态 1:正式授权 2:测试授权 128:未获得授权
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function transformServerAPIContractState({
|
|
53
|
-
status,
|
|
54
|
-
authStatus,
|
|
55
|
-
}: TransformServerAPIContractStateParams): 'active' | 'testActive' | 'inactive' | 'terminal' | 'exception' {
|
|
56
|
-
if (status === 0) {
|
|
57
|
-
if (authStatus === 1 || authStatus === 3) {
|
|
58
|
-
return 'active';
|
|
59
|
-
}
|
|
60
|
-
if (authStatus === 2) {
|
|
61
|
-
return 'testActive';
|
|
62
|
-
}
|
|
63
|
-
if (authStatus === 128) {
|
|
64
|
-
return 'inactive';
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (status === 1) {
|
|
69
|
-
return 'terminal';
|
|
70
|
-
}
|
|
71
|
-
return 'exception';
|
|
72
|
-
}
|
|
1
|
+
import * as CryptoJS from 'crypto-js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 根据 File 获取 SHA1 Hash 字符串
|
|
5
|
+
* @param file
|
|
6
|
+
* @return {Promise<string>}
|
|
7
|
+
*/
|
|
8
|
+
export function getSHA1Hash(file: File): Promise<string> {
|
|
9
|
+
return new Promise((resolve) => {
|
|
10
|
+
const reader: FileReader = new FileReader();
|
|
11
|
+
reader.onload = function () {
|
|
12
|
+
const wordArray = CryptoJS.lib.WordArray.create(reader.result as any);
|
|
13
|
+
const hash = CryptoJS.SHA1(wordArray).toString();
|
|
14
|
+
resolve(hash);
|
|
15
|
+
};
|
|
16
|
+
reader.readAsArrayBuffer(file);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 生成随机码
|
|
22
|
+
*/
|
|
23
|
+
export function generateRandomCode(strLen: number = 5): string {
|
|
24
|
+
const allStr: string = 'ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
|
|
25
|
+
const newStrArr: string[] = [];
|
|
26
|
+
for (let i = 0; i < strLen; i++) {
|
|
27
|
+
newStrArr.push(allStr[Math.floor(Math.random() * 61)]);
|
|
28
|
+
}
|
|
29
|
+
return newStrArr.join('');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 通过读取 cookies 获取用户 ID
|
|
34
|
+
*/
|
|
35
|
+
export function getUserIDByCookies(): number {
|
|
36
|
+
const uid: string | undefined = document.cookie.split('; ').find((co) => co.startsWith('uid='));
|
|
37
|
+
if (!uid) {
|
|
38
|
+
return -1;
|
|
39
|
+
}
|
|
40
|
+
return Number(uid.replace('uid=', ''));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 将服务端的合约状态转换成前端需要的状态
|
|
46
|
+
*/
|
|
47
|
+
interface TransformServerAPIContractStateParams {
|
|
48
|
+
status: 0 | 1 | 2; // 合同综合状态: 0:正常 1:已终止(不接受任何事件,也不给授权,事实上无效的合约) 2:异常
|
|
49
|
+
authStatus: 1 | 2 | 128 | number; // 合同授权状态 1:正式授权 2:测试授权 128:未获得授权
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function transformServerAPIContractState({
|
|
53
|
+
status,
|
|
54
|
+
authStatus,
|
|
55
|
+
}: TransformServerAPIContractStateParams): 'active' | 'testActive' | 'inactive' | 'terminal' | 'exception' {
|
|
56
|
+
if (status === 0) {
|
|
57
|
+
if (authStatus === 1 || authStatus === 3) {
|
|
58
|
+
return 'active';
|
|
59
|
+
}
|
|
60
|
+
if (authStatus === 2) {
|
|
61
|
+
return 'testActive';
|
|
62
|
+
}
|
|
63
|
+
if (authStatus === 128) {
|
|
64
|
+
return 'inactive';
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (status === 1) {
|
|
69
|
+
return 'terminal';
|
|
70
|
+
}
|
|
71
|
+
return 'exception';
|
|
72
|
+
}
|