mm_validator 0.0.0-stage → 1.0.1

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.
Files changed (52) hide show
  1. package/index.js +9 -0
  2. package/lib/tools/abac/index.js +80 -0
  3. package/lib/tools/basic/index.js +73 -0
  4. package/lib/tools/code/index.js +462 -0
  5. package/lib/tools/enum/index.js +22 -0
  6. package/lib/tools/index.js +16 -0
  7. package/lib/tools/json/index.js +181 -0
  8. package/lib/tools/jwt/index.js +109 -0
  9. package/lib/tools/length/index.js +61 -0
  10. package/lib/tools/oauth/index.js +170 -0
  11. package/lib/tools/params/index.js +99 -0
  12. package/lib/tools/pattern/index.js +58 -0
  13. package/lib/tools/range/index.js +112 -0
  14. package/lib/tools/rbac/index.js +92 -0
  15. package/lib/tools/required/index.js +37 -0
  16. package/lib/tools/sanitize/index.js +124 -0
  17. package/lib/tools/string/index.js +75 -0
  18. package/lib/tools/type/index.js +21 -0
  19. package/package.json +36 -5
  20. package/tool/abac/index.js +7 -0
  21. package/tool/abac/tool.json +76 -0
  22. package/tool/basic/index.js +7 -0
  23. package/tool/basic/tool.json +69 -0
  24. package/tool/code/index.js +7 -0
  25. package/tool/code/tool.json +69 -0
  26. package/tool/enum/index.js +7 -0
  27. package/tool/enum/tool.json +51 -0
  28. package/tool/json/index.js +7 -0
  29. package/tool/json/tool.json +65 -0
  30. package/tool/jwt/index.js +7 -0
  31. package/tool/jwt/tool.json +91 -0
  32. package/tool/length/index.js +7 -0
  33. package/tool/length/tool.json +53 -0
  34. package/tool/oauth/index.js +7 -0
  35. package/tool/oauth/tool.json +86 -0
  36. package/tool/params/index.js +7 -0
  37. package/tool/params/tool.json +92 -0
  38. package/tool/pattern/index.js +7 -0
  39. package/tool/pattern/tool.json +52 -0
  40. package/tool/range/index.js +7 -0
  41. package/tool/range/tool.json +79 -0
  42. package/tool/rbac/index.js +7 -0
  43. package/tool/rbac/tool.json +74 -0
  44. package/tool/required/index.js +7 -0
  45. package/tool/required/tool.json +46 -0
  46. package/tool/sanitize/index.js +7 -0
  47. package/tool/sanitize/tool.json +83 -0
  48. package/tool/string/index.js +7 -0
  49. package/tool/string/tool.json +62 -0
  50. package/tool/type/index.js +7 -0
  51. package/tool/type/tool.json +54 -0
  52. package/README.md +0 -3
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "range",
3
+ "handler": "validator",
4
+ "title": "范围验证器",
5
+ "description": "校验数值比较关系,支持 between/not_between/>/>=/</<=/=/!=/in/not_in 十种模式。适用场景:价格区间校验、库存阈值判断、批量规则验证时。工作流提示:field/value 填字段与数值、mode 选模式、min/max 填边界,结果看 valid 与 errors。",
6
+ "type": "core",
7
+ "params": {
8
+ "type": "object",
9
+ "properties": {
10
+ "field": {
11
+ "type": "string",
12
+ "description": "字段名称"
13
+ },
14
+ "value": {
15
+ "description": "待验证的数值"
16
+ },
17
+ "min": {
18
+ "description": "最小值(between / > / >= / = / != 模式)"
19
+ },
20
+ "max": {
21
+ "description": "最大值(between / < / <= 模式)"
22
+ },
23
+ "mode": {
24
+ "type": "string",
25
+ "description": "比较模式: between / not_between / > / >= / < / <= / = / != / in / not_in",
26
+ "default": "between",
27
+ "enum": [
28
+ "between",
29
+ "not_between",
30
+ ">",
31
+ ">=",
32
+ "<",
33
+ "<=",
34
+ "=",
35
+ "!=",
36
+ "in",
37
+ "not_in"
38
+ ]
39
+ },
40
+ "inclusive_min": {
41
+ "type": "boolean",
42
+ "description": "最小值是否包含边界(between 模式)",
43
+ "default": true
44
+ },
45
+ "inclusive_max": {
46
+ "type": "boolean",
47
+ "description": "最大值是否包含边界(between 模式)",
48
+ "default": true
49
+ },
50
+ "values": {
51
+ "type": "array",
52
+ "description": "候选值列表(in/not_in 模式)"
53
+ },
54
+ "rules": {
55
+ "type": "array",
56
+ "description": "批量规则列表,每项为 {field, value, min, max, mode, ...}"
57
+ }
58
+ }
59
+ },
60
+ "returns": {
61
+ "type": "object",
62
+ "properties": {
63
+ "valid": {
64
+ "type": "boolean",
65
+ "description": "验证是否通过"
66
+ },
67
+ "tip": {
68
+ "type": "string",
69
+ "description": "提示信息,通过时为'参数校验通过',失败时包含错误数量和详情"
70
+ },
71
+ "errors": {
72
+ "type": "array",
73
+ "description": "错误信息列表"
74
+ }
75
+ }
76
+ },
77
+ "options": {},
78
+ "group": "check"
79
+ }
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+ /**
3
+ * rbac —— 工具契约适配层
4
+ * 业务实现归位于模块 lib/tools/rbac/,本文件只把模块能力暴露给加载器。
5
+ * 其它模块可直接 require('mm_validator').tools.rbac 复用。
6
+ */
7
+ module.exports = require('../../lib/tools/rbac');
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "rbac",
3
+ "handler": "validator",
4
+ "title": "RBAC权限验证器",
5
+ "description": "基于角色的访问控制,校验用户角色是否拥有指定权限。适用场景:后台权限判断、菜单与接口授权、角色动态分配时。工作流提示:action 选 check 时填 user_id、role、permission 判权,add_role/remove_role 管理角色,结果看 valid 与 roles。",
6
+ "type": "core",
7
+ "params": {
8
+ "type": "object",
9
+ "properties": {
10
+ "action": {
11
+ "type": "string",
12
+ "description": "操作类型: check/add_role/remove_role/list_roles",
13
+ "enum": [
14
+ "check",
15
+ "add_role",
16
+ "remove_role",
17
+ "list_roles"
18
+ ]
19
+ },
20
+ "user_id": {
21
+ "type": "string",
22
+ "description": "用户ID"
23
+ },
24
+ "role": {
25
+ "type": "string",
26
+ "description": "角色名称"
27
+ },
28
+ "permission": {
29
+ "type": "string",
30
+ "description": "权限标识"
31
+ }
32
+ },
33
+ "required": [
34
+ "action"
35
+ ]
36
+ },
37
+ "returns": {
38
+ "type": "object",
39
+ "properties": {
40
+ "valid": {
41
+ "type": "boolean",
42
+ "description": "验证是否通过"
43
+ },
44
+ "tip": {
45
+ "type": "string",
46
+ "description": "提示信息,通过时为'参数校验通过',失败时包含错误数量和详情"
47
+ },
48
+ "errors": {
49
+ "type": "array",
50
+ "description": "错误信息列表"
51
+ },
52
+ "roles": {
53
+ "type": "object",
54
+ "description": "角色信息,check 返回 {role, permission, allowed},add_role 返回 {role, permissions},list_roles 返回 {roles, mapping}"
55
+ },
56
+ "error": {
57
+ "type": "object",
58
+ "description": "错误信息,仅调用出错时返回",
59
+ "properties": {
60
+ "code": {
61
+ "type": "string",
62
+ "description": "错误码,如 VAL_RBAC"
63
+ },
64
+ "message": {
65
+ "type": "string",
66
+ "description": "错误描述"
67
+ }
68
+ }
69
+ }
70
+ }
71
+ },
72
+ "options": {},
73
+ "group": "permission"
74
+ }
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+ /**
3
+ * required —— 工具契约适配层
4
+ * 业务实现归位于模块 lib/tools/required/,本文件只把模块能力暴露给加载器。
5
+ * 其它模块可直接 require('mm_validator').tools.required 复用。
6
+ */
7
+ module.exports = require('../../lib/tools/required');
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "required",
3
+ "handler": "validator",
4
+ "title": "必填验证器",
5
+ "description": "校验字段值非空,拒绝 null、undefined 与空字符串。适用场景:参数校验、必填项检查,与条件分发器组合做入参守卫时。工作流提示:field 填字段名、value 填待校验值,结果看 valid(boolean) 与 errors,可配合 dispatcher.condition 分流。",
6
+ "type": "core",
7
+ "params": {
8
+ "type": "object",
9
+ "properties": {
10
+ "field": {
11
+ "type": "string",
12
+ "description": "字段名称"
13
+ },
14
+ "value": {
15
+ "description": "待验证的值"
16
+ }
17
+ },
18
+ "required": [
19
+ "field",
20
+ "value"
21
+ ]
22
+ },
23
+ "returns": {
24
+ "type": "object",
25
+ "properties": {
26
+ "valid": {
27
+ "type": "boolean",
28
+ "description": "验证是否通过"
29
+ },
30
+ "tip": {
31
+ "type": "string",
32
+ "description": "提示信息,通过时为'参数校验通过',失败时包含错误数量和详情"
33
+ },
34
+ "errors": {
35
+ "type": "array",
36
+ "description": "错误信息列表"
37
+ },
38
+ "required_fields": {
39
+ "type": "array",
40
+ "description": "被校验的必填字段列表"
41
+ }
42
+ }
43
+ },
44
+ "options": {},
45
+ "group": "check"
46
+ }
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+ /**
3
+ * sanitize —— 工具契约适配层
4
+ * 业务实现归位于模块 lib/tools/sanitize/,本文件只把模块能力暴露给加载器。
5
+ * 其它模块可直接 require('mm_validator').tools.sanitize 复用。
6
+ */
7
+ module.exports = require('../../lib/tools/sanitize');
@@ -0,0 +1,83 @@
1
+ {
2
+ "name": "sanitize",
3
+ "handler": "validator",
4
+ "title": "输入消毒器",
5
+ "description": "对用户输入做安全清洗,检测 SQL 注入、脚本注入与路径遍历攻击,支持对象递归处理。适用场景:外部请求入参入库前消毒、防注入与 XSS 防线时。工作流提示:input 传待清洗值,max_depth/max_string_len/max_keys 限制深度大小,结果看 valid、cleaned 与 threats。",
6
+ "type": "core",
7
+ "params": {
8
+ "type": "object",
9
+ "properties": {
10
+ "input": {
11
+ "description": "待清洗的输入值,支持字符串、对象、数组等任意类型"
12
+ },
13
+ "max_depth": {
14
+ "type": "integer",
15
+ "description": "递归清洗最大深度,默认从 options 读取"
16
+ },
17
+ "max_string_len": {
18
+ "type": "integer",
19
+ "description": "字符串最大长度,超出部分截断"
20
+ },
21
+ "max_keys": {
22
+ "type": "integer",
23
+ "description": "对象最大键数量,超出部分忽略"
24
+ }
25
+ },
26
+ "required": [
27
+ "input"
28
+ ]
29
+ },
30
+ "returns": {
31
+ "type": "object",
32
+ "description": "返回清洗结果,正常时包含清洗后的数据和威胁检测结果,异常时包含 error",
33
+ "properties": {
34
+ "msg": {
35
+ "type": "string",
36
+ "description": "消毒完成/消毒失败"
37
+ },
38
+ "valid": {
39
+ "type": "boolean",
40
+ "description": "是否通过安全检查"
41
+ },
42
+ "cleaned": {
43
+ "description": "清洗后的值"
44
+ },
45
+ "threats": {
46
+ "type": "array",
47
+ "description": "检测到的威胁类型列表 (sql_injection/script_injection/path_traversal)"
48
+ },
49
+ "error": {
50
+ "type": "object",
51
+ "description": "错误信息,仅调用出错时返回",
52
+ "properties": {
53
+ "code": {
54
+ "type": "string",
55
+ "description": "错误码 (EXEC_ 前缀)"
56
+ },
57
+ "message": {
58
+ "type": "string",
59
+ "description": "错误描述"
60
+ }
61
+ }
62
+ }
63
+ }
64
+ },
65
+ "options": {
66
+ "max_depth": {
67
+ "type": "integer",
68
+ "description": "递归清洗最大深度",
69
+ "default": 10
70
+ },
71
+ "max_string_len": {
72
+ "type": "integer",
73
+ "description": "字符串最大长度",
74
+ "default": 1048576
75
+ },
76
+ "max_keys": {
77
+ "type": "integer",
78
+ "description": "对象最大键数量",
79
+ "default": 1000
80
+ }
81
+ },
82
+ "group": "security"
83
+ }
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+ /**
3
+ * string —— 工具契约适配层
4
+ * 业务实现归位于模块 lib/tools/string/,本文件只把模块能力暴露给加载器。
5
+ * 其它模块可直接 require('mm_validator').tools.string 复用。
6
+ */
7
+ module.exports = require('../../lib/tools/string');
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "string",
3
+ "handler": "validator",
4
+ "title": "字符串验证器",
5
+ "description": "校验字符串是否满足匹配条件,支持 contains、starts_with、ends_with 三种模式。适用场景:关键词包含检查、前缀判断、后缀校验时。工作流提示:field/value 填字段与字符串、pattern 填匹配子串、mode 选模式,结果看 valid 与 errors。",
6
+ "type": "core",
7
+ "params": {
8
+ "type": "object",
9
+ "properties": {
10
+ "field": {
11
+ "type": "string",
12
+ "description": "字段名称"
13
+ },
14
+ "value": {
15
+ "type": "string",
16
+ "description": "待验证的字符串"
17
+ },
18
+ "pattern": {
19
+ "type": "string",
20
+ "description": "匹配的子串/模式"
21
+ },
22
+ "mode": {
23
+ "type": "string",
24
+ "description": "匹配模式: contains(包含)/ starts_with(以...开头)/ ends_with(以...结尾)",
25
+ "default": "contains",
26
+ "enum": [
27
+ "contains",
28
+ "starts_with",
29
+ "ends_with"
30
+ ]
31
+ },
32
+ "case_sensitive": {
33
+ "type": "boolean",
34
+ "description": "是否区分大小写",
35
+ "default": true
36
+ },
37
+ "rules": {
38
+ "type": "array",
39
+ "description": "批量规则列表,每项为 {field, value, pattern, mode, case_sensitive}"
40
+ }
41
+ }
42
+ },
43
+ "returns": {
44
+ "type": "object",
45
+ "properties": {
46
+ "valid": {
47
+ "type": "boolean",
48
+ "description": "验证是否通过"
49
+ },
50
+ "tip": {
51
+ "type": "string",
52
+ "description": "提示信息,通过时为'参数校验通过',失败时包含错误数量和详情"
53
+ },
54
+ "errors": {
55
+ "type": "array",
56
+ "description": "错误信息列表"
57
+ }
58
+ }
59
+ },
60
+ "options": {},
61
+ "group": "check"
62
+ }
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+ /**
3
+ * type —— 工具契约适配层
4
+ * 业务实现归位于模块 lib/tools/type/,本文件只把模块能力暴露给加载器。
5
+ * 其它模块可直接 require('mm_validator').tools.type 复用。
6
+ */
7
+ module.exports = require('../../lib/tools/type');
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "type",
3
+ "handler": "validator",
4
+ "title": "类型验证器",
5
+ "description": "校验字段值是否为指定数据类型。适用场景:接口入参类型检查、防止脏数据流入下游、类型守卫分流时。工作流提示:field 填字段名、value 填待验证值、expected_type 填期望类型(string/number/boolean/array/object),结果看 valid 与 errors。",
6
+ "type": "core",
7
+ "params": {
8
+ "type": "object",
9
+ "properties": {
10
+ "field": {
11
+ "type": "string",
12
+ "description": "字段名称"
13
+ },
14
+ "value": {
15
+ "description": "待验证的值"
16
+ },
17
+ "expected_type": {
18
+ "type": "string",
19
+ "description": "期望的类型",
20
+ "enum": [
21
+ "string",
22
+ "number",
23
+ "boolean",
24
+ "array",
25
+ "object"
26
+ ]
27
+ }
28
+ },
29
+ "required": [
30
+ "field",
31
+ "value",
32
+ "expected_type"
33
+ ]
34
+ },
35
+ "returns": {
36
+ "type": "object",
37
+ "properties": {
38
+ "valid": {
39
+ "type": "boolean",
40
+ "description": "验证是否通过"
41
+ },
42
+ "tip": {
43
+ "type": "string",
44
+ "description": "提示信息,通过时为'参数校验通过',失败时包含错误数量和详情"
45
+ },
46
+ "errors": {
47
+ "type": "array",
48
+ "description": "错误信息列表"
49
+ }
50
+ }
51
+ },
52
+ "options": {},
53
+ "group": "check"
54
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.