@prosopo/user-access-policy 3.4.0 → 3.5.27
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 +309 -0
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/clover.xml +786 -0
- package/coverage/coverage-final.json +15 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +146 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +210 -0
- package/coverage/src/accessPolicy.ts.html +457 -0
- package/coverage/src/accessPolicyResolver.ts.html +211 -0
- package/coverage/src/accessRules.ts.html +265 -0
- package/coverage/src/api/accessRuleApiRoutes.ts.html +379 -0
- package/coverage/src/api/accessRulesApiClient.ts.html +274 -0
- package/coverage/src/api/deleteAllRulesEndpoint.ts.html +229 -0
- package/coverage/src/api/deleteRulesEndpoint.ts.html +301 -0
- package/coverage/src/api/index.html +176 -0
- package/coverage/src/api/insertRulesEndpoint.ts.html +436 -0
- package/coverage/src/index.html +176 -0
- package/coverage/src/index.ts.html +277 -0
- package/coverage/src/redis/index.html +161 -0
- package/coverage/src/redis/redisRulesIndex.ts.html +769 -0
- package/coverage/src/redis/redisRulesReader.ts.html +652 -0
- package/coverage/src/redis/redisRulesStorage.ts.html +229 -0
- package/coverage/src/redis/redisRulesWriter.ts.html +424 -0
- package/coverage/src/util.ts.html +136 -0
- package/dist/.export.d.ts +6 -0
- package/dist/.export.d.ts.map +1 -0
- package/dist/.export.js +21 -0
- package/dist/.export.js.map +1 -0
- package/dist/accessPolicy.d.ts +169 -0
- package/dist/accessPolicy.d.ts.map +1 -0
- package/dist/accessPolicy.js.map +1 -0
- package/dist/accessPolicyResolver.d.ts +110 -0
- package/dist/accessPolicyResolver.d.ts.map +1 -0
- package/dist/accessPolicyResolver.js.map +1 -0
- package/dist/accessRules.d.ts +16 -0
- package/dist/accessRules.d.ts.map +1 -0
- package/dist/accessRules.js.map +1 -0
- package/dist/api/.export.d.ts +7 -0
- package/dist/api/.export.d.ts.map +1 -0
- package/dist/api/.export.js +11 -0
- package/dist/api/.export.js.map +1 -0
- package/dist/api/accessRuleApiRoutes.d.ts +27 -0
- package/dist/api/accessRuleApiRoutes.d.ts.map +1 -0
- package/dist/api/accessRuleApiRoutes.js.map +1 -0
- package/dist/api/accessRulesApiClient.d.ts +10 -0
- package/dist/api/accessRulesApiClient.d.ts.map +1 -0
- package/dist/api/accessRulesApiClient.js +38 -0
- package/dist/api/accessRulesApiClient.js.map +1 -0
- package/dist/api/delete/.export.d.ts +2 -0
- package/dist/api/delete/.export.d.ts.map +1 -0
- package/dist/api/delete/.export.js +1 -0
- package/dist/api/delete/.export.js.map +1 -0
- package/dist/api/delete/deleteAllRules.d.ts +11 -0
- package/dist/api/delete/deleteAllRules.d.ts.map +1 -0
- package/dist/api/delete/deleteAllRules.js +25 -0
- package/dist/api/delete/deleteAllRules.js.map +1 -0
- package/dist/api/delete/deleteRuleGroups.d.ts +19 -0
- package/dist/api/delete/deleteRuleGroups.d.ts.map +1 -0
- package/dist/api/delete/deleteRuleGroups.js +52 -0
- package/dist/api/delete/deleteRuleGroups.js.map +1 -0
- package/dist/api/delete/deleteRules.d.ts +15 -0
- package/dist/api/delete/deleteRules.d.ts.map +1 -0
- package/dist/api/delete/deleteRules.js +43 -0
- package/dist/api/delete/deleteRules.js.map +1 -0
- package/dist/api/deleteAllRulesEndpoint.d.ts +12 -0
- package/dist/api/deleteAllRulesEndpoint.d.ts.map +1 -0
- package/dist/api/deleteAllRulesEndpoint.js.map +1 -0
- package/dist/api/deleteRulesEndpoint.d.ts +116 -0
- package/dist/api/deleteRulesEndpoint.d.ts.map +1 -0
- package/dist/api/deleteRulesEndpoint.js.map +1 -0
- package/dist/api/insertRulesEndpoint.d.ts +22 -0
- package/dist/api/insertRulesEndpoint.d.ts.map +1 -0
- package/dist/api/insertRulesEndpoint.js.map +1 -0
- package/dist/api/read/.export.d.ts +4 -0
- package/dist/api/read/.export.d.ts.map +1 -0
- package/dist/api/read/.export.js +1 -0
- package/dist/api/read/.export.js.map +1 -0
- package/dist/api/read/fetchRules.d.ts +53 -0
- package/dist/api/read/fetchRules.d.ts.map +1 -0
- package/dist/api/read/fetchRules.js +43 -0
- package/dist/api/read/fetchRules.js.map +1 -0
- package/dist/api/read/findRuleIds.d.ts +28 -0
- package/dist/api/read/findRuleIds.d.ts.map +1 -0
- package/dist/api/read/findRuleIds.js +50 -0
- package/dist/api/read/findRuleIds.js.map +1 -0
- package/dist/api/read/getMissingIds.d.ts +28 -0
- package/dist/api/read/getMissingIds.d.ts.map +1 -0
- package/dist/api/read/getMissingIds.js +41 -0
- package/dist/api/read/getMissingIds.js.map +1 -0
- package/dist/api/ruleApiRoutes.d.ts +43 -0
- package/dist/api/ruleApiRoutes.d.ts.map +1 -0
- package/dist/api/ruleApiRoutes.js +131 -0
- package/dist/api/ruleApiRoutes.js.map +1 -0
- package/dist/api/rulesApiClient.d.ts +20 -0
- package/dist/api/rulesApiClient.d.ts.map +1 -0
- package/dist/api/rulesApiClient.js +93 -0
- package/dist/api/rulesApiClient.js.map +1 -0
- package/dist/api/write/.export.d.ts +2 -0
- package/dist/api/write/.export.d.ts.map +1 -0
- package/dist/api/write/.export.js +1 -0
- package/dist/api/write/.export.js.map +1 -0
- package/dist/api/write/insertRules.d.ts +29 -0
- package/dist/api/write/insertRules.d.ts.map +1 -0
- package/dist/api/write/insertRules.js +102 -0
- package/dist/api/write/insertRules.js.map +1 -0
- package/dist/api/write/rehashRules.d.ts +11 -0
- package/dist/api/write/rehashRules.d.ts.map +1 -0
- package/dist/api/write/rehashRules.js +57 -0
- package/dist/api/write/rehashRules.js.map +1 -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/delete/deleteAllRules.cjs +25 -0
- 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/index.cjs +2 -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/redisAccessRules.cjs +4 -4
- package/dist/cjs/redis/redisAccessRulesIndex.cjs +55 -14
- package/dist/cjs/redis/redisClient.cjs +67 -0
- package/dist/cjs/redis/redisRuleIndex.cjs +50 -0
- package/dist/cjs/redis/redisRulesStorage.cjs +34 -0
- package/dist/cjs/redis/redisRulesWriter.cjs +100 -0
- 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/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -3
- package/dist/index.js.map +1 -0
- package/dist/mongoose/.export.d.ts +2 -0
- package/dist/mongoose/.export.d.ts.map +1 -0
- package/dist/mongoose/.export.js +4 -0
- package/dist/mongoose/.export.js.map +1 -0
- package/dist/mongoose/mongooseRuleSchema.d.ts +4 -0
- package/dist/mongoose/mongooseRuleSchema.d.ts.map +1 -0
- package/dist/mongoose/mongooseRuleSchema.js +36 -0
- package/dist/mongoose/mongooseRuleSchema.js.map +1 -0
- package/dist/redis/.export.d.ts +3 -0
- package/dist/redis/.export.d.ts.map +1 -0
- package/dist/redis/.export.js +6 -0
- package/dist/redis/.export.js.map +1 -0
- package/dist/redis/reader/redisAggregate.d.ts +4 -0
- package/dist/redis/reader/redisAggregate.d.ts.map +1 -0
- package/dist/redis/reader/redisAggregate.js +60 -0
- package/dist/redis/reader/redisAggregate.js.map +1 -0
- package/dist/redis/reader/redisRulesQuery.d.ts +4 -0
- package/dist/redis/reader/redisRulesQuery.d.ts.map +1 -0
- package/dist/redis/reader/redisRulesQuery.js +99 -0
- package/dist/redis/reader/redisRulesQuery.js.map +1 -0
- package/dist/redis/reader/redisRulesReader.d.ts +26 -0
- package/dist/redis/reader/redisRulesReader.d.ts.map +1 -0
- package/dist/redis/reader/redisRulesReader.js +213 -0
- package/dist/redis/reader/redisRulesReader.js.map +1 -0
- package/dist/redis/redisAccessRules.d.ts +7 -0
- package/dist/redis/redisAccessRules.d.ts.map +1 -0
- package/dist/redis/redisAccessRules.js +112 -128
- package/dist/redis/redisAccessRules.js.map +1 -0
- package/dist/redis/redisAccessRulesIndex.d.ts +13 -0
- package/dist/redis/redisAccessRulesIndex.d.ts.map +1 -0
- package/dist/redis/redisAccessRulesIndex.js +122 -112
- package/dist/redis/redisAccessRulesIndex.js.map +1 -0
- package/dist/redis/redisClient.d.ts +11 -0
- package/dist/redis/redisClient.d.ts.map +1 -0
- package/dist/redis/redisClient.js +67 -0
- package/dist/redis/redisClient.js.map +1 -0
- package/dist/redis/redisIndex.d.ts +9 -0
- package/dist/redis/redisIndex.d.ts.map +1 -0
- package/dist/redis/redisIndex.js +16 -15
- package/dist/redis/redisIndex.js.map +1 -0
- package/dist/redis/redisRuleIndex.d.ts +13 -0
- package/dist/redis/redisRuleIndex.d.ts.map +1 -0
- package/dist/redis/redisRuleIndex.js +50 -0
- package/dist/redis/redisRuleIndex.js.map +1 -0
- package/dist/redis/redisRulesIndex.d.ts +9 -0
- package/dist/redis/redisRulesIndex.d.ts.map +1 -0
- package/dist/redis/redisRulesIndex.js +138 -0
- package/dist/redis/redisRulesIndex.js.map +1 -0
- package/dist/redis/redisRulesReader.d.ts +6 -0
- package/dist/redis/redisRulesReader.d.ts.map +1 -0
- package/dist/redis/redisRulesReader.js +125 -0
- package/dist/redis/redisRulesReader.js.map +1 -0
- package/dist/redis/redisRulesStorage.d.ts +5 -0
- package/dist/redis/redisRulesStorage.d.ts.map +1 -0
- package/dist/redis/redisRulesStorage.js +34 -0
- package/dist/redis/redisRulesStorage.js.map +1 -0
- package/dist/redis/redisRulesWriter.d.ts +22 -0
- package/dist/redis/redisRulesWriter.d.ts.map +1 -0
- package/dist/redis/redisRulesWriter.js +100 -0
- package/dist/redis/redisRulesWriter.js.map +1 -0
- package/dist/rule.d.ts +34 -0
- package/dist/rule.d.ts.map +1 -0
- package/dist/rule.js +8 -0
- package/dist/rule.js.map +1 -0
- package/dist/ruleInput/.export.d.ts +4 -0
- package/dist/ruleInput/.export.d.ts.map +1 -0
- package/dist/ruleInput/.export.js +9 -0
- package/dist/ruleInput/.export.js.map +1 -0
- package/dist/ruleInput/policyInput.d.ts +38 -0
- package/dist/ruleInput/policyInput.d.ts.map +1 -0
- package/dist/ruleInput/policyInput.js +25 -0
- package/dist/ruleInput/policyInput.js.map +1 -0
- package/dist/ruleInput/ruleInput.d.ts +145 -0
- package/dist/ruleInput/ruleInput.d.ts.map +1 -0
- package/dist/ruleInput/ruleInput.js +50 -0
- package/dist/ruleInput/ruleInput.js.map +1 -0
- package/dist/ruleInput/userScopeInput.d.ts +93 -0
- package/dist/ruleInput/userScopeInput.d.ts.map +1 -0
- package/dist/ruleInput/userScopeInput.js +55 -0
- package/dist/ruleInput/userScopeInput.js.map +1 -0
- package/dist/ruleRecord.d.ts +18 -0
- package/dist/ruleRecord.d.ts.map +1 -0
- package/dist/ruleRecord.js +23 -0
- package/dist/ruleRecord.js.map +1 -0
- package/dist/rulesStorage.d.ts +30 -0
- package/dist/rulesStorage.d.ts.map +1 -0
- package/dist/rulesStorage.js +8 -0
- package/dist/rulesStorage.js.map +1 -0
- package/dist/tests/accessPolicy.test.d.ts +2 -0
- package/dist/tests/accessPolicy.test.d.ts.map +1 -0
- package/dist/tests/accessPolicy.test.js +27 -0
- package/dist/tests/accessPolicy.test.js.map +1 -0
- package/dist/tests/redis/reader/redisRulesQuery.unit.test.d.ts +2 -0
- package/dist/tests/redis/reader/redisRulesQuery.unit.test.d.ts.map +1 -0
- package/dist/tests/redis/reader/redisRulesQuery.unit.test.js +101 -0
- package/dist/tests/redis/reader/redisRulesQuery.unit.test.js.map +1 -0
- package/dist/tests/redis/redisAccessRules.integration.test.d.ts +2 -0
- package/dist/tests/redis/redisAccessRules.integration.test.d.ts.map +1 -0
- package/dist/tests/redis/redisAccessRules.integration.test.js +586 -0
- package/dist/tests/redis/redisAccessRules.integration.test.js.map +1 -0
- package/dist/tests/redis/redisAccessRules.unit.test.d.ts +2 -0
- package/dist/tests/redis/redisAccessRules.unit.test.d.ts.map +1 -0
- package/dist/tests/redis/redisAccessRules.unit.test.js +198 -0
- package/dist/tests/redis/redisAccessRules.unit.test.js.map +1 -0
- package/dist/tests/redis/redisIndex.integration.test.d.ts +2 -0
- package/dist/tests/redis/redisIndex.integration.test.d.ts.map +1 -0
- package/dist/tests/redis/redisIndex.integration.test.js +80 -0
- package/dist/tests/redis/redisIndex.integration.test.js.map +1 -0
- package/dist/tests/redis/redisRulesIndex.unit.test.d.ts +2 -0
- package/dist/tests/redis/redisRulesIndex.unit.test.d.ts.map +1 -0
- package/dist/tests/redis/redisRulesIndex.unit.test.js +101 -0
- package/dist/tests/redis/redisRulesIndex.unit.test.js.map +1 -0
- package/dist/tests/redis/redisRulesStorage.integration.test.d.ts +2 -0
- package/dist/tests/redis/redisRulesStorage.integration.test.d.ts.map +1 -0
- package/dist/tests/redis/redisRulesStorage.integration.test.js +611 -0
- package/dist/tests/redis/redisRulesStorage.integration.test.js.map +1 -0
- package/dist/tests/redis/testRedisClient.d.ts +3 -0
- package/dist/tests/redis/testRedisClient.d.ts.map +1 -0
- package/dist/tests/redis/testRedisClient.js +8 -0
- package/dist/tests/redis/testRedisClient.js.map +1 -0
- package/dist/tests/testLogger.d.ts +4 -0
- package/dist/tests/testLogger.d.ts.map +1 -0
- package/dist/tests/testLogger.js +22 -0
- package/dist/tests/testLogger.js.map +1 -0
- package/dist/tests/transformRule.unit.test.d.ts +2 -0
- package/dist/tests/transformRule.unit.test.d.ts.map +1 -0
- package/dist/tests/transformRule.unit.test.js +188 -0
- package/dist/tests/transformRule.unit.test.js.map +1 -0
- package/dist/transformRule.d.ts +7 -0
- package/dist/transformRule.d.ts.map +1 -0
- package/dist/transformRule.js +77 -0
- package/dist/transformRule.js.map +1 -0
- package/dist/util.d.ts +2 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js.map +1 -0
- package/entries.ts +20 -0
- package/package.json +42 -21
- package/vite.cjs.config.ts +4 -1
- package/vite.esm.config.ts +6 -1
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const common = require("@prosopo/common");
|
|
4
|
+
const redisClient = require("./redisClient.cjs");
|
|
5
|
+
const redisRuleIndex = require("./redisRuleIndex.cjs");
|
|
6
|
+
class RedisRulesWriter {
|
|
7
|
+
constructor(client, logger) {
|
|
8
|
+
this.client = client;
|
|
9
|
+
this.logger = logger;
|
|
10
|
+
}
|
|
11
|
+
async insertRules(ruleEntries) {
|
|
12
|
+
const entryBatches = common.chunkIntoBatches(ruleEntries, redisClient.REDIS_BATCH_SIZE);
|
|
13
|
+
const keyBatches = await common.executeBatchesSequentially(
|
|
14
|
+
entryBatches,
|
|
15
|
+
async (entriesBatch) => this.insertRuleEntries(entriesBatch)
|
|
16
|
+
);
|
|
17
|
+
return keyBatches.flatMap(
|
|
18
|
+
(ruleKey) => ruleKey.slice(redisRuleIndex.ACCESS_RULE_REDIS_KEY_PREFIX.length)
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
async deleteRules(ruleIds) {
|
|
22
|
+
const ruleKeys = ruleIds.map(
|
|
23
|
+
(ruleId) => redisRuleIndex.ACCESS_RULE_REDIS_KEY_PREFIX + ruleId
|
|
24
|
+
);
|
|
25
|
+
const keyBatches = common.chunkIntoBatches(ruleKeys, redisClient.REDIS_BATCH_SIZE);
|
|
26
|
+
await common.executeBatchesSequentially(keyBatches, async (keysBatch) => {
|
|
27
|
+
const queries = this.client.multi();
|
|
28
|
+
for (const ruleKey of keysBatch) {
|
|
29
|
+
queries.del(ruleKey);
|
|
30
|
+
}
|
|
31
|
+
await queries.exec();
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async deleteAllRules() {
|
|
35
|
+
let cursor = "0";
|
|
36
|
+
let total = 0;
|
|
37
|
+
do {
|
|
38
|
+
const reply = await this.client.scan(cursor, {
|
|
39
|
+
MATCH: `${redisRuleIndex.ACCESS_RULE_REDIS_KEY_PREFIX}*`,
|
|
40
|
+
COUNT: redisClient.REDIS_BATCH_SIZE
|
|
41
|
+
});
|
|
42
|
+
const ids = reply.keys.map(
|
|
43
|
+
(key) => key.slice(redisRuleIndex.ACCESS_RULE_REDIS_KEY_PREFIX.length)
|
|
44
|
+
);
|
|
45
|
+
await this.deleteRules(ids);
|
|
46
|
+
total += ids.length;
|
|
47
|
+
cursor = reply.cursor;
|
|
48
|
+
} while ("0" !== cursor);
|
|
49
|
+
return total;
|
|
50
|
+
}
|
|
51
|
+
async insertRuleEntries(ruleEntries) {
|
|
52
|
+
const queries = this.client.multi();
|
|
53
|
+
const ruleKeys = ruleEntries.map((ruleEntry) => {
|
|
54
|
+
const { rule, expiresUnixTimestamp } = ruleEntry;
|
|
55
|
+
const ruleKey = redisRuleIndex.getAccessRuleRedisKey(rule);
|
|
56
|
+
const ruleValue = getRedisRuleValue(rule);
|
|
57
|
+
queries.hSet(ruleKey, ruleValue);
|
|
58
|
+
if (expiresUnixTimestamp) {
|
|
59
|
+
queries.expireAt(ruleKey, expiresUnixTimestamp);
|
|
60
|
+
}
|
|
61
|
+
return ruleKey;
|
|
62
|
+
});
|
|
63
|
+
await queries.exec();
|
|
64
|
+
return ruleKeys;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const getRedisRuleValue = (rule) => Object.fromEntries(
|
|
68
|
+
Object.entries(rule).map(([key, value]) => [key, String(value)])
|
|
69
|
+
);
|
|
70
|
+
class DummyRedisRulesWriter {
|
|
71
|
+
constructor(logger) {
|
|
72
|
+
this.logger = logger;
|
|
73
|
+
}
|
|
74
|
+
async insertRules(ruleEntries) {
|
|
75
|
+
this.logger.info(() => ({
|
|
76
|
+
msg: "Dummy insertRules() has no effect (redis is not ready)",
|
|
77
|
+
data: {
|
|
78
|
+
ruleEntries
|
|
79
|
+
}
|
|
80
|
+
}));
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
async deleteRules(ruleIds) {
|
|
84
|
+
this.logger.info(() => ({
|
|
85
|
+
msg: "Dummy deleteRules() has no effect (redis is not ready)",
|
|
86
|
+
data: {
|
|
87
|
+
ruleIds
|
|
88
|
+
}
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
async deleteAllRules() {
|
|
92
|
+
this.logger.info(() => ({
|
|
93
|
+
msg: "Dummy deleteAllRules() has no effect (redis is not ready)"
|
|
94
|
+
}));
|
|
95
|
+
return 0;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.DummyRedisRulesWriter = DummyRedisRulesWriter;
|
|
99
|
+
exports.RedisRulesWriter = RedisRulesWriter;
|
|
100
|
+
exports.getRedisRuleValue = getRedisRuleValue;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
var AccessPolicyType = /* @__PURE__ */ ((AccessPolicyType2) => {
|
|
4
|
+
AccessPolicyType2["Block"] = "block";
|
|
5
|
+
AccessPolicyType2["Restrict"] = "restrict";
|
|
6
|
+
return AccessPolicyType2;
|
|
7
|
+
})(AccessPolicyType || {});
|
|
8
|
+
exports.AccessPolicyType = AccessPolicyType;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const ruleInput = require("./ruleInput.cjs");
|
|
4
|
+
const policyInput = require("./policyInput.cjs");
|
|
5
|
+
const userScopeInput = require("./userScopeInput.cjs");
|
|
6
|
+
exports.accessRuleInput = ruleInput.accessRuleInput;
|
|
7
|
+
exports.accessPolicyInput = policyInput.accessPolicyInput;
|
|
8
|
+
exports.policyScopeInput = policyInput.policyScopeInput;
|
|
9
|
+
exports.userScopeInput = userScopeInput.userScopeInput;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const types = require("@prosopo/types");
|
|
4
|
+
const zod = require("zod");
|
|
5
|
+
const rule = require("../rule.cjs");
|
|
6
|
+
const accessPolicyInput = zod.z.object({
|
|
7
|
+
type: zod.z.nativeEnum(rule.AccessPolicyType),
|
|
8
|
+
captchaType: types.CaptchaTypeSchema.optional(),
|
|
9
|
+
description: zod.z.coerce.string().optional(),
|
|
10
|
+
// Redis stores values as strings, so coerce is needed to parse properly
|
|
11
|
+
solvedImagesCount: zod.z.coerce.number().optional(),
|
|
12
|
+
// the percentage of image panels that must be solved per image CAPTCHA
|
|
13
|
+
imageThreshold: zod.z.coerce.number().optional(),
|
|
14
|
+
// the Proof-of-Work difficulty level
|
|
15
|
+
powDifficulty: zod.z.coerce.number().optional(),
|
|
16
|
+
// the number of unsolved image CAPTCHA challenges to serve
|
|
17
|
+
unsolvedImagesCount: zod.z.coerce.number().optional(),
|
|
18
|
+
// used to increase the user's score
|
|
19
|
+
frictionlessScore: zod.z.coerce.number().optional()
|
|
20
|
+
});
|
|
21
|
+
const policyScopeInput = zod.z.object({
|
|
22
|
+
clientId: zod.z.coerce.string().optional()
|
|
23
|
+
});
|
|
24
|
+
exports.accessPolicyInput = accessPolicyInput;
|
|
25
|
+
exports.policyScopeInput = policyScopeInput;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const zod = require("zod");
|
|
4
|
+
const rulesStorage = require("../rulesStorage.cjs");
|
|
5
|
+
const policyInput = require("./policyInput.cjs");
|
|
6
|
+
const userScopeInput = require("./userScopeInput.cjs");
|
|
7
|
+
const ruleGroupInput = zod.z.object({
|
|
8
|
+
groupId: zod.z.coerce.string().optional(),
|
|
9
|
+
ruleGroupId: zod.z.coerce.string().optional()
|
|
10
|
+
}).transform((ruleGroupInput2) => {
|
|
11
|
+
const { ruleGroupId, ...ruleGroup } = ruleGroupInput2;
|
|
12
|
+
if ("string" === typeof ruleGroupId) {
|
|
13
|
+
ruleGroup.groupId = ruleGroupId;
|
|
14
|
+
}
|
|
15
|
+
return ruleGroup;
|
|
16
|
+
});
|
|
17
|
+
const accessRuleInput = zod.z.object({
|
|
18
|
+
...policyInput.accessPolicyInput.shape,
|
|
19
|
+
...policyInput.policyScopeInput.shape
|
|
20
|
+
}).and(userScopeInput.userScopeInput).and(ruleGroupInput).transform((ruleInput) => ruleInput);
|
|
21
|
+
const ruleEntryInput = zod.z.object({
|
|
22
|
+
rule: accessRuleInput,
|
|
23
|
+
expiresUnixTimestamp: zod.z.coerce.number().optional()
|
|
24
|
+
});
|
|
25
|
+
const accessRulesFilterInput = zod.z.object({
|
|
26
|
+
policyScope: policyInput.policyScopeInput.optional(),
|
|
27
|
+
policyScopes: zod.z.array(policyInput.policyScopeInput).optional(),
|
|
28
|
+
policyScopeMatch: zod.z.nativeEnum(rulesStorage.FilterScopeMatch).default(rulesStorage.FilterScopeMatch.Exact),
|
|
29
|
+
userScope: userScopeInput.userScopeInput.optional(),
|
|
30
|
+
userScopeMatch: zod.z.nativeEnum(rulesStorage.FilterScopeMatch).default(rulesStorage.FilterScopeMatch.Exact),
|
|
31
|
+
groupId: zod.z.string().optional()
|
|
32
|
+
});
|
|
33
|
+
const getAccessRuleFiltersFromInput = (filterInput) => {
|
|
34
|
+
const { policyScopes, policyScope, ...filterBase } = filterInput;
|
|
35
|
+
const allPolicyScopes = policyScopes || [];
|
|
36
|
+
if (policyScope) {
|
|
37
|
+
allPolicyScopes.push(policyScope);
|
|
38
|
+
}
|
|
39
|
+
if (allPolicyScopes.length > 0) {
|
|
40
|
+
return allPolicyScopes.map((policyScope2) => ({
|
|
41
|
+
...filterBase,
|
|
42
|
+
policyScope: policyScope2
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
return [filterBase];
|
|
46
|
+
};
|
|
47
|
+
exports.accessRuleInput = accessRuleInput;
|
|
48
|
+
exports.accessRulesFilterInput = accessRulesFilterInput;
|
|
49
|
+
exports.getAccessRuleFiltersFromInput = getAccessRuleFiltersFromInput;
|
|
50
|
+
exports.ruleEntryInput = ruleEntryInput;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const crypto = require("node:crypto");
|
|
4
|
+
const util = require("@prosopo/util");
|
|
5
|
+
const ipAddress = require("ip-address");
|
|
6
|
+
const zod = require("zod");
|
|
7
|
+
const userAttributesSchema = zod.z.object({
|
|
8
|
+
// coerce is used for safety, as e.g., incoming userId can be digital
|
|
9
|
+
userId: zod.z.coerce.string().optional(),
|
|
10
|
+
ja4Hash: zod.z.coerce.string().optional(),
|
|
11
|
+
headersHash: zod.z.coerce.string().optional(),
|
|
12
|
+
userAgentHash: zod.z.coerce.string().optional()
|
|
13
|
+
});
|
|
14
|
+
const userAttributesInput = zod.z.object({
|
|
15
|
+
...userAttributesSchema.shape,
|
|
16
|
+
userAgent: zod.z.coerce.string().optional()
|
|
17
|
+
}).transform((userAttributesInput2) => {
|
|
18
|
+
const { userAgent, ...userScope } = userAttributesInput2;
|
|
19
|
+
if ("string" === typeof userAgent) {
|
|
20
|
+
userScope.userAgentHash = hashUserAgent(userAgent);
|
|
21
|
+
}
|
|
22
|
+
return userScope;
|
|
23
|
+
});
|
|
24
|
+
const hashUserAgent = (userAgent) => crypto.createHash("sha256").update(userAgent).digest("hex");
|
|
25
|
+
const userIpSchema = zod.z.object({
|
|
26
|
+
numericIp: zod.z.coerce.bigint().optional(),
|
|
27
|
+
numericIpMaskMin: zod.z.coerce.bigint().optional(),
|
|
28
|
+
numericIpMaskMax: zod.z.coerce.bigint().optional()
|
|
29
|
+
});
|
|
30
|
+
const userIpInput = zod.z.object({
|
|
31
|
+
...userIpSchema.shape,
|
|
32
|
+
ip: zod.z.string().optional(),
|
|
33
|
+
ipMask: zod.z.string().optional()
|
|
34
|
+
}).transform((userIpInput2) => {
|
|
35
|
+
const { ip, ipMask, ...numericUserIp } = userIpInput2;
|
|
36
|
+
if ("string" === typeof ip) {
|
|
37
|
+
numericUserIp.numericIp = util.getIPAddress(ip).bigInt();
|
|
38
|
+
}
|
|
39
|
+
if ("string" === typeof ipMask) {
|
|
40
|
+
const ipObject = new ipAddress.Address4(ipMask);
|
|
41
|
+
numericUserIp.numericIpMaskMin = ipObject.startAddress().bigInt();
|
|
42
|
+
numericUserIp.numericIpMaskMax = ipObject.endAddress().bigInt();
|
|
43
|
+
}
|
|
44
|
+
return numericUserIp;
|
|
45
|
+
});
|
|
46
|
+
const userScopeSchema = zod.z.object({
|
|
47
|
+
...userIpSchema.shape,
|
|
48
|
+
...userAttributesSchema.shape
|
|
49
|
+
});
|
|
50
|
+
const userScopeInput = zod.z.object({}).and(userIpInput).and(userAttributesInput).transform(
|
|
51
|
+
// transform is used for type safety only - plain "satisfies ZodType<x>" doesn't work after ".and()"
|
|
52
|
+
(userScopeInput2) => userScopeInput2
|
|
53
|
+
);
|
|
54
|
+
exports.userScopeInput = userScopeInput;
|
|
55
|
+
exports.userScopeSchema = userScopeSchema;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const userAttributesRecordFields = [
|
|
4
|
+
"userId",
|
|
5
|
+
"ja4Hash",
|
|
6
|
+
"headersHash",
|
|
7
|
+
"userAgent"
|
|
8
|
+
];
|
|
9
|
+
const userIpRecordFields = [
|
|
10
|
+
"ip",
|
|
11
|
+
"ipMask"
|
|
12
|
+
];
|
|
13
|
+
const userScopeRecordFields = [
|
|
14
|
+
...userAttributesRecordFields,
|
|
15
|
+
...userIpRecordFields
|
|
16
|
+
];
|
|
17
|
+
const getUserScopeRecordFromAccessRuleRecord = (ruleRecord) => Object.fromEntries(
|
|
18
|
+
userScopeRecordFields.map((field) => [field, ruleRecord[field]]).filter(([, value]) => value !== void 0)
|
|
19
|
+
);
|
|
20
|
+
exports.getUserScopeRecordFromAccessRuleRecord = getUserScopeRecordFromAccessRuleRecord;
|
|
21
|
+
exports.userAttributesRecordFields = userAttributesRecordFields;
|
|
22
|
+
exports.userIpRecordFields = userIpRecordFields;
|
|
23
|
+
exports.userScopeRecordFields = userScopeRecordFields;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
var FilterScopeMatch = /* @__PURE__ */ ((FilterScopeMatch2) => {
|
|
4
|
+
FilterScopeMatch2["Exact"] = "exact";
|
|
5
|
+
FilterScopeMatch2["Greedy"] = "greedy";
|
|
6
|
+
return FilterScopeMatch2;
|
|
7
|
+
})(FilterScopeMatch || {});
|
|
8
|
+
exports.FilterScopeMatch = FilterScopeMatch;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const crypto = require("node:crypto");
|
|
4
|
+
const cidrCalc = require("cidr-calc");
|
|
5
|
+
const ipAddress = require("ip-address");
|
|
6
|
+
const zod = require("zod");
|
|
7
|
+
const policyInput = require("./ruleInput/policyInput.cjs");
|
|
8
|
+
const ruleInput = require("./ruleInput/ruleInput.cjs");
|
|
9
|
+
const userScopeInput = require("./ruleInput/userScopeInput.cjs");
|
|
10
|
+
const RULE_HASH_ALGORITHM = "md5";
|
|
11
|
+
const makeAccessRuleHash = (rule) => {
|
|
12
|
+
const valueProperties = Object.entries(rule).filter(
|
|
13
|
+
([key, value]) => "undefined" !== typeof value
|
|
14
|
+
);
|
|
15
|
+
const orderedProperties = valueProperties.sort();
|
|
16
|
+
const objectToHash = Object.fromEntries(orderedProperties);
|
|
17
|
+
return hashObject(objectToHash, RULE_HASH_ALGORITHM);
|
|
18
|
+
};
|
|
19
|
+
const transformAccessRuleRecordIntoRule = (ruleRecord) => (
|
|
20
|
+
// accessRuleInput does all the record field transformations
|
|
21
|
+
ruleInput.accessRuleInput.parse(ruleRecord)
|
|
22
|
+
);
|
|
23
|
+
const transformAccessRuleIntoRecord = (rule) => accessRuleToRecordScheme.parse(rule);
|
|
24
|
+
const accessRuleToRecordScheme = zod.z.object({
|
|
25
|
+
...policyInput.accessPolicyInput.shape,
|
|
26
|
+
...policyInput.policyScopeInput.shape,
|
|
27
|
+
...userScopeInput.userScopeSchema.shape,
|
|
28
|
+
groupId: zod.z.coerce.string().optional()
|
|
29
|
+
}).transform((ruleInput2) => {
|
|
30
|
+
const {
|
|
31
|
+
groupId,
|
|
32
|
+
numericIp,
|
|
33
|
+
numericIpMaskMin,
|
|
34
|
+
numericIpMaskMax,
|
|
35
|
+
userAgentHash,
|
|
36
|
+
...rule
|
|
37
|
+
} = ruleInput2;
|
|
38
|
+
const record = rule;
|
|
39
|
+
if ("string" === typeof groupId) {
|
|
40
|
+
record.ruleGroupId = groupId;
|
|
41
|
+
}
|
|
42
|
+
if ("string" === typeof userAgentHash) {
|
|
43
|
+
record.userAgent = userAgentHash;
|
|
44
|
+
}
|
|
45
|
+
if ("bigint" === typeof numericIp) {
|
|
46
|
+
record.ip = getStringIpFromNumeric(numericIp);
|
|
47
|
+
}
|
|
48
|
+
if ("bigint" === typeof numericIpMaskMin && "bigint" === typeof numericIpMaskMax) {
|
|
49
|
+
record.ipMask = getCidrFromNumericIpRange(
|
|
50
|
+
numericIpMaskMin,
|
|
51
|
+
numericIpMaskMax
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
return record;
|
|
55
|
+
});
|
|
56
|
+
const hashObject = (object, algorithm) => crypto.createHash(algorithm).update(
|
|
57
|
+
JSON.stringify(
|
|
58
|
+
object,
|
|
59
|
+
(key, value) => (
|
|
60
|
+
// JSON.stringify can't handle BigInt itself: throws "Do not know how to serialize a BigInt"
|
|
61
|
+
"bigint" === typeof value ? value.toString() : value
|
|
62
|
+
)
|
|
63
|
+
)
|
|
64
|
+
).digest("hex");
|
|
65
|
+
const getStringIpFromNumeric = (numericIp) => ipAddress.Address4.fromInteger(Number(numericIp)).address;
|
|
66
|
+
const getCidrFromNumericIpRange = (startIp, endIp) => {
|
|
67
|
+
const ipRange = new cidrCalc.IpRange(
|
|
68
|
+
cidrCalc.IpAddress.of(getStringIpFromNumeric(startIp)),
|
|
69
|
+
cidrCalc.IpAddress.of(getStringIpFromNumeric(endIp))
|
|
70
|
+
);
|
|
71
|
+
const cidr = ipRange.toCidrs()[0];
|
|
72
|
+
return cidr ? `${cidr.prefix.toString()}/${cidr.prefixLen}` : void 0;
|
|
73
|
+
};
|
|
74
|
+
exports.getCidrFromNumericIpRange = getCidrFromNumericIpRange;
|
|
75
|
+
exports.makeAccessRuleHash = makeAccessRuleHash;
|
|
76
|
+
exports.transformAccessRuleIntoRecord = transformAccessRuleIntoRecord;
|
|
77
|
+
exports.transformAccessRuleRecordIntoRule = transformAccessRuleRecordIntoRule;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { type AccessPolicy, AccessPolicyType, type AccessRuleExtended, type PolicyScope, type UserScope, type UserScopeApiInput, type UserScopeApiOutput, accessPolicySchema, accessRuleSchemaExtended, policyScopeSchema, } from "#policy/accessPolicy.js";
|
|
2
|
+
export { type PolicyFilter, ScopeMatch } from "#policy/accessPolicyResolver.js";
|
|
3
|
+
export { type AccessRule, type AccessRulesStorage, accessRuleSchema, } from "#policy/accessRules.js";
|
|
4
|
+
export { accessRuleApiPaths, getExpressApiRuleRateLimits, } from "#policy/api/accessRuleApiRoutes.js";
|
|
5
|
+
export { type DeleteAllRulesEndpointSchema, deleteAllRulesEndpointSchema, } from "#policy/api/deleteAllRulesEndpoint.js";
|
|
6
|
+
export { type DeleteRulesEndpointSchemaInput, type DeleteRulesEndpointSchemaOutput, deleteRulesEndpointSchema, } from "#policy/api/deleteRulesEndpoint.js";
|
|
7
|
+
export { type InsertManyRulesEndpointInputSchema, type InsertManyRulesEndpointOutputSchema, insertRulesEndpointSchema, } from "#policy/api/insertRulesEndpoint.js";
|
|
8
|
+
export { createRedisAccessRulesStorage } from "#policy/redis/redisRulesStorage.js";
|
|
9
|
+
export { userScopeInputSchema } from "./accessPolicy.js";
|
|
10
|
+
export { redisAccessRulesIndex } from "./redis/redisRulesIndex.js";
|
|
11
|
+
export { AccessRulesApiClient } from "./api/accessRulesApiClient.js";
|
|
12
|
+
import type { ApiRoutesProvider } from "@prosopo/api-route";
|
|
13
|
+
import type { AccessRulesStorage } from "#policy/accessRules.js";
|
|
14
|
+
export declare const createApiRuleRoutesProvider: (rulesStorage: AccessRulesStorage) => ApiRoutesProvider;
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA,OAAO,EACN,KAAK,YAAY,EACjB,gBAAgB,EAChB,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,kBAAkB,EAClB,wBAAwB,EACxB,iBAAiB,GACjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,KAAK,YAAY,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EACN,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,gBAAgB,GAChB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACN,kBAAkB,EAClB,2BAA2B,GAC3B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACN,KAAK,4BAA4B,EACjC,4BAA4B,GAC5B,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACN,KAAK,8BAA8B,EACnC,KAAK,+BAA+B,EACpC,yBAAyB,GACzB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACN,KAAK,kCAAkC,EACvC,KAAK,mCAAmC,EACxC,yBAAyB,GACzB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAErE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAGjE,eAAO,MAAM,2BAA2B,iBACzB,kBAAkB,KAC9B,iBAEF,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
import { AccessPolicyType, accessPolicySchema, accessRuleSchemaExtended, policyScopeSchema, userScopeInputSchema } from "./accessPolicy.js";
|
|
2
2
|
import { ScopeMatch } from "./accessPolicyResolver.js";
|
|
3
|
+
import { accessRuleSchema } from "./accessRules.js";
|
|
3
4
|
import { AccessRuleApiRoutes } from "./api/accessRuleApiRoutes.js";
|
|
4
5
|
import { accessRuleApiPaths, getExpressApiRuleRateLimits } from "./api/accessRuleApiRoutes.js";
|
|
5
6
|
import { deleteAllRulesEndpointSchema } from "./api/deleteAllRulesEndpoint.js";
|
|
6
7
|
import { deleteRulesEndpointSchema } from "./api/deleteRulesEndpoint.js";
|
|
7
8
|
import { insertRulesEndpointSchema } from "./api/insertRulesEndpoint.js";
|
|
8
|
-
import { createRedisAccessRulesStorage } from "./redis/
|
|
9
|
-
import {
|
|
9
|
+
import { createRedisAccessRulesStorage } from "./redis/redisRulesStorage.js";
|
|
10
|
+
import { redisAccessRulesIndex } from "./redis/redisRulesIndex.js";
|
|
11
|
+
import { AccessRulesApiClient } from "./api/accessRulesApiClient.js";
|
|
10
12
|
const createApiRuleRoutesProvider = (rulesStorage) => {
|
|
11
13
|
return new AccessRuleApiRoutes(rulesStorage);
|
|
12
14
|
};
|
|
13
15
|
export {
|
|
14
16
|
AccessPolicyType,
|
|
17
|
+
AccessRulesApiClient,
|
|
15
18
|
ScopeMatch,
|
|
16
19
|
accessPolicySchema,
|
|
17
20
|
accessRuleApiPaths,
|
|
21
|
+
accessRuleSchema,
|
|
18
22
|
accessRuleSchemaExtended,
|
|
19
23
|
createApiRuleRoutesProvider,
|
|
20
|
-
createRedisAccessRulesIndex,
|
|
21
24
|
createRedisAccessRulesStorage,
|
|
22
25
|
deleteAllRulesEndpointSchema,
|
|
23
26
|
deleteRulesEndpointSchema,
|
|
24
27
|
getExpressApiRuleRateLimits,
|
|
25
28
|
insertRulesEndpointSchema,
|
|
26
29
|
policyScopeSchema,
|
|
30
|
+
redisAccessRulesIndex,
|
|
27
31
|
userScopeInputSchema
|
|
28
32
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA,OAAO,EAEN,gBAAgB,EAMhB,kBAAkB,EAClB,wBAAwB,EACxB,iBAAiB,GACjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAqB,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAGN,gBAAgB,GAChB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACN,kBAAkB,EAClB,2BAA2B,GAC3B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAEN,4BAA4B,GAC5B,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAGN,yBAAyB,GACzB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAGN,yBAAyB,GACzB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAIrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAEzE,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAC1C,YAAgC,EACZ,EAAE;IACtB,OAAO,IAAI,mBAAmB,CAAC,YAAY,CAAC,CAAC;AAC9C,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":".export.d.ts","sourceRoot":"","sources":["../../src/mongoose/.export.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":".export.js","sourceRoot":"","sources":["../../src/mongoose/.export.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongooseRuleSchema.d.ts","sourceRoot":"","sources":["../../src/mongoose/mongooseRuleSchema.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD,OAAO,KAAK,EACX,gBAAgB,EAIhB,MAAM,uBAAuB,CAAC;AAkC/B,eAAO,MAAM,wBAAwB,EAAE,gBAAgB,CAAC,gBAAgB,CAKtC,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const userAttributesSchema = {
|
|
2
|
+
userId: { type: String, required: false },
|
|
3
|
+
ja4Hash: { type: String, required: false },
|
|
4
|
+
userAgent: { type: String, required: false },
|
|
5
|
+
headersHash: { type: String, required: false }
|
|
6
|
+
};
|
|
7
|
+
const userIpSchema = {
|
|
8
|
+
ip: { type: String, required: false },
|
|
9
|
+
ipMask: { type: String, required: false }
|
|
10
|
+
};
|
|
11
|
+
const userScopeSchema = {
|
|
12
|
+
...userAttributesSchema,
|
|
13
|
+
...userIpSchema
|
|
14
|
+
};
|
|
15
|
+
const policyScopeSchema = {
|
|
16
|
+
clientId: { type: String, required: false }
|
|
17
|
+
};
|
|
18
|
+
const accessPolicySchema = {
|
|
19
|
+
type: { type: String, required: true },
|
|
20
|
+
captchaType: { type: String, required: false },
|
|
21
|
+
description: { type: String, required: false },
|
|
22
|
+
solvedImagesCount: { type: Number, required: false },
|
|
23
|
+
imageThreshold: { type: Number, required: false },
|
|
24
|
+
powDifficulty: { type: Number, required: false },
|
|
25
|
+
unsolvedImagesCount: { type: Number, required: false },
|
|
26
|
+
frictionlessScore: { type: Number, required: false }
|
|
27
|
+
};
|
|
28
|
+
const accessRuleMongooseSchema = {
|
|
29
|
+
...accessPolicySchema,
|
|
30
|
+
...policyScopeSchema,
|
|
31
|
+
...userScopeSchema,
|
|
32
|
+
ruleGroupId: { type: String, required: false }
|
|
33
|
+
};
|
|
34
|
+
export {
|
|
35
|
+
accessRuleMongooseSchema
|
|
36
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongooseRuleSchema.js","sourceRoot":"","sources":["../../src/mongoose/mongooseRuleSchema.ts"],"names":[],"mappings":"AAwBA,MAAM,oBAAoB,GAA2C;IACpE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE;IACzC,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE;IAC1C,SAAS,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE;IAC5C,WAAW,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE;CACN,CAAC;AAE1C,MAAM,YAAY,GAAmC;IACpD,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE;IACrC,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE;CACT,CAAC;AAElC,MAAM,eAAe,GAAsC;IAC1D,GAAG,oBAAoB;IACvB,GAAG,YAAY;CACiB,CAAC;AAElC,MAAM,iBAAiB,GAAkC;IACxD,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE;CACZ,CAAC;AAEjC,MAAM,kBAAkB,GAAmC;IAC1D,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IACtC,WAAW,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE;IAC9C,WAAW,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE;IAC9C,iBAAiB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE;IACpD,cAAc,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE;IACjD,aAAa,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE;IAChD,mBAAmB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE;IACtD,iBAAiB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE;CACpB,CAAC;AAElC,MAAM,CAAC,MAAM,wBAAwB,GAAuC;IAC3E,GAAG,kBAAkB;IACrB,GAAG,iBAAiB;IACpB,GAAG,eAAe;IAClB,WAAW,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE;CACb,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":".export.d.ts","sourceRoot":"","sources":["../../src/redis/.export.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,6BAA6B,EAAE,MAAM,wBAAwB,CAAC;AAEvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":".export.js","sourceRoot":"","sources":["../../src/redis/.export.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,6BAA6B,EAAE,MAAM,wBAAwB,CAAC;AAEvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Logger } from "@prosopo/common";
|
|
2
|
+
import type { RedisClientType } from "redis";
|
|
3
|
+
export declare const aggregateRedisKeys: (client: RedisClientType, query: string, logger: Logger, batchHandler?: (keys: string[]) => Promise<void>) => Promise<string[]>;
|
|
4
|
+
//# sourceMappingURL=redisAggregate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redisAggregate.d.ts","sourceRoot":"","sources":["../../../src/redis/reader/redisAggregate.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAU7C,eAAO,MAAM,kBAAkB,WACtB,eAAe,SAChB,MAAM,UACL,MAAM,iBACC,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,KAC9C,OAAO,CAAC,MAAM,EAAE,CA0ClB,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { REDIS_QUERY_DIALECT } from "./redisRulesQuery.js";
|
|
3
|
+
import { parseRedisRecords, REDIS_BATCH_SIZE } from "../redisClient.js";
|
|
4
|
+
import { ACCESS_RULES_REDIS_INDEX_NAME } from "../redisRuleIndex.js";
|
|
5
|
+
const aggregateRedisKeys = async (client, query, logger, batchHandler) => {
|
|
6
|
+
const keyField = "__key";
|
|
7
|
+
const recordSchema = z.object({
|
|
8
|
+
// it's a reserved name for the record key
|
|
9
|
+
[keyField]: z.string()
|
|
10
|
+
});
|
|
11
|
+
const foundKeys = [];
|
|
12
|
+
const addRecordKeys = async (records) => {
|
|
13
|
+
const parsedRecords = parseRedisRecords(records, recordSchema, logger);
|
|
14
|
+
const recordKeys = parsedRecords.map((record) => record[keyField]);
|
|
15
|
+
if (batchHandler) {
|
|
16
|
+
await batchHandler(recordKeys);
|
|
17
|
+
} else {
|
|
18
|
+
foundKeys.push(...recordKeys);
|
|
19
|
+
logger.debug(() => ({
|
|
20
|
+
msg: "Processed aggregation batch",
|
|
21
|
+
data: {
|
|
22
|
+
size: recordKeys.length
|
|
23
|
+
}
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
await executeAggregation(
|
|
28
|
+
client,
|
|
29
|
+
query,
|
|
30
|
+
{
|
|
31
|
+
// #2 is a required option when the 'ismissing()' function is in the query body
|
|
32
|
+
DIALECT: REDIS_QUERY_DIALECT,
|
|
33
|
+
COUNT: REDIS_BATCH_SIZE,
|
|
34
|
+
LOAD: `@${keyField}`
|
|
35
|
+
},
|
|
36
|
+
addRecordKeys
|
|
37
|
+
);
|
|
38
|
+
return foundKeys;
|
|
39
|
+
};
|
|
40
|
+
const executeAggregation = async (client, query, aggregateOptions, handleBatch) => {
|
|
41
|
+
const initialReply = await client.ft.aggregateWithCursor(
|
|
42
|
+
ACCESS_RULES_REDIS_INDEX_NAME,
|
|
43
|
+
query,
|
|
44
|
+
aggregateOptions
|
|
45
|
+
);
|
|
46
|
+
await handleBatch(initialReply.results);
|
|
47
|
+
let cursor = initialReply.cursor;
|
|
48
|
+
while (0 !== cursor) {
|
|
49
|
+
const batchReply = await client.ft.cursorRead(
|
|
50
|
+
ACCESS_RULES_REDIS_INDEX_NAME,
|
|
51
|
+
cursor,
|
|
52
|
+
{ COUNT: aggregateOptions.COUNT }
|
|
53
|
+
);
|
|
54
|
+
await handleBatch(batchReply.results);
|
|
55
|
+
cursor = batchReply.cursor;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
export {
|
|
59
|
+
aggregateRedisKeys
|
|
60
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redisAggregate.js","sourceRoot":"","sources":["../../../src/redis/reader/redisAggregate.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EACN,gBAAgB,EAChB,iBAAiB,GACjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAGhF,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EACtC,MAAuB,EACvB,KAAa,EACb,MAAc,EACd,YAAgD,EAC5B,EAAE;IACtB,MAAM,QAAQ,GAAG,OAAO,CAAC;IAEzB,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;QAE7B,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE;KACtB,CAAC,CAAC;IAEH,MAAM,SAAS,GAAa,EAAE,CAAC;IAE/B,MAAM,aAAa,GAAG,KAAK,EAAE,OAAiB,EAAE,EAAE;QACjD,MAAM,aAAa,GAAG,iBAAiB,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;QAEvE,MAAM,UAAU,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QAEnE,IAAI,YAAY,EAAE,CAAC;YAClB,MAAM,YAAY,CAAC,UAAU,CAAC,CAAC;QAChC,CAAC;aAAM,CAAC;YACP,SAAS,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,CAAC;YAE9B,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;gBACnB,GAAG,EAAE,6BAA6B;gBAClC,IAAI,EAAE;oBACL,IAAI,EAAE,UAAU,CAAC,MAAM;iBACvB;aACD,CAAC,CAAC,CAAC;QACL,CAAC;IACF,CAAC,CAAC;IAEF,MAAM,kBAAkB,CACvB,MAAM,EACN,KAAK,EACL;QAEC,OAAO,EAAE,mBAAmB;QAC5B,KAAK,EAAE,gBAAgB;QACvB,IAAI,EAAE,IAAI,QAAQ,EAAE;KACpB,EACD,aAAa,CACb,CAAC;IAEF,OAAO,SAAS,CAAC;AAClB,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,KAAK,EAC/B,MAAuB,EACvB,KAAa,EACb,gBAA8C,EAC9C,WAAiD,EACjC,EAAE;IAClB,MAAM,YAAY,GAAG,MAAM,MAAM,CAAC,EAAE,CAAC,mBAAmB,CACvD,6BAA6B,EAC7B,KAAK,EACL,gBAAgB,CAChB,CAAC;IAEF,MAAM,WAAW,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAExC,IAAI,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC;IAEjC,OAAO,CAAC,KAAK,MAAM,EAAE,CAAC;QACrB,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,EAAE,CAAC,UAAU,CAC5C,6BAA6B,EAC7B,MAAM,EACN,EAAE,KAAK,EAAE,gBAAgB,CAAC,KAAK,EAAE,CACjC,CAAC;QAEF,MAAM,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAEtC,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IAC5B,CAAC;AACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redisRulesQuery.d.ts","sourceRoot":"","sources":["../../../src/redis/reader/redisRulesQuery.ts"],"names":[],"mappings":"AAgBA,OAAO,EACN,KAAK,iBAAiB,EAEtB,MAAM,yBAAyB,CAAC;AAKjC,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAmIrC,eAAO,MAAM,kBAAkB,WACtB,iBAAiB,sBACL,OAAO,KACzB,MA4BF,CAAC"}
|