@prosopo/user-access-policy 3.12.7 → 3.12.9
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 +40 -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 +36 -39
- 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.d.ts +52 -1
- package/dist/ruleInput/policyInput.d.ts.map +1 -1
- package/dist/ruleInput/policyInput.js +35 -41
- package/dist/ruleInput/policyInput.js.map +1 -1
- package/dist/ruleInput/ruleInput.d.ts.map +1 -1
- package/dist/ruleInput/ruleInput.js +36 -44
- package/dist/ruleInput/ruleInput.js.map +1 -1
- package/dist/ruleInput/userScopeInput.js +44 -55
- package/dist/ruleRecord.js +17 -27
- package/dist/rulesStorage.js +9 -8
- package/dist/tests/policyInput.unit.test.js +50 -1
- package/dist/tests/policyInput.unit.test.js.map +1 -1
- package/dist/tests/redis/redisRulesStorage.integration.test.js +22 -3
- package/dist/tests/redis/redisRulesStorage.integration.test.js.map +1 -1
- package/dist/transformRule.js +34 -73
- package/dist/transformRule.js.map +1 -1
- package/entries.ts +25 -6
- package/package.json +13 -12
- package/src/ruleInput/policyInput.ts +45 -2
- package/src/ruleInput/ruleInput.ts +10 -3
- package/src/tests/policyInput.unit.test.ts +69 -1
- package/src/tests/redis/redisRulesStorage.integration.test.ts +191 -148
- package/src/transformRule.ts +2 -2
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,44 +1,36 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { z } from "zod";
|
|
1
|
+
import "../../_virtual/_rolldown/runtime.js";
|
|
3
2
|
import { ruleEntryInput } from "../../ruleInput/ruleInput.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
data: {
|
|
36
|
-
ruleEntries
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
export {
|
|
42
|
-
FetchRulesEndpoint,
|
|
43
|
-
fetchRulesResponse
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { ApiEndpointResponseStatus } from "@prosopo/api-route";
|
|
5
|
+
//#region src/api/read/fetchRules.ts
|
|
6
|
+
var fetchRulesResponse = z.object({ ruleEntries: ruleEntryInput.array() });
|
|
7
|
+
var FetchRulesEndpoint = class {
|
|
8
|
+
constructor(accessRulesStorage, logger) {
|
|
9
|
+
this.accessRulesStorage = accessRulesStorage;
|
|
10
|
+
this.logger = logger;
|
|
11
|
+
}
|
|
12
|
+
getRequestArgsSchema() {
|
|
13
|
+
return z.object({ ids: z.string().array() });
|
|
14
|
+
}
|
|
15
|
+
async processRequest(args, logger) {
|
|
16
|
+
const log = logger ?? this.logger;
|
|
17
|
+
const ruleEntries = await this.accessRulesStorage.fetchRules(args.ids);
|
|
18
|
+
log.info(() => ({
|
|
19
|
+
msg: "Endpoint fetched rules",
|
|
20
|
+
data: {
|
|
21
|
+
requestedCount: args.ids.length,
|
|
22
|
+
foundCount: ruleEntries.length
|
|
23
|
+
}
|
|
24
|
+
}));
|
|
25
|
+
log.debug(() => ({
|
|
26
|
+
msg: "Fetched rule details",
|
|
27
|
+
data: { ruleEntries }
|
|
28
|
+
}));
|
|
29
|
+
return {
|
|
30
|
+
status: ApiEndpointResponseStatus.SUCCESS,
|
|
31
|
+
data: { ruleEntries }
|
|
32
|
+
};
|
|
33
|
+
}
|
|
44
34
|
};
|
|
35
|
+
//#endregion
|
|
36
|
+
export { FetchRulesEndpoint, fetchRulesResponse };
|
|
@@ -1,51 +1,38 @@
|
|
|
1
|
+
import "../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { accessRulesFilterInput, getAccessRuleFiltersFromInput } from "../../ruleInput/ruleInput.js";
|
|
3
|
+
import { z } from "zod";
|
|
1
4
|
import { ApiEndpointResponseStatus } from "@prosopo/api-route";
|
|
2
5
|
import { executeBatchesSequentially } from "@prosopo/common";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
data: {
|
|
34
|
-
totalFoundCount: ruleIds.length,
|
|
35
|
-
uniqueFoundCount: uniqueRuleIds.length,
|
|
36
|
-
searchFilters: args,
|
|
37
|
-
foundIds: uniqueRuleIds
|
|
38
|
-
}
|
|
39
|
-
}));
|
|
40
|
-
return {
|
|
41
|
-
status: ApiEndpointResponseStatus.SUCCESS,
|
|
42
|
-
data: {
|
|
43
|
-
ruleIds: uniqueRuleIds
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
export {
|
|
49
|
-
FindRuleIdsEndpoint,
|
|
50
|
-
ruleIdsResponse
|
|
6
|
+
//#region src/api/read/findRuleIds.ts
|
|
7
|
+
var ruleIdsResponse = z.object({ ruleIds: z.string().array() });
|
|
8
|
+
var FindRuleIdsEndpoint = class {
|
|
9
|
+
constructor(accessRulesStorage, logger) {
|
|
10
|
+
this.accessRulesStorage = accessRulesStorage;
|
|
11
|
+
this.logger = logger;
|
|
12
|
+
}
|
|
13
|
+
getRequestArgsSchema() {
|
|
14
|
+
return z.array(accessRulesFilterInput);
|
|
15
|
+
}
|
|
16
|
+
async processRequest(args, logger) {
|
|
17
|
+
const log = logger ?? this.logger;
|
|
18
|
+
const ruleIds = (await executeBatchesSequentially(args, async (rulesFilterInput) => {
|
|
19
|
+
return (await executeBatchesSequentially(getAccessRuleFiltersFromInput(rulesFilterInput), (ruleFilter) => this.accessRulesStorage.findRuleIds(ruleFilter))).flat();
|
|
20
|
+
})).flat();
|
|
21
|
+
const uniqueRuleIds = [...new Set(ruleIds)];
|
|
22
|
+
log.info(() => ({
|
|
23
|
+
msg: "Endpoint found rules",
|
|
24
|
+
data: {
|
|
25
|
+
totalFoundCount: ruleIds.length,
|
|
26
|
+
uniqueFoundCount: uniqueRuleIds.length,
|
|
27
|
+
searchFilters: args,
|
|
28
|
+
foundIds: uniqueRuleIds
|
|
29
|
+
}
|
|
30
|
+
}));
|
|
31
|
+
return {
|
|
32
|
+
status: ApiEndpointResponseStatus.SUCCESS,
|
|
33
|
+
data: { ruleIds: uniqueRuleIds }
|
|
34
|
+
};
|
|
35
|
+
}
|
|
51
36
|
};
|
|
37
|
+
//#endregion
|
|
38
|
+
export { FindRuleIdsEndpoint, ruleIdsResponse };
|
|
@@ -1,42 +1,38 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "../../_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
export {
|
|
40
|
-
GetMissingIdsEndpoint,
|
|
41
|
-
missingIdsResponse
|
|
3
|
+
import { ApiEndpointResponseStatus } from "@prosopo/api-route";
|
|
4
|
+
//#region src/api/read/getMissingIds.ts
|
|
5
|
+
var missingIdsResponse = z.object({ ids: z.string().array() });
|
|
6
|
+
var GetMissingIdsEndpoint = class {
|
|
7
|
+
constructor(accessRulesStorage, logger) {
|
|
8
|
+
this.accessRulesStorage = accessRulesStorage;
|
|
9
|
+
this.logger = logger;
|
|
10
|
+
}
|
|
11
|
+
getRequestArgsSchema() {
|
|
12
|
+
return z.string().array();
|
|
13
|
+
}
|
|
14
|
+
async processRequest(args, logger) {
|
|
15
|
+
const log = logger ?? this.logger;
|
|
16
|
+
const missingIds = await this.accessRulesStorage.getMissingRuleIds(args);
|
|
17
|
+
log.info(() => ({
|
|
18
|
+
msg: "Endpoint checked missing ids",
|
|
19
|
+
data: {
|
|
20
|
+
idsToCheck: args.length,
|
|
21
|
+
missingIds: missingIds.length
|
|
22
|
+
}
|
|
23
|
+
}));
|
|
24
|
+
log.debug(() => ({
|
|
25
|
+
msg: "Missing id details",
|
|
26
|
+
data: {
|
|
27
|
+
idsToCheck: args,
|
|
28
|
+
missingIds
|
|
29
|
+
}
|
|
30
|
+
}));
|
|
31
|
+
return {
|
|
32
|
+
status: ApiEndpointResponseStatus.SUCCESS,
|
|
33
|
+
data: { ids: missingIds }
|
|
34
|
+
};
|
|
35
|
+
}
|
|
42
36
|
};
|
|
37
|
+
//#endregion
|
|
38
|
+
export { GetMissingIdsEndpoint, missingIdsResponse };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import "../_virtual/_rolldown/runtime.js";
|
|
1
2
|
import { FetchRulesEndpoint } from "./read/fetchRules.js";
|
|
2
3
|
import { FindRuleIdsEndpoint } from "./read/findRuleIds.js";
|
|
3
4
|
import { GetMissingIdsEndpoint } from "./read/getMissingIds.js";
|
|
@@ -6,126 +7,67 @@ import { DeleteAllRulesEndpoint } from "./delete/deleteAllRules.js";
|
|
|
6
7
|
import { DeleteRuleGroupsEndpoint } from "./delete/deleteRuleGroups.js";
|
|
7
8
|
import { DeleteRulesEndpoint } from "./delete/deleteRules.js";
|
|
8
9
|
import { InsertRulesEndpoint } from "./write/insertRules.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
this.logger
|
|
54
|
-
)
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
makeReadEndpoints() {
|
|
58
|
-
return {
|
|
59
|
-
[
|
|
60
|
-
"/v1/prosopo/user-access-policy/rules/fetch-many"
|
|
61
|
-
/* FETCH_MANY */
|
|
62
|
-
]: new FetchRulesEndpoint(
|
|
63
|
-
this.accessRulesStorage,
|
|
64
|
-
this.logger
|
|
65
|
-
),
|
|
66
|
-
[
|
|
67
|
-
"/v1/prosopo/user-access-policy/rules/find-ids"
|
|
68
|
-
/* FIND_IDS */
|
|
69
|
-
]: new FindRuleIdsEndpoint(
|
|
70
|
-
this.accessRulesStorage,
|
|
71
|
-
this.logger
|
|
72
|
-
),
|
|
73
|
-
[
|
|
74
|
-
"/v1/prosopo/user-access-policy/rules/get-missing-ids"
|
|
75
|
-
/* GET_MISSING_IDS */
|
|
76
|
-
]: new GetMissingIdsEndpoint(
|
|
77
|
-
this.accessRulesStorage,
|
|
78
|
-
this.logger
|
|
79
|
-
)
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
makeWriteEndpoints() {
|
|
83
|
-
return {
|
|
84
|
-
[
|
|
85
|
-
"/v1/prosopo/user-access-policy/rules/insert-many"
|
|
86
|
-
/* INSERT_MANY */
|
|
87
|
-
]: new InsertRulesEndpoint(
|
|
88
|
-
this.accessRulesStorage,
|
|
89
|
-
this.logger
|
|
90
|
-
),
|
|
91
|
-
[
|
|
92
|
-
"/v1/prosopo/user-access-policy/rules/rehash-all"
|
|
93
|
-
/* REHASH_ALL */
|
|
94
|
-
]: new RehashRulesEndpoint(
|
|
95
|
-
this.accessRulesStorage,
|
|
96
|
-
this.logger
|
|
97
|
-
)
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
const getExpressApiRuleRateLimits = () => {
|
|
102
|
-
const defaults = {
|
|
103
|
-
limit: 5,
|
|
104
|
-
windowSeconds: 10
|
|
105
|
-
};
|
|
106
|
-
const defaultWindowMs = defaults.windowSeconds * 1e3;
|
|
107
|
-
const rateLimitEntries = Object.entries(accessRuleApiPaths).map(
|
|
108
|
-
([endpointName, endpointPath]) => [
|
|
109
|
-
endpointPath,
|
|
110
|
-
{
|
|
111
|
-
windowMs: getIntEnvironmentVariable(
|
|
112
|
-
`PROSOPO_USER_ACCESS_POLICY_RULE_${endpointName}_WINDOW`
|
|
113
|
-
) || defaultWindowMs,
|
|
114
|
-
limit: getIntEnvironmentVariable(
|
|
115
|
-
`PROSOPO_USER_ACCESS_POLICY_RULE_${endpointName}_LIMIT`
|
|
116
|
-
) || defaults.limit
|
|
117
|
-
}
|
|
118
|
-
]
|
|
119
|
-
);
|
|
120
|
-
return Object.fromEntries(rateLimitEntries);
|
|
10
|
+
//#region src/api/ruleApiRoutes.ts
|
|
11
|
+
var accessRuleApiPaths = /* @__PURE__ */ function(accessRuleApiPaths) {
|
|
12
|
+
accessRuleApiPaths["DELETE_ALL"] = "/v1/prosopo/user-access-policy/rules/delete-all";
|
|
13
|
+
accessRuleApiPaths["DELETE_GROUPS"] = "/v1/prosopo/user-access-policy/rules/delete-groups";
|
|
14
|
+
accessRuleApiPaths["DELETE_MANY"] = "/v1/prosopo/user-access-policy/rules/delete-many";
|
|
15
|
+
accessRuleApiPaths["FETCH_MANY"] = "/v1/prosopo/user-access-policy/rules/fetch-many";
|
|
16
|
+
accessRuleApiPaths["FIND_IDS"] = "/v1/prosopo/user-access-policy/rules/find-ids";
|
|
17
|
+
accessRuleApiPaths["GET_MISSING_IDS"] = "/v1/prosopo/user-access-policy/rules/get-missing-ids";
|
|
18
|
+
accessRuleApiPaths["INSERT_MANY"] = "/v1/prosopo/user-access-policy/rules/insert-many";
|
|
19
|
+
accessRuleApiPaths["REHASH_ALL"] = "/v1/prosopo/user-access-policy/rules/rehash-all";
|
|
20
|
+
return accessRuleApiPaths;
|
|
21
|
+
}({});
|
|
22
|
+
var AccessRuleApiRoutes = class {
|
|
23
|
+
constructor(accessRulesStorage, logger) {
|
|
24
|
+
this.accessRulesStorage = accessRulesStorage;
|
|
25
|
+
this.logger = logger;
|
|
26
|
+
}
|
|
27
|
+
getRoutes() {
|
|
28
|
+
return {
|
|
29
|
+
...this.makeDeleteEndpoints(),
|
|
30
|
+
...this.makeReadEndpoints(),
|
|
31
|
+
...this.makeWriteEndpoints()
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
makeDeleteEndpoints() {
|
|
35
|
+
return {
|
|
36
|
+
["/v1/prosopo/user-access-policy/rules/delete-all"]: new DeleteAllRulesEndpoint(this.accessRulesStorage, this.logger),
|
|
37
|
+
["/v1/prosopo/user-access-policy/rules/delete-groups"]: new DeleteRuleGroupsEndpoint(this.accessRulesStorage, this.logger),
|
|
38
|
+
["/v1/prosopo/user-access-policy/rules/delete-many"]: new DeleteRulesEndpoint(this.accessRulesStorage, this.logger)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
makeReadEndpoints() {
|
|
42
|
+
return {
|
|
43
|
+
["/v1/prosopo/user-access-policy/rules/fetch-many"]: new FetchRulesEndpoint(this.accessRulesStorage, this.logger),
|
|
44
|
+
["/v1/prosopo/user-access-policy/rules/find-ids"]: new FindRuleIdsEndpoint(this.accessRulesStorage, this.logger),
|
|
45
|
+
["/v1/prosopo/user-access-policy/rules/get-missing-ids"]: new GetMissingIdsEndpoint(this.accessRulesStorage, this.logger)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
makeWriteEndpoints() {
|
|
49
|
+
return {
|
|
50
|
+
["/v1/prosopo/user-access-policy/rules/insert-many"]: new InsertRulesEndpoint(this.accessRulesStorage, this.logger),
|
|
51
|
+
["/v1/prosopo/user-access-policy/rules/rehash-all"]: new RehashRulesEndpoint(this.accessRulesStorage, this.logger)
|
|
52
|
+
};
|
|
53
|
+
}
|
|
121
54
|
};
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
55
|
+
var getExpressApiRuleRateLimits = () => {
|
|
56
|
+
const defaults = {
|
|
57
|
+
limit: 5,
|
|
58
|
+
windowSeconds: 10
|
|
59
|
+
};
|
|
60
|
+
const defaultWindowMs = defaults.windowSeconds * 1e3;
|
|
61
|
+
const rateLimitEntries = Object.entries(accessRuleApiPaths).map(([endpointName, endpointPath]) => [endpointPath, {
|
|
62
|
+
windowMs: getIntEnvironmentVariable(`PROSOPO_USER_ACCESS_POLICY_RULE_${endpointName}_WINDOW`) || defaultWindowMs,
|
|
63
|
+
limit: getIntEnvironmentVariable(`PROSOPO_USER_ACCESS_POLICY_RULE_${endpointName}_LIMIT`) || defaults.limit
|
|
64
|
+
}]);
|
|
65
|
+
return Object.fromEntries(rateLimitEntries);
|
|
126
66
|
};
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
67
|
+
var getIntEnvironmentVariable = (variableName) => {
|
|
68
|
+
const variableValue = process.env[variableName];
|
|
69
|
+
const numericValue = variableValue ? Number.parseInt(variableValue) : NaN;
|
|
70
|
+
return Number.isInteger(numericValue) ? numericValue : void 0;
|
|
131
71
|
};
|
|
72
|
+
//#endregion
|
|
73
|
+
export { AccessRuleApiRoutes, accessRuleApiPaths, getExpressApiRuleRateLimits };
|
|
@@ -1,92 +1,56 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "../_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { fetchRulesResponse } from "./read/fetchRules.js";
|
|
3
3
|
import { ruleIdsResponse } from "./read/findRuleIds.js";
|
|
4
4
|
import { missingIdsResponse } from "./read/getMissingIds.js";
|
|
5
5
|
import { accessRuleApiPaths } from "./ruleApiRoutes.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
async findIds(filters, jwt) {
|
|
55
|
-
const endpointResponse = await this.post(
|
|
56
|
-
accessRuleApiPaths.FIND_IDS,
|
|
57
|
-
filters,
|
|
58
|
-
this.getAuthHeaders(jwt)
|
|
59
|
-
);
|
|
60
|
-
const parsedData = ruleIdsResponse.safeParse(endpointResponse.data);
|
|
61
|
-
return {
|
|
62
|
-
...endpointResponse,
|
|
63
|
-
data: parsedData.success ? parsedData.data : void 0
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
//// write
|
|
67
|
-
async rehashAll(jwt) {
|
|
68
|
-
return this.post(
|
|
69
|
-
accessRuleApiPaths.REHASH_ALL,
|
|
70
|
-
{},
|
|
71
|
-
this.getAuthHeaders(jwt)
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
insertMany(ruleGroups, jwt) {
|
|
75
|
-
return this.post(
|
|
76
|
-
accessRuleApiPaths.INSERT_MANY,
|
|
77
|
-
ruleGroups,
|
|
78
|
-
this.getAuthHeaders(jwt)
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
getAuthHeaders(jwt) {
|
|
82
|
-
return {
|
|
83
|
-
headers: {
|
|
84
|
-
"Prosopo-Site-Key": this.account,
|
|
85
|
-
Authorization: `Bearer ${jwt}`
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
export {
|
|
91
|
-
AccessRulesApiClient
|
|
6
|
+
import { ApiClient } from "@prosopo/api";
|
|
7
|
+
//#region src/api/rulesApiClient.ts
|
|
8
|
+
var AccessRulesApiClient = class extends ApiClient {
|
|
9
|
+
deleteMany(filters, jwt) {
|
|
10
|
+
return this.post(accessRuleApiPaths.DELETE_MANY, filters, this.getAuthHeaders(jwt));
|
|
11
|
+
}
|
|
12
|
+
deleteGroups(siteGroups, jwt) {
|
|
13
|
+
return this.post(accessRuleApiPaths.DELETE_GROUPS, siteGroups, this.getAuthHeaders(jwt));
|
|
14
|
+
}
|
|
15
|
+
deleteAll(jwt) {
|
|
16
|
+
return this.post(accessRuleApiPaths.DELETE_ALL, {}, this.getAuthHeaders(jwt));
|
|
17
|
+
}
|
|
18
|
+
async getMissingIds(idsToCheck, jwt) {
|
|
19
|
+
const endpointResponse = await this.post(accessRuleApiPaths.GET_MISSING_IDS, idsToCheck, this.getAuthHeaders(jwt));
|
|
20
|
+
const parsedData = missingIdsResponse.safeParse(endpointResponse.data);
|
|
21
|
+
return {
|
|
22
|
+
...endpointResponse,
|
|
23
|
+
data: parsedData.success ? parsedData.data : void 0
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
async fetchMany(fetchOptions, jwt) {
|
|
27
|
+
const endpointResponse = await this.post(accessRuleApiPaths.FETCH_MANY, fetchOptions, this.getAuthHeaders(jwt));
|
|
28
|
+
const parsedData = fetchRulesResponse.safeParse(endpointResponse.data);
|
|
29
|
+
return {
|
|
30
|
+
...endpointResponse,
|
|
31
|
+
data: parsedData.success ? parsedData.data : void 0
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
async findIds(filters, jwt) {
|
|
35
|
+
const endpointResponse = await this.post(accessRuleApiPaths.FIND_IDS, filters, this.getAuthHeaders(jwt));
|
|
36
|
+
const parsedData = ruleIdsResponse.safeParse(endpointResponse.data);
|
|
37
|
+
return {
|
|
38
|
+
...endpointResponse,
|
|
39
|
+
data: parsedData.success ? parsedData.data : void 0
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async rehashAll(jwt) {
|
|
43
|
+
return this.post(accessRuleApiPaths.REHASH_ALL, {}, this.getAuthHeaders(jwt));
|
|
44
|
+
}
|
|
45
|
+
insertMany(ruleGroups, jwt) {
|
|
46
|
+
return this.post(accessRuleApiPaths.INSERT_MANY, ruleGroups, this.getAuthHeaders(jwt));
|
|
47
|
+
}
|
|
48
|
+
getAuthHeaders(jwt) {
|
|
49
|
+
return { headers: {
|
|
50
|
+
"Prosopo-Site-Key": this.account,
|
|
51
|
+
Authorization: `Bearer ${jwt}`
|
|
52
|
+
} };
|
|
53
|
+
}
|
|
92
54
|
};
|
|
55
|
+
//#endregion
|
|
56
|
+
export { AccessRulesApiClient };
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import "../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
export {};
|