@prosopo/user-access-policy 3.12.8 → 3.12.10
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/.turbo/turbo-build$colon$cjs.log +45 -41
- package/.turbo/turbo-build$colon$tsc.log +14 -14
- package/.turbo/turbo-build.log +46 -42
- package/CHANGELOG.md +24 -0
- package/dist/.export.js +7 -21
- package/dist/_virtual/_rolldown/runtime.js +3 -0
- package/dist/api/.export.js +2 -9
- package/dist/api/accessRulesApiClient.js +1 -1
- package/dist/api/delete/.export.js +2 -1
- package/dist/api/delete/deleteAllRules.js +22 -24
- package/dist/api/delete/deleteRuleGroups.js +39 -51
- package/dist/api/delete/deleteRules.js +37 -41
- package/dist/api/read/.export.js +2 -1
- package/dist/api/read/fetchRules.js +34 -42
- package/dist/api/read/findRuleIds.js +35 -48
- package/dist/api/read/getMissingIds.js +36 -40
- package/dist/api/ruleApiRoutes.js +62 -120
- package/dist/api/rulesApiClient.js +51 -87
- package/dist/api/write/.export.js +2 -1
- package/dist/api/write/insertRules.js +84 -102
- package/dist/api/write/rehashRules.js +48 -56
- package/dist/cjs/.export.cjs +21 -23
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/cjs/api/.export.cjs +6 -10
- package/dist/cjs/api/accessRulesApiClient.cjs +0 -0
- package/dist/cjs/api/delete/.export.cjs +0 -1
- package/dist/cjs/api/delete/deleteAllRules.cjs +22 -24
- package/dist/cjs/api/delete/deleteRuleGroups.cjs +39 -51
- package/dist/cjs/api/delete/deleteRules.cjs +41 -42
- package/dist/cjs/api/read/.export.cjs +0 -1
- package/dist/cjs/api/read/fetchRules.cjs +34 -41
- package/dist/cjs/api/read/findRuleIds.cjs +37 -48
- package/dist/cjs/api/read/getMissingIds.cjs +36 -39
- package/dist/cjs/api/ruleApiRoutes.cjs +69 -125
- package/dist/cjs/api/rulesApiClient.cjs +54 -90
- package/dist/cjs/api/write/.export.cjs +0 -1
- package/dist/cjs/api/write/insertRules.cjs +85 -103
- package/dist/cjs/api/write/rehashRules.cjs +48 -56
- package/dist/cjs/classifyOs.cjs +46 -26
- package/dist/cjs/mongoose/.export.cjs +2 -3
- package/dist/cjs/mongoose/mongooseRuleSchema.cjs +97 -36
- package/dist/cjs/redis/.export.cjs +4 -5
- package/dist/cjs/redis/reader/redisAggregate.cjs +59 -84
- package/dist/cjs/redis/reader/redisRulesQuery.cjs +74 -116
- package/dist/cjs/redis/reader/redisRulesReader.cjs +322 -503
- package/dist/cjs/redis/reader/redisRulesSplitQuery.cjs +94 -72
- package/dist/cjs/redis/redisClient.cjs +53 -58
- package/dist/cjs/redis/redisRuleIndex.cjs +93 -49
- package/dist/cjs/redis/redisRulesStorage.cjs +21 -30
- package/dist/cjs/redis/redisRulesWriter.cjs +86 -112
- package/dist/cjs/rule.cjs +8 -7
- package/dist/cjs/ruleInput/.export.cjs +7 -8
- package/dist/cjs/ruleInput/policyInput.cjs +35 -58
- package/dist/cjs/ruleInput/ruleInput.cjs +37 -42
- package/dist/cjs/ruleInput/userScopeInput.cjs +47 -55
- package/dist/cjs/ruleRecord.cjs +15 -22
- package/dist/cjs/rulesStorage.cjs +7 -6
- package/dist/cjs/transformRule.cjs +36 -70
- package/dist/classifyOs.js +48 -29
- package/dist/mongoose/.export.js +2 -3
- package/dist/mongoose/mongooseRuleSchema.js +99 -38
- package/dist/redis/.export.js +3 -5
- package/dist/redis/reader/redisAggregate.js +60 -86
- package/dist/redis/reader/redisRulesQuery.js +75 -118
- package/dist/redis/reader/redisRulesReader.js +312 -487
- package/dist/redis/reader/redisRulesSplitQuery.js +96 -75
- package/dist/redis/redisClient.js +54 -62
- package/dist/redis/redisRuleIndex.js +93 -58
- package/dist/redis/redisRulesStorage.js +21 -30
- package/dist/redis/redisRulesWriter.js +82 -113
- package/dist/rule.js +10 -10
- package/dist/ruleInput/.export.js +3 -7
- package/dist/ruleInput/policyInput.js +35 -61
- package/dist/ruleInput/ruleInput.js +36 -44
- package/dist/ruleInput/userScopeInput.js +44 -55
- package/dist/ruleRecord.js +17 -27
- package/dist/rulesStorage.js +9 -8
- package/dist/tests/redis/redisRulesStorage.integration.test.js +1 -3
- package/dist/tests/redis/redisRulesStorage.integration.test.js.map +1 -1
- package/dist/transformRule.js +34 -73
- package/entries.ts +25 -6
- package/package.json +13 -12
- package/src/tests/redis/redisRulesStorage.integration.test.ts +191 -195
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,125 +1,82 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { userScopeSchema } from "../../ruleInput/userScopeInput.js";
|
|
1
|
+
import "../../_virtual/_rolldown/runtime.js";
|
|
3
2
|
import { FilterScopeMatch } from "../../rulesStorage.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (scope.numericIpMaskMin === void 0 && scope.numericIpMaskMax === void 0) {
|
|
14
|
-
return "ismissing(@numericIp) ismissing(@numericIpMaskMin) ismissing(@numericIpMaskMax)";
|
|
15
|
-
}
|
|
16
|
-
return "";
|
|
17
|
-
},
|
|
18
|
-
numericIpMaskMin: (value, scope) => {
|
|
19
|
-
if (scope.numericIp !== void 0) {
|
|
20
|
-
return "";
|
|
21
|
-
}
|
|
22
|
-
if (value === void 0 && scope.numericIpMaskMax === void 0) {
|
|
23
|
-
return "";
|
|
24
|
-
}
|
|
25
|
-
return value !== void 0 ? `@numericIpMaskMin:[-inf ${value}]` : "ismissing(@numericIpMaskMin)";
|
|
26
|
-
},
|
|
27
|
-
numericIpMaskMax: (value, scope) => {
|
|
28
|
-
if (scope.numericIp !== void 0) {
|
|
29
|
-
return "";
|
|
30
|
-
}
|
|
31
|
-
if (value === void 0 && scope.numericIpMaskMin === void 0) {
|
|
32
|
-
return "";
|
|
33
|
-
}
|
|
34
|
-
return value !== void 0 ? `@numericIpMaskMax:[${value} +inf]` : "ismissing(@numericIpMaskMax)";
|
|
35
|
-
}
|
|
3
|
+
import { AccessPolicyType, GLOBAL_CLIENT_SCOPE_SENTINEL } from "../../rule.js";
|
|
4
|
+
import { userScopeSchema } from "../../ruleInput/userScopeInput.js";
|
|
5
|
+
//#region src/redis/reader/redisRulesQuery.ts
|
|
6
|
+
/**
|
|
7
|
+
* Escapes special characters for Redis TAG field queries.
|
|
8
|
+
* Redis TAG fields treat these characters as special and they must be escaped with a backslash.
|
|
9
|
+
*/
|
|
10
|
+
var escapeTagValue = (value) => {
|
|
11
|
+
return value.replace(/([,.<>{}\[\]"':;!@#$%^&*()\-+=~|/\\])/g, "\\$1");
|
|
36
12
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
scopeMap.set(name, void 0);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
scopeEntries = [...scopeMap.entries()];
|
|
58
|
-
}
|
|
59
|
-
const scopeObj = Object.fromEntries(scopeEntries);
|
|
60
|
-
return scopeEntries.map(
|
|
61
|
-
([scopeFieldName, scopeFieldValue]) => getUserScopeFieldQuery(
|
|
62
|
-
scopeFieldName,
|
|
63
|
-
scopeFieldValue,
|
|
64
|
-
FilterScopeMatchType,
|
|
65
|
-
scopeObj
|
|
66
|
-
)
|
|
67
|
-
).filter(Boolean).join(scopeJoinType);
|
|
13
|
+
var REDIS_QUERY_DIALECT = 2;
|
|
14
|
+
var userIpQueries = {
|
|
15
|
+
numericIp: (value, scope) => {
|
|
16
|
+
if (void 0 !== value) return `( @numericIp:[${value} ${value}] | ( @numericIpMaskMin:[-inf ${value}] @numericIpMaskMax:[${value} +inf] ) )`;
|
|
17
|
+
if (scope.numericIpMaskMin === void 0 && scope.numericIpMaskMax === void 0) return "ismissing(@numericIp) ismissing(@numericIpMaskMin) ismissing(@numericIpMaskMax)";
|
|
18
|
+
return "";
|
|
19
|
+
},
|
|
20
|
+
numericIpMaskMin: (value, scope) => {
|
|
21
|
+
if (scope.numericIp !== void 0) return "";
|
|
22
|
+
if (value === void 0 && scope.numericIpMaskMax === void 0) return "";
|
|
23
|
+
return value !== void 0 ? `@numericIpMaskMin:[-inf ${value}]` : "ismissing(@numericIpMaskMin)";
|
|
24
|
+
},
|
|
25
|
+
numericIpMaskMax: (value, scope) => {
|
|
26
|
+
if (scope.numericIp !== void 0) return "";
|
|
27
|
+
if (value === void 0 && scope.numericIpMaskMin === void 0) return "";
|
|
28
|
+
return value !== void 0 ? `@numericIpMaskMax:[${value} +inf]` : "ismissing(@numericIpMaskMax)";
|
|
29
|
+
}
|
|
68
30
|
};
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
31
|
+
var getUserScopeQuery = (userScope, FilterScopeMatchType, matchingFieldsOnly) => {
|
|
32
|
+
let scopeEntries = Object.entries(userScope);
|
|
33
|
+
let scopeJoinType = " ";
|
|
34
|
+
if (FilterScopeMatchType === FilterScopeMatch.Greedy) {
|
|
35
|
+
scopeEntries = scopeEntries.filter(([_, value]) => value !== void 0);
|
|
36
|
+
scopeJoinType = " | ";
|
|
37
|
+
}
|
|
38
|
+
if (matchingFieldsOnly) {
|
|
39
|
+
const scopeMap = new Map(scopeEntries);
|
|
40
|
+
if (scopeMap.has("numericIp") && scopeMap.get("numericIp") === void 0) {
|
|
41
|
+
scopeMap.set("numericIpMaskMin", void 0);
|
|
42
|
+
scopeMap.set("numericIpMaskMax", void 0);
|
|
43
|
+
}
|
|
44
|
+
for (const name of Object.keys(userScopeSchema.shape)) if (!scopeMap.has(name)) scopeMap.set(name, void 0);
|
|
45
|
+
scopeEntries = [...scopeMap.entries()];
|
|
46
|
+
}
|
|
47
|
+
const scopeObj = Object.fromEntries(scopeEntries);
|
|
48
|
+
return scopeEntries.map(([scopeFieldName, scopeFieldValue]) => getUserScopeFieldQuery(scopeFieldName, scopeFieldValue, FilterScopeMatchType, scopeObj)).filter(Boolean).join(scopeJoinType);
|
|
87
49
|
};
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
50
|
+
var FIELDS_REQUIRING_ESCAPE = /* @__PURE__ */ new Set(["coords"]);
|
|
51
|
+
var NUMERIC_FIELDS = /* @__PURE__ */ new Set(["asn"]);
|
|
52
|
+
var getUserScopeFieldQuery = (fieldName, fieldValue, scopeMatch, fullScope) => {
|
|
53
|
+
if (fieldName in userIpQueries) {
|
|
54
|
+
const queryBuilder = userIpQueries[fieldName];
|
|
55
|
+
return queryBuilder(fieldValue, fullScope);
|
|
56
|
+
}
|
|
57
|
+
if (void 0 === fieldValue) return `ismissing(@${fieldName})`;
|
|
58
|
+
const stringValue = String(fieldValue);
|
|
59
|
+
if (NUMERIC_FIELDS.has(fieldName)) return `@${fieldName}:[${stringValue} ${stringValue}]`;
|
|
60
|
+
return `@${fieldName}:{${FIELDS_REQUIRING_ESCAPE.has(fieldName) ? escapeTagValue(stringValue) : stringValue}}`;
|
|
95
61
|
};
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
if (filter.blockOnly) {
|
|
103
|
-
queryParts.push(`@type:{${AccessPolicyType.Block}}`);
|
|
104
|
-
}
|
|
105
|
-
const policyScopeQuery = getPolicyScopeQuery(
|
|
106
|
-
policyScope,
|
|
107
|
-
filter.policyScopeMatch
|
|
108
|
-
);
|
|
109
|
-
if (policyScopeQuery) {
|
|
110
|
-
queryParts.push(policyScopeQuery);
|
|
111
|
-
}
|
|
112
|
-
if (userScope && Object.keys(userScope).length > 0) {
|
|
113
|
-
const userScopeFilter = getUserScopeQuery(
|
|
114
|
-
userScope,
|
|
115
|
-
filter.userScopeMatch,
|
|
116
|
-
matchingFieldsOnly
|
|
117
|
-
);
|
|
118
|
-
queryParts.push(`( ${userScopeFilter} )`);
|
|
119
|
-
}
|
|
120
|
-
return queryParts.length > 0 ? queryParts.join(" ") : "*";
|
|
62
|
+
var GLOBAL_MATCH_CLAUSE_INNER = `@clientId:{${GLOBAL_CLIENT_SCOPE_SENTINEL}} | ismissing(@clientId)`;
|
|
63
|
+
var getPolicyScopeQuery = (policyScope, scopeMatch) => {
|
|
64
|
+
const clientId = policyScope?.clientId;
|
|
65
|
+
if ("string" === typeof clientId) return FilterScopeMatch.Exact === scopeMatch ? `@clientId:{${clientId}}` : `( @clientId:{${clientId}} | ${GLOBAL_MATCH_CLAUSE_INNER} )`;
|
|
66
|
+
return FilterScopeMatch.Exact === scopeMatch ? `( ${GLOBAL_MATCH_CLAUSE_INNER} )` : "";
|
|
121
67
|
};
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
68
|
+
var getRulesRedisQuery = (filter, matchingFieldsOnly) => {
|
|
69
|
+
const { policyScope, userScope } = filter;
|
|
70
|
+
const queryParts = [];
|
|
71
|
+
if (filter.groupId) queryParts.push(`@groupId:{${filter.groupId}}`);
|
|
72
|
+
if (filter.blockOnly) queryParts.push(`@type:{${AccessPolicyType.Block}}`);
|
|
73
|
+
const policyScopeQuery = getPolicyScopeQuery(policyScope, filter.policyScopeMatch);
|
|
74
|
+
if (policyScopeQuery) queryParts.push(policyScopeQuery);
|
|
75
|
+
if (userScope && Object.keys(userScope).length > 0) {
|
|
76
|
+
const userScopeFilter = getUserScopeQuery(userScope, filter.userScopeMatch, matchingFieldsOnly);
|
|
77
|
+
queryParts.push(`( ${userScopeFilter} )`);
|
|
78
|
+
}
|
|
79
|
+
return queryParts.length > 0 ? queryParts.join(" ") : "*";
|
|
125
80
|
};
|
|
81
|
+
//#endregion
|
|
82
|
+
export { REDIS_QUERY_DIALECT, getRulesRedisQuery };
|