@prosopo/user-access-policy 3.5.19 → 3.5.28
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/CHANGELOG.md +84 -0
- package/dist/.export.js +21 -0
- package/dist/api/.export.js +11 -0
- package/dist/api/delete/.export.js +1 -0
- package/dist/api/{deleteAllRulesEndpoint.js → delete/deleteAllRules.js} +10 -9
- package/dist/api/delete/deleteRuleGroups.js +52 -0
- package/dist/api/delete/deleteRules.js +43 -0
- package/dist/api/read/.export.js +1 -0
- package/dist/api/read/fetchRules.js +43 -0
- package/dist/api/read/findRuleIds.js +50 -0
- package/dist/api/read/getMissingIds.js +41 -0
- package/dist/api/ruleApiRoutes.js +131 -0
- package/dist/api/rulesApiClient.js +93 -0
- package/dist/api/write/.export.js +1 -0
- package/dist/api/write/insertRules.js +102 -0
- package/dist/api/write/rehashRules.js +57 -0
- package/dist/cjs/.export.cjs +21 -0
- package/dist/cjs/api/.export.cjs +11 -0
- package/dist/cjs/api/delete/.export.cjs +1 -0
- package/dist/cjs/api/{deleteAllRulesEndpoint.cjs → delete/deleteAllRules.cjs} +9 -8
- package/dist/cjs/api/delete/deleteRuleGroups.cjs +52 -0
- package/dist/cjs/api/delete/deleteRules.cjs +43 -0
- package/dist/cjs/api/read/.export.cjs +1 -0
- package/dist/cjs/api/read/fetchRules.cjs +43 -0
- package/dist/cjs/api/read/findRuleIds.cjs +50 -0
- package/dist/cjs/api/read/getMissingIds.cjs +41 -0
- package/dist/cjs/api/ruleApiRoutes.cjs +131 -0
- package/dist/cjs/api/rulesApiClient.cjs +93 -0
- package/dist/cjs/api/write/.export.cjs +1 -0
- package/dist/cjs/api/write/insertRules.cjs +102 -0
- package/dist/cjs/api/write/rehashRules.cjs +57 -0
- package/dist/cjs/mongoose/.export.cjs +4 -0
- package/dist/cjs/mongoose/mongooseRuleSchema.cjs +36 -0
- package/dist/cjs/redis/.export.cjs +6 -0
- package/dist/cjs/redis/reader/redisAggregate.cjs +60 -0
- package/dist/cjs/redis/reader/redisRulesQuery.cjs +99 -0
- package/dist/cjs/redis/reader/redisRulesReader.cjs +230 -0
- package/dist/cjs/redis/redisClient.cjs +67 -0
- package/dist/cjs/redis/redisRuleIndex.cjs +50 -0
- package/dist/cjs/redis/redisRulesStorage.cjs +22 -9
- package/dist/cjs/redis/redisRulesWriter.cjs +91 -64
- package/dist/cjs/rule.cjs +8 -0
- package/dist/cjs/ruleInput/.export.cjs +9 -0
- package/dist/cjs/ruleInput/policyInput.cjs +25 -0
- package/dist/cjs/ruleInput/ruleInput.cjs +50 -0
- package/dist/cjs/ruleInput/userScopeInput.cjs +55 -0
- package/dist/cjs/ruleRecord.cjs +23 -0
- package/dist/cjs/rulesStorage.cjs +8 -0
- package/dist/cjs/transformRule.cjs +77 -0
- package/dist/mongoose/.export.js +4 -0
- package/dist/mongoose/mongooseRuleSchema.js +36 -0
- package/dist/redis/.export.js +6 -0
- package/dist/redis/reader/redisAggregate.js +60 -0
- package/dist/redis/reader/redisRulesQuery.js +99 -0
- package/dist/redis/reader/redisRulesReader.js +213 -0
- package/dist/redis/redisClient.js +67 -0
- package/dist/redis/redisRuleIndex.js +50 -0
- package/dist/redis/redisRulesStorage.js +23 -10
- package/dist/redis/redisRulesWriter.js +91 -64
- package/dist/rule.js +8 -0
- package/dist/ruleInput/.export.js +9 -0
- package/dist/ruleInput/policyInput.js +25 -0
- package/dist/ruleInput/ruleInput.js +50 -0
- package/dist/ruleInput/userScopeInput.js +55 -0
- package/dist/ruleRecord.js +23 -0
- package/dist/rulesStorage.js +8 -0
- package/dist/transformRule.js +77 -0
- package/entries.ts +20 -0
- package/package.json +34 -18
- package/vite.cjs.config.ts +4 -1
- package/vite.esm.config.ts +6 -1
- package/dist/accessPolicy.js +0 -80
- package/dist/accessPolicyResolver.js +0 -31
- package/dist/accessRules.js +0 -11
- package/dist/api/accessRuleApiRoutes.js +0 -79
- package/dist/api/accessRulesApiClient.js +0 -38
- package/dist/api/deleteRulesEndpoint.js +0 -34
- package/dist/api/insertRulesEndpoint.js +0 -62
- package/dist/cjs/accessPolicy.cjs +0 -80
- package/dist/cjs/accessPolicyResolver.cjs +0 -31
- package/dist/cjs/accessRules.cjs +0 -11
- package/dist/cjs/api/accessRuleApiRoutes.cjs +0 -79
- package/dist/cjs/api/accessRulesApiClient.cjs +0 -38
- package/dist/cjs/api/deleteRulesEndpoint.cjs +0 -34
- package/dist/cjs/api/insertRulesEndpoint.cjs +0 -62
- package/dist/cjs/index.cjs +0 -31
- package/dist/cjs/redis/redisRulesIndex.cjs +0 -138
- package/dist/cjs/redis/redisRulesReader.cjs +0 -142
- package/dist/cjs/util.cjs +0 -5
- package/dist/index.js +0 -32
- package/dist/redis/redisRulesIndex.js +0 -138
- package/dist/redis/redisRulesReader.js +0 -125
- package/dist/util.js +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,89 @@
|
|
|
1
1
|
# @prosopo/user-access-policy
|
|
2
2
|
|
|
3
|
+
## 3.5.28
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
- 8ce9205: enhance/uap-rules-push
|
|
7
|
+
- 8ce9205: Change engine requirements
|
|
8
|
+
- b6e98b2: Run npm audit
|
|
9
|
+
- Updated dependencies [15ae7cf]
|
|
10
|
+
- Updated dependencies [bb5f41c]
|
|
11
|
+
- Updated dependencies [8ce9205]
|
|
12
|
+
- Updated dependencies [b6e98b2]
|
|
13
|
+
- @prosopo/types@3.6.0
|
|
14
|
+
- @prosopo/util@3.2.0
|
|
15
|
+
- @prosopo/redis-client@1.0.7
|
|
16
|
+
- @prosopo/api-route@2.6.30
|
|
17
|
+
- @prosopo/common@3.1.22
|
|
18
|
+
- @prosopo/api@3.1.33
|
|
19
|
+
|
|
20
|
+
## 3.5.27
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- Updated dependencies [8f1773a]
|
|
24
|
+
- @prosopo/types@3.5.11
|
|
25
|
+
- @prosopo/api@3.1.32
|
|
26
|
+
|
|
27
|
+
## 3.5.26
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- Updated dependencies [cb8ab85]
|
|
31
|
+
- @prosopo/types@3.5.10
|
|
32
|
+
- @prosopo/api@3.1.31
|
|
33
|
+
|
|
34
|
+
## 3.5.25
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- 005ce66: Split load balancer into URL fn and getter fn for private repo
|
|
38
|
+
- Updated dependencies [43907e8]
|
|
39
|
+
- Updated dependencies [005ce66]
|
|
40
|
+
- Updated dependencies [7101036]
|
|
41
|
+
- @prosopo/types@3.5.9
|
|
42
|
+
- @prosopo/util@3.1.7
|
|
43
|
+
- @prosopo/api@3.1.30
|
|
44
|
+
|
|
45
|
+
## 3.5.24
|
|
46
|
+
### Patch Changes
|
|
47
|
+
|
|
48
|
+
- Updated dependencies [e5c259d]
|
|
49
|
+
- @prosopo/types@3.5.8
|
|
50
|
+
- @prosopo/api@3.1.29
|
|
51
|
+
|
|
52
|
+
## 3.5.23
|
|
53
|
+
### Patch Changes
|
|
54
|
+
|
|
55
|
+
- c9d8fdf: feat/access-policy-group
|
|
56
|
+
- b8185a4: feat/uap-rules-syncer
|
|
57
|
+
- Updated dependencies [c9d8fdf]
|
|
58
|
+
- Updated dependencies [b8185a4]
|
|
59
|
+
- @prosopo/api@3.1.28
|
|
60
|
+
- @prosopo/common@3.1.21
|
|
61
|
+
- @prosopo/api-route@2.6.29
|
|
62
|
+
- @prosopo/redis-client@1.0.6
|
|
63
|
+
- @prosopo/types@3.5.7
|
|
64
|
+
- @prosopo/util@3.1.6
|
|
65
|
+
|
|
66
|
+
## 3.5.22
|
|
67
|
+
### Patch Changes
|
|
68
|
+
|
|
69
|
+
- Updated dependencies [5d11a81]
|
|
70
|
+
- @prosopo/types@3.5.6
|
|
71
|
+
- @prosopo/api@3.1.27
|
|
72
|
+
|
|
73
|
+
## 3.5.21
|
|
74
|
+
### Patch Changes
|
|
75
|
+
|
|
76
|
+
- Updated dependencies [494c5a8]
|
|
77
|
+
- @prosopo/types@3.5.5
|
|
78
|
+
- @prosopo/api@3.1.26
|
|
79
|
+
|
|
80
|
+
## 3.5.20
|
|
81
|
+
### Patch Changes
|
|
82
|
+
|
|
83
|
+
- Updated dependencies [08ff50f]
|
|
84
|
+
- @prosopo/types@3.5.4
|
|
85
|
+
- @prosopo/api@3.1.25
|
|
86
|
+
|
|
3
87
|
## 3.5.19
|
|
4
88
|
### Patch Changes
|
|
5
89
|
|
package/dist/.export.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import "./ruleInput/.export.js";
|
|
2
|
+
import { makeAccessRuleHash, transformAccessRuleIntoRecord, transformAccessRuleRecordIntoRule } from "./transformRule.js";
|
|
3
|
+
import { AccessPolicyType } from "./rule.js";
|
|
4
|
+
import { FilterScopeMatch } from "./rulesStorage.js";
|
|
5
|
+
import { getUserScopeRecordFromAccessRuleRecord, userScopeRecordFields } from "./ruleRecord.js";
|
|
6
|
+
import { accessRuleInput } from "./ruleInput/ruleInput.js";
|
|
7
|
+
import { accessPolicyInput, policyScopeInput } from "./ruleInput/policyInput.js";
|
|
8
|
+
import { userScopeInput } from "./ruleInput/userScopeInput.js";
|
|
9
|
+
export {
|
|
10
|
+
AccessPolicyType,
|
|
11
|
+
FilterScopeMatch,
|
|
12
|
+
accessPolicyInput,
|
|
13
|
+
accessRuleInput,
|
|
14
|
+
getUserScopeRecordFromAccessRuleRecord,
|
|
15
|
+
makeAccessRuleHash,
|
|
16
|
+
policyScopeInput,
|
|
17
|
+
transformAccessRuleIntoRecord,
|
|
18
|
+
transformAccessRuleRecordIntoRule,
|
|
19
|
+
userScopeInput,
|
|
20
|
+
userScopeRecordFields
|
|
21
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import "./delete/.export.js";
|
|
2
|
+
import "./read/.export.js";
|
|
3
|
+
import "./write/.export.js";
|
|
4
|
+
import { AccessRuleApiRoutes, accessRuleApiPaths, getExpressApiRuleRateLimits } from "./ruleApiRoutes.js";
|
|
5
|
+
import { AccessRulesApiClient } from "./rulesApiClient.js";
|
|
6
|
+
export {
|
|
7
|
+
AccessRuleApiRoutes,
|
|
8
|
+
AccessRulesApiClient,
|
|
9
|
+
accessRuleApiPaths,
|
|
10
|
+
getExpressApiRuleRateLimits
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { ApiEndpointResponseStatus } from "@prosopo/api-route";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
const deleteAllRulesEndpointSchema = z.object({});
|
|
4
2
|
class DeleteAllRulesEndpoint {
|
|
5
|
-
constructor(accessRulesStorage) {
|
|
3
|
+
constructor(accessRulesStorage, logger) {
|
|
6
4
|
this.accessRulesStorage = accessRulesStorage;
|
|
5
|
+
this.logger = logger;
|
|
7
6
|
}
|
|
8
|
-
|
|
7
|
+
getRequestArgsSchema() {
|
|
8
|
+
}
|
|
9
|
+
async processRequest() {
|
|
9
10
|
const deletedCount = await this.accessRulesStorage.deleteAllRules();
|
|
11
|
+
this.logger.info(() => ({
|
|
12
|
+
msg: "Endpoint deleted all access rules",
|
|
13
|
+
data: { deletedCount }
|
|
14
|
+
}));
|
|
10
15
|
return {
|
|
11
16
|
status: ApiEndpointResponseStatus.SUCCESS,
|
|
12
17
|
data: {
|
|
@@ -14,11 +19,7 @@ class DeleteAllRulesEndpoint {
|
|
|
14
19
|
}
|
|
15
20
|
};
|
|
16
21
|
}
|
|
17
|
-
getRequestArgsSchema() {
|
|
18
|
-
return deleteAllRulesEndpointSchema;
|
|
19
|
-
}
|
|
20
22
|
}
|
|
21
23
|
export {
|
|
22
|
-
DeleteAllRulesEndpoint
|
|
23
|
-
deleteAllRulesEndpointSchema
|
|
24
|
+
DeleteAllRulesEndpoint
|
|
24
25
|
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ApiEndpointResponseStatus } from "@prosopo/api-route";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { FilterScopeMatch } from "../../rulesStorage.js";
|
|
4
|
+
class DeleteRuleGroupsEndpoint {
|
|
5
|
+
constructor(accessRulesStorage, logger) {
|
|
6
|
+
this.accessRulesStorage = accessRulesStorage;
|
|
7
|
+
this.logger = logger;
|
|
8
|
+
}
|
|
9
|
+
getRequestArgsSchema() {
|
|
10
|
+
return z.array(
|
|
11
|
+
z.object({
|
|
12
|
+
clientIds: z.string().array(),
|
|
13
|
+
groupId: z.string()
|
|
14
|
+
})
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
async processRequest(args) {
|
|
18
|
+
const foundRuleIdPromises = args.flatMap(
|
|
19
|
+
(ruleToDelete) => ruleToDelete.clientIds.map(
|
|
20
|
+
(clientId) => this.accessRulesStorage.findRuleIds({
|
|
21
|
+
policyScope: {
|
|
22
|
+
clientId
|
|
23
|
+
},
|
|
24
|
+
policyScopeMatch: FilterScopeMatch.Exact,
|
|
25
|
+
groupId: ruleToDelete.groupId
|
|
26
|
+
})
|
|
27
|
+
)
|
|
28
|
+
);
|
|
29
|
+
const foundRuleIds = await Promise.all(foundRuleIdPromises);
|
|
30
|
+
const ruleIds = foundRuleIds.flat();
|
|
31
|
+
const uniqueRuleIds = [...new Set(ruleIds)];
|
|
32
|
+
if (uniqueRuleIds.length > 0) {
|
|
33
|
+
await this.accessRulesStorage.deleteRules(uniqueRuleIds);
|
|
34
|
+
}
|
|
35
|
+
this.logger.info(() => ({
|
|
36
|
+
msg: "Endpoint deleted rule groups",
|
|
37
|
+
data: {
|
|
38
|
+
args,
|
|
39
|
+
uniqueRuleIds
|
|
40
|
+
}
|
|
41
|
+
}));
|
|
42
|
+
return {
|
|
43
|
+
status: ApiEndpointResponseStatus.SUCCESS,
|
|
44
|
+
data: {
|
|
45
|
+
deleted_count: uniqueRuleIds.length
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
DeleteRuleGroupsEndpoint
|
|
52
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ApiEndpointResponseStatus } from "@prosopo/api-route";
|
|
2
|
+
import { executeBatchesSequentially } from "@prosopo/common";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { accessRulesFilterInput, getAccessRuleFiltersFromInput } from "../../ruleInput/ruleInput.js";
|
|
5
|
+
class DeleteRulesEndpoint {
|
|
6
|
+
constructor(accessRulesStorage, logger) {
|
|
7
|
+
this.accessRulesStorage = accessRulesStorage;
|
|
8
|
+
this.logger = logger;
|
|
9
|
+
}
|
|
10
|
+
getRequestArgsSchema() {
|
|
11
|
+
return z.array(accessRulesFilterInput);
|
|
12
|
+
}
|
|
13
|
+
async processRequest(args) {
|
|
14
|
+
let deletedCount = 0;
|
|
15
|
+
for (const rulesFilterInput of args) {
|
|
16
|
+
const ruleFilters = getAccessRuleFiltersFromInput(rulesFilterInput);
|
|
17
|
+
await executeBatchesSequentially(ruleFilters, async (ruleFilter) => {
|
|
18
|
+
const ruleIds = await this.accessRulesStorage.findRuleIds(ruleFilter);
|
|
19
|
+
const uniqueRuleIds = [...new Set(ruleIds)];
|
|
20
|
+
if (uniqueRuleIds.length > 0) {
|
|
21
|
+
await this.accessRulesStorage.deleteRules(uniqueRuleIds);
|
|
22
|
+
deletedCount += uniqueRuleIds.length;
|
|
23
|
+
this.logger.info(() => ({
|
|
24
|
+
msg: "Endpoint deleted rules",
|
|
25
|
+
data: {
|
|
26
|
+
rulesFilterInput,
|
|
27
|
+
uniqueRuleIds
|
|
28
|
+
}
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
status: ApiEndpointResponseStatus.SUCCESS,
|
|
35
|
+
data: {
|
|
36
|
+
deleted_count: deletedCount
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
DeleteRulesEndpoint
|
|
43
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ApiEndpointResponseStatus } from "@prosopo/api-route";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { ruleEntryInput } from "../../ruleInput/ruleInput.js";
|
|
4
|
+
const fetchRulesResponse = z.object({
|
|
5
|
+
ruleEntries: ruleEntryInput.array()
|
|
6
|
+
});
|
|
7
|
+
class FetchRulesEndpoint {
|
|
8
|
+
constructor(accessRulesStorage, logger) {
|
|
9
|
+
this.accessRulesStorage = accessRulesStorage;
|
|
10
|
+
this.logger = logger;
|
|
11
|
+
}
|
|
12
|
+
getRequestArgsSchema() {
|
|
13
|
+
return z.object({
|
|
14
|
+
ids: z.string().array()
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
async processRequest(args) {
|
|
18
|
+
const ruleEntries = await this.accessRulesStorage.fetchRules(args.ids);
|
|
19
|
+
this.logger.info(() => ({
|
|
20
|
+
msg: "Endpoint fetched rules",
|
|
21
|
+
data: {
|
|
22
|
+
requestedCount: args.ids.length,
|
|
23
|
+
foundCount: ruleEntries.length
|
|
24
|
+
}
|
|
25
|
+
}));
|
|
26
|
+
this.logger.debug(() => ({
|
|
27
|
+
msg: "Fetched rule details",
|
|
28
|
+
data: {
|
|
29
|
+
ruleEntries
|
|
30
|
+
}
|
|
31
|
+
}));
|
|
32
|
+
return {
|
|
33
|
+
status: ApiEndpointResponseStatus.SUCCESS,
|
|
34
|
+
data: {
|
|
35
|
+
ruleEntries
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
FetchRulesEndpoint,
|
|
42
|
+
fetchRulesResponse
|
|
43
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ApiEndpointResponseStatus } from "@prosopo/api-route";
|
|
2
|
+
import { executeBatchesSequentially } from "@prosopo/common";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { accessRulesFilterInput, getAccessRuleFiltersFromInput } from "../../ruleInput/ruleInput.js";
|
|
5
|
+
const ruleIdsResponse = z.object({
|
|
6
|
+
ruleIds: z.string().array()
|
|
7
|
+
});
|
|
8
|
+
class FindRuleIdsEndpoint {
|
|
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) {
|
|
17
|
+
const ruleIdBatches = await executeBatchesSequentially(
|
|
18
|
+
args,
|
|
19
|
+
async (rulesFilterInput) => {
|
|
20
|
+
const ruleFilters = getAccessRuleFiltersFromInput(rulesFilterInput);
|
|
21
|
+
const ruleIds2 = await executeBatchesSequentially(
|
|
22
|
+
ruleFilters,
|
|
23
|
+
(ruleFilter) => this.accessRulesStorage.findRuleIds(ruleFilter)
|
|
24
|
+
);
|
|
25
|
+
return ruleIds2.flat();
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
const ruleIds = ruleIdBatches.flat();
|
|
29
|
+
const uniqueRuleIds = [...new Set(ruleIds)];
|
|
30
|
+
this.logger.info(() => ({
|
|
31
|
+
msg: "Endpoint found rules",
|
|
32
|
+
data: {
|
|
33
|
+
totalFoundCount: ruleIds.length,
|
|
34
|
+
uniqueFoundCount: uniqueRuleIds.length,
|
|
35
|
+
searchFilters: args,
|
|
36
|
+
foundIds: uniqueRuleIds
|
|
37
|
+
}
|
|
38
|
+
}));
|
|
39
|
+
return {
|
|
40
|
+
status: ApiEndpointResponseStatus.SUCCESS,
|
|
41
|
+
data: {
|
|
42
|
+
ruleIds: uniqueRuleIds
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
FindRuleIdsEndpoint,
|
|
49
|
+
ruleIdsResponse
|
|
50
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ApiEndpointResponseStatus } from "@prosopo/api-route";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
const missingIdsResponse = z.object({
|
|
4
|
+
ids: z.string().array()
|
|
5
|
+
});
|
|
6
|
+
class GetMissingIdsEndpoint {
|
|
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) {
|
|
15
|
+
const missingIds = await this.accessRulesStorage.getMissingRuleIds(args);
|
|
16
|
+
this.logger.info(() => ({
|
|
17
|
+
msg: "Endpoint checked missing ids",
|
|
18
|
+
data: {
|
|
19
|
+
idsToCheck: args.length,
|
|
20
|
+
missingIds: missingIds.length
|
|
21
|
+
}
|
|
22
|
+
}));
|
|
23
|
+
this.logger.debug(() => ({
|
|
24
|
+
msg: "Missing id details",
|
|
25
|
+
data: {
|
|
26
|
+
idsToCheck: args,
|
|
27
|
+
missingIds
|
|
28
|
+
}
|
|
29
|
+
}));
|
|
30
|
+
return {
|
|
31
|
+
status: ApiEndpointResponseStatus.SUCCESS,
|
|
32
|
+
data: {
|
|
33
|
+
ids: missingIds
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
GetMissingIdsEndpoint,
|
|
40
|
+
missingIdsResponse
|
|
41
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { FetchRulesEndpoint } from "./read/fetchRules.js";
|
|
2
|
+
import { FindRuleIdsEndpoint } from "./read/findRuleIds.js";
|
|
3
|
+
import { GetMissingIdsEndpoint } from "./read/getMissingIds.js";
|
|
4
|
+
import { RehashRulesEndpoint } from "./write/rehashRules.js";
|
|
5
|
+
import { DeleteAllRulesEndpoint } from "./delete/deleteAllRules.js";
|
|
6
|
+
import { DeleteRuleGroupsEndpoint } from "./delete/deleteRuleGroups.js";
|
|
7
|
+
import { DeleteRulesEndpoint } from "./delete/deleteRules.js";
|
|
8
|
+
import { InsertRulesEndpoint } from "./write/insertRules.js";
|
|
9
|
+
var accessRuleApiPaths = /* @__PURE__ */ ((accessRuleApiPaths2) => {
|
|
10
|
+
accessRuleApiPaths2["DELETE_ALL"] = "/v1/prosopo/user-access-policy/rules/delete-all";
|
|
11
|
+
accessRuleApiPaths2["DELETE_GROUPS"] = "/v1/prosopo/user-access-policy/rules/delete-groups";
|
|
12
|
+
accessRuleApiPaths2["DELETE_MANY"] = "/v1/prosopo/user-access-policy/rules/delete-many";
|
|
13
|
+
accessRuleApiPaths2["FETCH_MANY"] = "/v1/prosopo/user-access-policy/rules/fetch-many";
|
|
14
|
+
accessRuleApiPaths2["FIND_IDS"] = "/v1/prosopo/user-access-policy/rules/find-ids";
|
|
15
|
+
accessRuleApiPaths2["GET_MISSING_IDS"] = "/v1/prosopo/user-access-policy/rules/get-missing-ids";
|
|
16
|
+
accessRuleApiPaths2["INSERT_MANY"] = "/v1/prosopo/user-access-policy/rules/insert-many";
|
|
17
|
+
accessRuleApiPaths2["REHASH_ALL"] = "/v1/prosopo/user-access-policy/rules/rehash-all";
|
|
18
|
+
return accessRuleApiPaths2;
|
|
19
|
+
})(accessRuleApiPaths || {});
|
|
20
|
+
class AccessRuleApiRoutes {
|
|
21
|
+
constructor(accessRulesStorage, logger) {
|
|
22
|
+
this.accessRulesStorage = accessRulesStorage;
|
|
23
|
+
this.logger = logger;
|
|
24
|
+
}
|
|
25
|
+
getRoutes() {
|
|
26
|
+
return {
|
|
27
|
+
...this.makeDeleteEndpoints(),
|
|
28
|
+
...this.makeReadEndpoints(),
|
|
29
|
+
...this.makeWriteEndpoints()
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
makeDeleteEndpoints() {
|
|
33
|
+
return {
|
|
34
|
+
[
|
|
35
|
+
"/v1/prosopo/user-access-policy/rules/delete-all"
|
|
36
|
+
/* DELETE_ALL */
|
|
37
|
+
]: new DeleteAllRulesEndpoint(
|
|
38
|
+
this.accessRulesStorage,
|
|
39
|
+
this.logger
|
|
40
|
+
),
|
|
41
|
+
[
|
|
42
|
+
"/v1/prosopo/user-access-policy/rules/delete-groups"
|
|
43
|
+
/* DELETE_GROUPS */
|
|
44
|
+
]: new DeleteRuleGroupsEndpoint(
|
|
45
|
+
this.accessRulesStorage,
|
|
46
|
+
this.logger
|
|
47
|
+
),
|
|
48
|
+
[
|
|
49
|
+
"/v1/prosopo/user-access-policy/rules/delete-many"
|
|
50
|
+
/* DELETE_MANY */
|
|
51
|
+
]: new DeleteRulesEndpoint(
|
|
52
|
+
this.accessRulesStorage,
|
|
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);
|
|
121
|
+
};
|
|
122
|
+
const getIntEnvironmentVariable = (variableName) => {
|
|
123
|
+
const variableValue = process.env[variableName];
|
|
124
|
+
const numericValue = variableValue ? Number.parseInt(variableValue) : Number.NaN;
|
|
125
|
+
return Number.isInteger(numericValue) ? numericValue : void 0;
|
|
126
|
+
};
|
|
127
|
+
export {
|
|
128
|
+
AccessRuleApiRoutes,
|
|
129
|
+
accessRuleApiPaths,
|
|
130
|
+
getExpressApiRuleRateLimits
|
|
131
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { ApiClient } from "@prosopo/api";
|
|
2
|
+
import { fetchRulesResponse } from "./read/fetchRules.js";
|
|
3
|
+
import { ruleIdsResponse } from "./read/findRuleIds.js";
|
|
4
|
+
import { missingIdsResponse } from "./read/getMissingIds.js";
|
|
5
|
+
import { accessRuleApiPaths } from "./ruleApiRoutes.js";
|
|
6
|
+
class AccessRulesApiClient extends ApiClient {
|
|
7
|
+
//// delete
|
|
8
|
+
deleteMany(filters, timestamp, signature) {
|
|
9
|
+
return this.post(
|
|
10
|
+
accessRuleApiPaths.DELETE_MANY,
|
|
11
|
+
filters,
|
|
12
|
+
this.getAuthHeaders(timestamp, signature)
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
deleteGroups(siteGroups, timestamp, signature) {
|
|
16
|
+
return this.post(
|
|
17
|
+
accessRuleApiPaths.DELETE_GROUPS,
|
|
18
|
+
siteGroups,
|
|
19
|
+
this.getAuthHeaders(timestamp, signature)
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
deleteAll(timestamp, signature) {
|
|
23
|
+
return this.post(
|
|
24
|
+
accessRuleApiPaths.DELETE_ALL,
|
|
25
|
+
{},
|
|
26
|
+
this.getAuthHeaders(timestamp, signature)
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
//// read
|
|
30
|
+
async getMissingIds(idsToCheck, timestamp, signature) {
|
|
31
|
+
const endpointResponse = await this.post(
|
|
32
|
+
accessRuleApiPaths.GET_MISSING_IDS,
|
|
33
|
+
idsToCheck,
|
|
34
|
+
this.getAuthHeaders(timestamp, signature)
|
|
35
|
+
);
|
|
36
|
+
const parsedData = missingIdsResponse.safeParse(endpointResponse.data);
|
|
37
|
+
return {
|
|
38
|
+
...endpointResponse,
|
|
39
|
+
data: parsedData.success ? parsedData.data : void 0
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async fetchMany(fetchOptions, timestamp, signature) {
|
|
43
|
+
const endpointResponse = await this.post(
|
|
44
|
+
accessRuleApiPaths.FETCH_MANY,
|
|
45
|
+
fetchOptions,
|
|
46
|
+
this.getAuthHeaders(timestamp, signature)
|
|
47
|
+
);
|
|
48
|
+
const parsedData = fetchRulesResponse.safeParse(endpointResponse.data);
|
|
49
|
+
return {
|
|
50
|
+
...endpointResponse,
|
|
51
|
+
data: parsedData.success ? parsedData.data : void 0
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
async findIds(filters, timestamp, signature) {
|
|
55
|
+
const endpointResponse = await this.post(
|
|
56
|
+
accessRuleApiPaths.FIND_IDS,
|
|
57
|
+
filters,
|
|
58
|
+
this.getAuthHeaders(timestamp, signature)
|
|
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(timestamp, signature) {
|
|
68
|
+
return this.post(
|
|
69
|
+
accessRuleApiPaths.REHASH_ALL,
|
|
70
|
+
{},
|
|
71
|
+
this.getAuthHeaders(timestamp, signature)
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
insertMany(ruleGroups, timestamp, signature) {
|
|
75
|
+
return this.post(
|
|
76
|
+
accessRuleApiPaths.INSERT_MANY,
|
|
77
|
+
ruleGroups,
|
|
78
|
+
this.getAuthHeaders(timestamp, signature)
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
getAuthHeaders(timestamp, signature) {
|
|
82
|
+
return {
|
|
83
|
+
headers: {
|
|
84
|
+
"Prosopo-Site-Key": this.account,
|
|
85
|
+
timestamp,
|
|
86
|
+
signature
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
export {
|
|
92
|
+
AccessRulesApiClient
|
|
93
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|