@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.
Files changed (96) hide show
  1. package/.turbo/turbo-build$colon$cjs.log +45 -41
  2. package/.turbo/turbo-build$colon$tsc.log +14 -14
  3. package/.turbo/turbo-build.log +46 -42
  4. package/CHANGELOG.md +40 -0
  5. package/dist/.export.js +7 -21
  6. package/dist/_virtual/_rolldown/runtime.js +3 -0
  7. package/dist/api/.export.js +2 -9
  8. package/dist/api/accessRulesApiClient.js +1 -1
  9. package/dist/api/delete/.export.js +2 -1
  10. package/dist/api/delete/deleteAllRules.js +22 -24
  11. package/dist/api/delete/deleteRuleGroups.js +39 -51
  12. package/dist/api/delete/deleteRules.js +37 -41
  13. package/dist/api/read/.export.js +2 -1
  14. package/dist/api/read/fetchRules.js +34 -42
  15. package/dist/api/read/findRuleIds.js +35 -48
  16. package/dist/api/read/getMissingIds.js +36 -40
  17. package/dist/api/ruleApiRoutes.js +62 -120
  18. package/dist/api/rulesApiClient.js +51 -87
  19. package/dist/api/write/.export.js +2 -1
  20. package/dist/api/write/insertRules.js +84 -102
  21. package/dist/api/write/rehashRules.js +48 -56
  22. package/dist/cjs/.export.cjs +21 -23
  23. package/dist/cjs/_virtual/_rolldown/runtime.cjs +23 -0
  24. package/dist/cjs/api/.export.cjs +6 -10
  25. package/dist/cjs/api/accessRulesApiClient.cjs +0 -0
  26. package/dist/cjs/api/delete/.export.cjs +0 -1
  27. package/dist/cjs/api/delete/deleteAllRules.cjs +22 -24
  28. package/dist/cjs/api/delete/deleteRuleGroups.cjs +39 -51
  29. package/dist/cjs/api/delete/deleteRules.cjs +41 -42
  30. package/dist/cjs/api/read/.export.cjs +0 -1
  31. package/dist/cjs/api/read/fetchRules.cjs +34 -41
  32. package/dist/cjs/api/read/findRuleIds.cjs +37 -48
  33. package/dist/cjs/api/read/getMissingIds.cjs +36 -39
  34. package/dist/cjs/api/ruleApiRoutes.cjs +69 -125
  35. package/dist/cjs/api/rulesApiClient.cjs +54 -90
  36. package/dist/cjs/api/write/.export.cjs +0 -1
  37. package/dist/cjs/api/write/insertRules.cjs +85 -103
  38. package/dist/cjs/api/write/rehashRules.cjs +48 -56
  39. package/dist/cjs/classifyOs.cjs +46 -26
  40. package/dist/cjs/mongoose/.export.cjs +2 -3
  41. package/dist/cjs/mongoose/mongooseRuleSchema.cjs +97 -36
  42. package/dist/cjs/redis/.export.cjs +4 -5
  43. package/dist/cjs/redis/reader/redisAggregate.cjs +59 -84
  44. package/dist/cjs/redis/reader/redisRulesQuery.cjs +74 -116
  45. package/dist/cjs/redis/reader/redisRulesReader.cjs +322 -503
  46. package/dist/cjs/redis/reader/redisRulesSplitQuery.cjs +94 -72
  47. package/dist/cjs/redis/redisClient.cjs +53 -58
  48. package/dist/cjs/redis/redisRuleIndex.cjs +93 -49
  49. package/dist/cjs/redis/redisRulesStorage.cjs +21 -30
  50. package/dist/cjs/redis/redisRulesWriter.cjs +86 -112
  51. package/dist/cjs/rule.cjs +8 -7
  52. package/dist/cjs/ruleInput/.export.cjs +7 -8
  53. package/dist/cjs/ruleInput/policyInput.cjs +36 -39
  54. package/dist/cjs/ruleInput/ruleInput.cjs +37 -42
  55. package/dist/cjs/ruleInput/userScopeInput.cjs +47 -55
  56. package/dist/cjs/ruleRecord.cjs +15 -22
  57. package/dist/cjs/rulesStorage.cjs +7 -6
  58. package/dist/cjs/transformRule.cjs +36 -70
  59. package/dist/classifyOs.js +48 -29
  60. package/dist/mongoose/.export.js +2 -3
  61. package/dist/mongoose/mongooseRuleSchema.js +99 -38
  62. package/dist/redis/.export.js +3 -5
  63. package/dist/redis/reader/redisAggregate.js +60 -86
  64. package/dist/redis/reader/redisRulesQuery.js +75 -118
  65. package/dist/redis/reader/redisRulesReader.js +312 -487
  66. package/dist/redis/reader/redisRulesSplitQuery.js +96 -75
  67. package/dist/redis/redisClient.js +54 -62
  68. package/dist/redis/redisRuleIndex.js +93 -58
  69. package/dist/redis/redisRulesStorage.js +21 -30
  70. package/dist/redis/redisRulesWriter.js +82 -113
  71. package/dist/rule.js +10 -10
  72. package/dist/ruleInput/.export.js +3 -7
  73. package/dist/ruleInput/policyInput.d.ts +52 -1
  74. package/dist/ruleInput/policyInput.d.ts.map +1 -1
  75. package/dist/ruleInput/policyInput.js +35 -41
  76. package/dist/ruleInput/policyInput.js.map +1 -1
  77. package/dist/ruleInput/ruleInput.d.ts.map +1 -1
  78. package/dist/ruleInput/ruleInput.js +36 -44
  79. package/dist/ruleInput/ruleInput.js.map +1 -1
  80. package/dist/ruleInput/userScopeInput.js +44 -55
  81. package/dist/ruleRecord.js +17 -27
  82. package/dist/rulesStorage.js +9 -8
  83. package/dist/tests/policyInput.unit.test.js +50 -1
  84. package/dist/tests/policyInput.unit.test.js.map +1 -1
  85. package/dist/tests/redis/redisRulesStorage.integration.test.js +22 -3
  86. package/dist/tests/redis/redisRulesStorage.integration.test.js.map +1 -1
  87. package/dist/transformRule.js +34 -73
  88. package/dist/transformRule.js.map +1 -1
  89. package/entries.ts +25 -6
  90. package/package.json +13 -12
  91. package/src/ruleInput/policyInput.ts +45 -2
  92. package/src/ruleInput/ruleInput.ts +10 -3
  93. package/src/tests/policyInput.unit.test.ts +69 -1
  94. package/src/tests/redis/redisRulesStorage.integration.test.ts +191 -148
  95. package/src/transformRule.ts +2 -2
  96. package/tsconfig.tsbuildinfo +1 -1
@@ -1,117 +1,86 @@
1
- import { chunkIntoBatches, executeBatchesSequentially } from "@prosopo/common";
2
- import { REDIS_BATCH_SIZE } from "./redisClient.js";
1
+ import "../_virtual/_rolldown/runtime.js";
3
2
  import { GLOBAL_CLIENT_SCOPE_SENTINEL } from "../rule.js";
3
+ import { REDIS_BATCH_SIZE } from "./redisClient.js";
4
4
  import { ACCESS_RULE_REDIS_KEY_PREFIX, getAccessRuleRedisKey } from "./redisRuleIndex.js";
5
- class RedisRulesWriter {
6
- constructor(client, logger) {
7
- this.client = client;
8
- this.logger = logger;
9
- }
10
- async insertRules(ruleEntries) {
11
- const entryBatches = chunkIntoBatches(ruleEntries, REDIS_BATCH_SIZE);
12
- const keyBatches = await executeBatchesSequentially(
13
- entryBatches,
14
- async (entriesBatch) => this.insertRuleEntries(entriesBatch)
15
- );
16
- return keyBatches.flatMap(
17
- (ruleKey) => ruleKey.slice(ACCESS_RULE_REDIS_KEY_PREFIX.length)
18
- );
19
- }
20
- async deleteRules(ruleIds) {
21
- const ruleKeys = ruleIds.map(
22
- (ruleId) => ACCESS_RULE_REDIS_KEY_PREFIX + ruleId
23
- );
24
- const keyBatches = chunkIntoBatches(ruleKeys, REDIS_BATCH_SIZE);
25
- await executeBatchesSequentially(keyBatches, async (keysBatch) => {
26
- const queries = this.client.multi();
27
- for (const ruleKey of keysBatch) {
28
- queries.del(ruleKey);
29
- }
30
- await queries.exec();
31
- });
32
- }
33
- async deleteAllRules() {
34
- let cursor = "0";
35
- let total = 0;
36
- do {
37
- const reply = await this.client.scan(cursor, {
38
- MATCH: `${ACCESS_RULE_REDIS_KEY_PREFIX}*`,
39
- COUNT: REDIS_BATCH_SIZE
40
- });
41
- const ids = reply.keys.map(
42
- (key) => key.slice(ACCESS_RULE_REDIS_KEY_PREFIX.length)
43
- );
44
- await this.deleteRules(ids);
45
- total += ids.length;
46
- cursor = reply.cursor;
47
- } while ("0" !== cursor);
48
- return total;
49
- }
50
- async insertRuleEntries(ruleEntries) {
51
- const queries = this.client.multi();
52
- const ruleKeys = ruleEntries.map((ruleEntry) => {
53
- const { rule, expiresUnixTimestamp } = ruleEntry;
54
- const ruleKey = getAccessRuleRedisKey(rule);
55
- const ruleValue = getRedisRuleValue(rule);
56
- queries.hSet(ruleKey, ruleValue);
57
- if (expiresUnixTimestamp) {
58
- const MILLISECOND_THRESHOLD = 1e10;
59
- if (expiresUnixTimestamp > MILLISECOND_THRESHOLD) {
60
- throw new Error(
61
- `Invalid expiry timestamp: ${expiresUnixTimestamp}. Timestamp must be in seconds, not milliseconds.`
62
- );
63
- }
64
- queries.expireAt(ruleKey, expiresUnixTimestamp);
65
- }
66
- return ruleKey;
67
- });
68
- await queries.exec();
69
- return ruleKeys;
70
- }
71
- }
72
- const getRedisRuleValue = (rule) => {
73
- const record = {};
74
- for (const [key, value] of Object.entries(rule)) {
75
- if (value === void 0) {
76
- continue;
77
- }
78
- record[key] = String(value);
79
- }
80
- if (record.clientId === void 0) {
81
- record.clientId = GLOBAL_CLIENT_SCOPE_SENTINEL;
82
- }
83
- return record;
5
+ import { chunkIntoBatches, executeBatchesSequentially } from "@prosopo/common";
6
+ //#region src/redis/redisRulesWriter.ts
7
+ var RedisRulesWriter = class {
8
+ constructor(client, logger) {
9
+ this.client = client;
10
+ this.logger = logger;
11
+ }
12
+ async insertRules(ruleEntries) {
13
+ return (await executeBatchesSequentially(chunkIntoBatches(ruleEntries, REDIS_BATCH_SIZE), async (entriesBatch) => this.insertRuleEntries(entriesBatch))).flatMap((ruleKey) => ruleKey.slice(ACCESS_RULE_REDIS_KEY_PREFIX.length));
14
+ }
15
+ async deleteRules(ruleIds) {
16
+ await executeBatchesSequentially(chunkIntoBatches(ruleIds.map((ruleId) => ACCESS_RULE_REDIS_KEY_PREFIX + ruleId), REDIS_BATCH_SIZE), async (keysBatch) => {
17
+ const queries = this.client.multi();
18
+ for (const ruleKey of keysBatch) queries.del(ruleKey);
19
+ await queries.exec();
20
+ });
21
+ }
22
+ async deleteAllRules() {
23
+ let cursor = "0";
24
+ let total = 0;
25
+ do {
26
+ const reply = await this.client.scan(cursor, {
27
+ MATCH: `${ACCESS_RULE_REDIS_KEY_PREFIX}*`,
28
+ COUNT: REDIS_BATCH_SIZE
29
+ });
30
+ const ids = reply.keys.map((key) => key.slice(ACCESS_RULE_REDIS_KEY_PREFIX.length));
31
+ await this.deleteRules(ids);
32
+ total += ids.length;
33
+ cursor = reply.cursor;
34
+ } while ("0" !== cursor);
35
+ return total;
36
+ }
37
+ async insertRuleEntries(ruleEntries) {
38
+ const queries = this.client.multi();
39
+ const ruleKeys = ruleEntries.map((ruleEntry) => {
40
+ const { rule, expiresUnixTimestamp } = ruleEntry;
41
+ const ruleKey = getAccessRuleRedisKey(rule);
42
+ const ruleValue = getRedisRuleValue(rule);
43
+ queries.hSet(ruleKey, ruleValue);
44
+ if (expiresUnixTimestamp) {
45
+ if (expiresUnixTimestamp > 1e10) throw new Error(`Invalid expiry timestamp: ${expiresUnixTimestamp}. Timestamp must be in seconds, not milliseconds.`);
46
+ queries.expireAt(ruleKey, expiresUnixTimestamp);
47
+ }
48
+ return ruleKey;
49
+ });
50
+ await queries.exec();
51
+ return ruleKeys;
52
+ }
53
+ };
54
+ var getRedisRuleValue = (rule) => {
55
+ const record = {};
56
+ for (const [key, value] of Object.entries(rule)) {
57
+ if (value === void 0) continue;
58
+ record[key] = String(value);
59
+ }
60
+ if (record.clientId === void 0) record.clientId = GLOBAL_CLIENT_SCOPE_SENTINEL;
61
+ return record;
84
62
  };
85
- class DummyRedisRulesWriter {
86
- constructor(logger) {
87
- this.logger = logger;
88
- }
89
- async insertRules(ruleEntries) {
90
- this.logger.info(() => ({
91
- msg: "Dummy insertRules() has no effect (redis is not ready)",
92
- data: {
93
- ruleEntries
94
- }
95
- }));
96
- return [];
97
- }
98
- async deleteRules(ruleIds) {
99
- this.logger.info(() => ({
100
- msg: "Dummy deleteRules() has no effect (redis is not ready)",
101
- data: {
102
- ruleIds
103
- }
104
- }));
105
- }
106
- async deleteAllRules() {
107
- this.logger.info(() => ({
108
- msg: "Dummy deleteAllRules() has no effect (redis is not ready)"
109
- }));
110
- return 0;
111
- }
112
- }
113
- export {
114
- DummyRedisRulesWriter,
115
- RedisRulesWriter,
116
- getRedisRuleValue
63
+ var DummyRedisRulesWriter = class {
64
+ constructor(logger) {
65
+ this.logger = logger;
66
+ }
67
+ async insertRules(ruleEntries) {
68
+ this.logger.info(() => ({
69
+ msg: "Dummy insertRules() has no effect (redis is not ready)",
70
+ data: { ruleEntries }
71
+ }));
72
+ return [];
73
+ }
74
+ async deleteRules(ruleIds) {
75
+ this.logger.info(() => ({
76
+ msg: "Dummy deleteRules() has no effect (redis is not ready)",
77
+ data: { ruleIds }
78
+ }));
79
+ }
80
+ async deleteAllRules() {
81
+ this.logger.info(() => ({ msg: "Dummy deleteAllRules() has no effect (redis is not ready)" }));
82
+ return 0;
83
+ }
117
84
  };
85
+ //#endregion
86
+ export { DummyRedisRulesWriter, RedisRulesWriter, getRedisRuleValue };
package/dist/rule.js CHANGED
@@ -1,10 +1,10 @@
1
- var AccessPolicyType = /* @__PURE__ */ ((AccessPolicyType2) => {
2
- AccessPolicyType2["Block"] = "block";
3
- AccessPolicyType2["Restrict"] = "restrict";
4
- return AccessPolicyType2;
5
- })(AccessPolicyType || {});
6
- const GLOBAL_CLIENT_SCOPE_SENTINEL = "global";
7
- export {
8
- AccessPolicyType,
9
- GLOBAL_CLIENT_SCOPE_SENTINEL
10
- };
1
+ import "./_virtual/_rolldown/runtime.js";
2
+ //#region src/rule.ts
3
+ var AccessPolicyType = /* @__PURE__ */ function(AccessPolicyType) {
4
+ AccessPolicyType["Block"] = "block";
5
+ AccessPolicyType["Restrict"] = "restrict";
6
+ return AccessPolicyType;
7
+ }({});
8
+ var GLOBAL_CLIENT_SCOPE_SENTINEL = "global";
9
+ //#endregion
10
+ export { AccessPolicyType, GLOBAL_CLIENT_SCOPE_SENTINEL };
@@ -1,9 +1,5 @@
1
- import { accessRuleInput } from "./ruleInput.js";
1
+ import "../_virtual/_rolldown/runtime.js";
2
2
  import { accessPolicyInput, policyScopeInput } from "./policyInput.js";
3
3
  import { userScopeInput } from "./userScopeInput.js";
4
- export {
5
- accessPolicyInput,
6
- accessRuleInput,
7
- policyScopeInput,
8
- userScopeInput
9
- };
4
+ import { accessRuleInput } from "./ruleInput.js";
5
+ export { accessPolicyInput, accessRuleInput, policyScopeInput, userScopeInput };
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { type AccessPolicy, AccessPolicyType } from "#policy/rule.js";
3
- export declare const accessPolicyInput: z.ZodObject<{
3
+ export declare const accessPolicyInputShape: z.ZodObject<{
4
4
  type: z.ZodNativeEnum<typeof AccessPolicyType>;
5
5
  captchaType: z.ZodOptional<z.ZodNativeEnum<typeof import("@prosopo/types").CaptchaType>>;
6
6
  description: z.ZodOptional<z.ZodString>;
@@ -31,6 +31,57 @@ export declare const accessPolicyInput: z.ZodObject<{
31
31
  frictionlessScore?: number | undefined;
32
32
  deferToVerify?: unknown;
33
33
  }>;
34
+ export declare const accessPolicyInput: z.ZodEffects<z.ZodObject<{
35
+ type: z.ZodNativeEnum<typeof AccessPolicyType>;
36
+ captchaType: z.ZodOptional<z.ZodNativeEnum<typeof import("@prosopo/types").CaptchaType>>;
37
+ description: z.ZodOptional<z.ZodString>;
38
+ solvedImagesCount: z.ZodOptional<z.ZodNumber>;
39
+ imageThreshold: z.ZodOptional<z.ZodNumber>;
40
+ powDifficulty: z.ZodOptional<z.ZodNumber>;
41
+ unsolvedImagesCount: z.ZodOptional<z.ZodNumber>;
42
+ frictionlessScore: z.ZodOptional<z.ZodNumber>;
43
+ deferToVerify: z.ZodOptional<z.ZodEffects<z.ZodBoolean, boolean, unknown>>;
44
+ }, "strip", z.ZodTypeAny, {
45
+ type: AccessPolicyType;
46
+ captchaType?: import("@prosopo/types").CaptchaType | undefined;
47
+ description?: string | undefined;
48
+ solvedImagesCount?: number | undefined;
49
+ imageThreshold?: number | undefined;
50
+ powDifficulty?: number | undefined;
51
+ unsolvedImagesCount?: number | undefined;
52
+ frictionlessScore?: number | undefined;
53
+ deferToVerify?: boolean | undefined;
54
+ }, {
55
+ type: AccessPolicyType;
56
+ captchaType?: import("@prosopo/types").CaptchaType | undefined;
57
+ description?: string | undefined;
58
+ solvedImagesCount?: number | undefined;
59
+ imageThreshold?: number | undefined;
60
+ powDifficulty?: number | undefined;
61
+ unsolvedImagesCount?: number | undefined;
62
+ frictionlessScore?: number | undefined;
63
+ deferToVerify?: unknown;
64
+ }>, {
65
+ type: AccessPolicyType;
66
+ captchaType?: import("@prosopo/types").CaptchaType | undefined;
67
+ description?: string | undefined;
68
+ solvedImagesCount?: number | undefined;
69
+ imageThreshold?: number | undefined;
70
+ powDifficulty?: number | undefined;
71
+ unsolvedImagesCount?: number | undefined;
72
+ frictionlessScore?: number | undefined;
73
+ deferToVerify?: boolean | undefined;
74
+ }, {
75
+ type: AccessPolicyType;
76
+ captchaType?: import("@prosopo/types").CaptchaType | undefined;
77
+ description?: string | undefined;
78
+ solvedImagesCount?: number | undefined;
79
+ imageThreshold?: number | undefined;
80
+ powDifficulty?: number | undefined;
81
+ unsolvedImagesCount?: number | undefined;
82
+ frictionlessScore?: number | undefined;
83
+ deferToVerify?: unknown;
84
+ }>;
34
85
  export declare const sanitizeAccessPolicy: (policy: AccessPolicy) => AccessPolicy;
35
86
  export declare const policyScopeInput: z.ZodObject<{
36
87
  clientId: z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, unknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"policyInput.d.ts","sourceRoot":"","sources":["../../src/ruleInput/policyInput.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACN,KAAK,YAAY,EACjB,gBAAgB,EAGhB,MAAM,iBAAiB,CAAC;AAOzB,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoBI,CAAC;AAGnC,eAAO,MAAM,oBAAoB,WAAY,YAAY,KAAG,YAM3D,CAAC;AAOF,eAAO,MAAM,gBAAgB;;;;;;EAUI,CAAC"}
1
+ {"version":3,"file":"policyInput.d.ts","sourceRoot":"","sources":["../../src/ruleInput/policyInput.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACN,KAAK,YAAY,EACjB,gBAAgB,EAGhB,MAAM,iBAAiB,CAAC;AAwBzB,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoBD,CAAC;AAEnC,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoB7B,CAAC;AAOF,eAAO,MAAM,oBAAoB,WAAY,YAAY,KAAG,YAM3D,CAAC;AAOF,eAAO,MAAM,gBAAgB;;;;;;EAUI,CAAC"}
@@ -1,45 +1,39 @@
1
- import { CaptchaTypeSchema } from "@prosopo/types";
1
+ import "../_virtual/_rolldown/runtime.js";
2
+ import { AccessPolicyType } from "../rule.js";
2
3
  import { z } from "zod";
3
- import { AccessPolicyType, GLOBAL_CLIENT_SCOPE_SENTINEL } from "../rule.js";
4
- const accessPolicyInput = z.object({
5
- type: z.nativeEnum(AccessPolicyType),
6
- captchaType: CaptchaTypeSchema.optional(),
7
- description: z.coerce.string().optional(),
8
- // Redis stores values as strings, so coerce is needed to parse properly
9
- solvedImagesCount: z.coerce.number().optional(),
10
- // the percentage of image panels that must be solved per image CAPTCHA
11
- imageThreshold: z.coerce.number().optional(),
12
- // the Proof-of-Work difficulty level
13
- powDifficulty: z.coerce.number().optional(),
14
- // the number of unsolved image CAPTCHA challenges to serve
15
- unsolvedImagesCount: z.coerce.number().optional(),
16
- // used to increase the user's score
17
- frictionlessScore: z.coerce.number().optional(),
18
- // Skip the request-time block middleware and only fire at verify.
19
- // Redis stores booleans as strings — preprocess so "true"/"false"
20
- // round-trip to the JS boolean the matcher expects.
21
- deferToVerify: z.preprocess((v) => typeof v === "string" ? v === "true" : v, z.boolean()).optional()
4
+ import { CaptchaTypeSchema } from "@prosopo/types";
5
+ //#region src/ruleInput/policyInput.ts
6
+ var accessPolicyInputShape = z.object({
7
+ type: z.nativeEnum(AccessPolicyType),
8
+ captchaType: CaptchaTypeSchema.optional(),
9
+ description: z.coerce.string().optional(),
10
+ solvedImagesCount: z.coerce.number().optional(),
11
+ imageThreshold: z.coerce.number().optional(),
12
+ powDifficulty: z.coerce.number().optional(),
13
+ unsolvedImagesCount: z.coerce.number().optional(),
14
+ frictionlessScore: z.coerce.number().optional(),
15
+ deferToVerify: z.preprocess((v) => typeof v === "string" ? v === "true" : v, z.boolean()).optional()
22
16
  });
23
- const sanitizeAccessPolicy = (policy) => {
24
- if (policy.type === AccessPolicyType.Block) {
25
- const { captchaType, solvedImagesCount, ...blockPolicy } = policy;
26
- return blockPolicy;
27
- }
28
- return policy;
29
- };
30
- const policyScopeInput = z.object({
31
- // `getRedisRuleValue` stamps a sentinel string on global rules so the
32
- // read-time query can probe `@clientId:{global}` cheaply. Undo the
33
- // stamp here so consumers (rankCandidateRules, response payloads,
34
- // tests) continue to see `undefined` for global rules — the mongoose
35
- // side and the API input side never emit the sentinel.
36
- clientId: z.preprocess(
37
- (v) => v === GLOBAL_CLIENT_SCOPE_SENTINEL ? void 0 : v,
38
- z.coerce.string().optional()
39
- )
17
+ var accessPolicyInput = accessPolicyInputShape.superRefine((policy, ctx) => {
18
+ if (policy.type !== AccessPolicyType.Block) return;
19
+ if (policy.captchaType !== void 0) ctx.addIssue({
20
+ code: z.ZodIssueCode.custom,
21
+ path: ["captchaType"],
22
+ message: "Block policies cannot pin a captchaType — Block always applies to every captcha type. Use a Restrict policy if you want to narrow the effect to one captcha type."
23
+ });
24
+ if (policy.solvedImagesCount !== void 0) ctx.addIssue({
25
+ code: z.ZodIssueCode.custom,
26
+ path: ["solvedImagesCount"],
27
+ message: "Block policies cannot set solvedImagesCount — the field only applies to Restrict policies that adjust image-captcha rounds."
28
+ });
40
29
  });
41
- export {
42
- accessPolicyInput,
43
- policyScopeInput,
44
- sanitizeAccessPolicy
30
+ var sanitizeAccessPolicy = (policy) => {
31
+ if (policy.type === AccessPolicyType.Block) {
32
+ const { captchaType, solvedImagesCount, ...blockPolicy } = policy;
33
+ return blockPolicy;
34
+ }
35
+ return policy;
45
36
  };
37
+ var policyScopeInput = z.object({ clientId: z.preprocess((v) => v === "global" ? void 0 : v, z.coerce.string().optional()) });
38
+ //#endregion
39
+ export { accessPolicyInput, accessPolicyInputShape, policyScopeInput, sanitizeAccessPolicy };
@@ -1 +1 @@
1
- {"version":3,"file":"policyInput.js","sourceRoot":"","sources":["../../src/ruleInput/policyInput.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAEN,gBAAgB,EAChB,4BAA4B,GAE5B,MAAM,iBAAiB,CAAC;AAOzB,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACzC,IAAI,EAAE,CAAC,CAAC,UAAU,CAAC,gBAAgB,CAAC;IACpC,WAAW,EAAE,iBAAiB,CAAC,QAAQ,EAAE;IACzC,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAEzC,iBAAiB,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAE/C,cAAc,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAE5C,aAAa,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAE3C,mBAAmB,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAEjD,iBAAiB,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAI/C,aAAa,EAAE,CAAC;SACd,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;SAC1E,QAAQ,EAAE;CACoB,CAAC,CAAC;AAGnC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,MAAoB,EAAgB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xD,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,YAAY,CAAC,EAAE,WAAW,EAAE,CAAC;CAC7B,CAAC;AAQF,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAYS,CAAC;AAE7C,eAAO,MAAM,6BAA6B,gBAC5B,sBAAsB,KACjC,iBAAiB,EAiBnB,CAAC"}
@@ -1,51 +1,43 @@
1
- import { z } from "zod";
1
+ import "../_virtual/_rolldown/runtime.js";
2
2
  import { FilterScopeMatch } from "../rulesStorage.js";
3
- import { policyScopeInput, accessPolicyInput } from "./policyInput.js";
3
+ import { accessPolicyInputShape, policyScopeInput } from "./policyInput.js";
4
4
  import { userScopeInput } from "./userScopeInput.js";
5
- const ruleGroupInput = z.object({
6
- groupId: z.coerce.string().optional(),
7
- ruleGroupId: z.coerce.string().optional()
8
- }).transform((ruleGroupInput2) => {
9
- const { ruleGroupId, ...ruleGroup } = ruleGroupInput2;
10
- if ("string" === typeof ruleGroupId) {
11
- ruleGroup.groupId = ruleGroupId;
12
- }
13
- return ruleGroup;
5
+ import { z } from "zod";
6
+ //#region src/ruleInput/ruleInput.ts
7
+ var ruleGroupInput = z.object({
8
+ groupId: z.coerce.string().optional(),
9
+ ruleGroupId: z.coerce.string().optional()
10
+ }).transform((ruleGroupInput) => {
11
+ const { ruleGroupId, ...ruleGroup } = ruleGroupInput;
12
+ if ("string" === typeof ruleGroupId) ruleGroup.groupId = ruleGroupId;
13
+ return ruleGroup;
14
14
  });
15
- const accessRuleInput = z.object({
16
- ...accessPolicyInput.shape,
17
- ...policyScopeInput.shape
15
+ var accessRuleInput = z.object({
16
+ ...accessPolicyInputShape.shape,
17
+ ...policyScopeInput.shape
18
18
  }).and(userScopeInput).and(ruleGroupInput).transform((ruleInput) => ruleInput);
19
- const ruleEntryInput = z.object({
20
- rule: accessRuleInput,
21
- expiresUnixTimestamp: z.coerce.number().optional()
19
+ var ruleEntryInput = z.object({
20
+ rule: accessRuleInput,
21
+ expiresUnixTimestamp: z.coerce.number().optional()
22
22
  });
23
- const accessRulesFilterInput = z.object({
24
- policyScope: policyScopeInput.optional(),
25
- policyScopes: z.array(policyScopeInput).optional(),
26
- policyScopeMatch: z.nativeEnum(FilterScopeMatch).default(FilterScopeMatch.Exact),
27
- userScope: userScopeInput.optional(),
28
- userScopeMatch: z.nativeEnum(FilterScopeMatch).default(FilterScopeMatch.Exact),
29
- groupId: z.string().optional(),
30
- blockOnly: z.boolean().optional()
23
+ var accessRulesFilterInput = z.object({
24
+ policyScope: policyScopeInput.optional(),
25
+ policyScopes: z.array(policyScopeInput).optional(),
26
+ policyScopeMatch: z.nativeEnum(FilterScopeMatch).default(FilterScopeMatch.Exact),
27
+ userScope: userScopeInput.optional(),
28
+ userScopeMatch: z.nativeEnum(FilterScopeMatch).default(FilterScopeMatch.Exact),
29
+ groupId: z.string().optional(),
30
+ blockOnly: z.boolean().optional()
31
31
  });
32
- const getAccessRuleFiltersFromInput = (filterInput) => {
33
- const { policyScopes, policyScope, ...filterBase } = filterInput;
34
- const allPolicyScopes = policyScopes || [];
35
- if (policyScope) {
36
- allPolicyScopes.push(policyScope);
37
- }
38
- if (allPolicyScopes.length > 0) {
39
- return allPolicyScopes.map((policyScope2) => ({
40
- ...filterBase,
41
- policyScope: policyScope2
42
- }));
43
- }
44
- return [filterBase];
45
- };
46
- export {
47
- accessRuleInput,
48
- accessRulesFilterInput,
49
- getAccessRuleFiltersFromInput,
50
- ruleEntryInput
32
+ var getAccessRuleFiltersFromInput = (filterInput) => {
33
+ const { policyScopes, policyScope, ...filterBase } = filterInput;
34
+ const allPolicyScopes = policyScopes || [];
35
+ if (policyScope) allPolicyScopes.push(policyScope);
36
+ if (allPolicyScopes.length > 0) return allPolicyScopes.map((policyScope) => ({
37
+ ...filterBase,
38
+ policyScope
39
+ }));
40
+ return [filterBase];
51
41
  };
42
+ //#endregion
43
+ export { accessRuleInput, accessRulesFilterInput, getAccessRuleFiltersFromInput, ruleEntryInput };
@@ -1 +1 @@
1
- {"version":3,"file":"ruleInput.js","sourceRoot":"","sources":["../../src/ruleInput/ruleInput.ts"],"names":[],"mappings":"AAeA,OAAO,EAAgB,CAAC,EAAE,MAAM,KAAK,CAAC;AAEtC,OAAO,EAGN,gBAAgB,GAChB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAuB,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAY1E,MAAM,cAAc,GAAG,CAAC;KACtB,MAAM,CAAC;IACP,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACrC,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACP,CAAC;KACnC,SAAS,CAAC,CAAC,cAA8B,EAAE,EAAE;IAC7C,MAAM,EAAE,WAAW,EAAE,GAAG,SAAS,EAAE,GAAG,cAAc,CAAC;IAErD,IAAI,QAAQ,KAAK,OAAO,WAAW,EAAE,CAAC;QACrC,SAAS,CAAC,OAAO,GAAG,WAAW,CAAC;IACjC,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC,CAAC,CAAC;AAOJ,MAAM,CAAC,MAAM,eAAe,GAA+C,CAAC;KAC1E,MAAM,CAAC;IACP,GAAG,iBAAiB,CAAC,KAAK;IAC1B,GAAG,gBAAgB,CAAC,KAAK;CACzB,CAAC;KACD,GAAG,CAAC,cAAc,CAAC;KACnB,GAAG,CAAC,cAAc,CAAC;KACnB,SAAS,CAAC,CAAC,SAA0B,EAAc,EAAE,CAAC,SAAS,CAAC,CAAC;AAEnE,MAAM,CAAC,MAAM,cAAc,GAC1B,CAAC,CA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AC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9C,WAAW,EAAE,gBAAgB,CAAC,QAAQ,EAAE;IACxC,YAAY,EAAE,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,QAAQ,EAAE;IAClD,gBAAgB,EAAE,CAAC;SACjB,UAAU,CAAC,gBAAgB,CAAC;SAC5B,OAAO,CAAC,gBAAgB,CAAC,KAAK,CAAC;IACjC,SAAS,EAAE,cAAc,CAAC,QAAQ,EAAE;IACpC,cAAc,EAAE,CAAC;SACf,UAAU,CAAC,gBAAgB,CAAC;SAC5B,OAAO,CAAC,gBAAgB,CAAC,KAAK,CAAC;IACjC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC9B,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CACS,CAAC,CAAC;AAE7C,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAC5C,WAAmC,EACb,EAAE;IACxB,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,UAAU,EAAE,GAAG,WAAW,CAAC;IAEjE,MAAM,eAAe,GAAG,YAAY,IAAI,EAAE,CAAC;IAE3C,IAAI,WAAW,EAAE,CAAC;QACjB,eAAe,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACnC,CAAC;IAED,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChC,OAAO,eAAe,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;YAC5C,GAAG,UAAU;YACb,WAAW;SACX,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,CAAC,UAAU,CAAC,CAAC;AACrB,CAAC,CAAC"}
@@ -1,63 +1,52 @@
1
+ import "../_virtual/_rolldown/runtime.js";
2
+ import { z } from "zod";
1
3
  import crypto from "node:crypto";
2
4
  import { getIPAddress } from "@prosopo/util";
3
5
  import { Address4, Address6 } from "ip-address";
4
- import { z } from "zod";
5
- const userAttributesSchema = z.object({
6
- // coerce is used for safety, as e.g., incoming userId can be digital
7
- userId: z.coerce.string().optional(),
8
- ja4Hash: z.coerce.string().optional(),
9
- headersHash: z.coerce.string().optional(),
10
- userAgentHash: z.coerce.string().optional(),
11
- headHash: z.coerce.string().optional(),
12
- coords: z.coerce.string().optional(),
13
- countryCode: z.coerce.string().optional(),
14
- asn: z.coerce.number().int().nonnegative().optional(),
15
- // Plain lowercase OS tag (see `classifyOs`). Loose `string` like
16
- // countryCode: a stale/unknown value just never matches a request rather
17
- // than failing the whole rule parse.
18
- os: z.coerce.string().optional()
6
+ //#region src/ruleInput/userScopeInput.ts
7
+ var userAttributesSchema = z.object({
8
+ userId: z.coerce.string().optional(),
9
+ ja4Hash: z.coerce.string().optional(),
10
+ headersHash: z.coerce.string().optional(),
11
+ userAgentHash: z.coerce.string().optional(),
12
+ headHash: z.coerce.string().optional(),
13
+ coords: z.coerce.string().optional(),
14
+ countryCode: z.coerce.string().optional(),
15
+ asn: z.coerce.number().int().nonnegative().optional(),
16
+ os: z.coerce.string().optional()
19
17
  });
20
- const userAttributesInput = z.object({
21
- ...userAttributesSchema.shape,
22
- userAgent: z.coerce.string().optional()
23
- }).transform((userAttributesInput2) => {
24
- const { userAgent, ...userScope } = userAttributesInput2;
25
- if ("string" === typeof userAgent) {
26
- userScope.userAgentHash = hashUserAgent(userAgent);
27
- }
28
- return userScope;
18
+ var userAttributesInput = z.object({
19
+ ...userAttributesSchema.shape,
20
+ userAgent: z.coerce.string().optional()
21
+ }).transform((userAttributesInput) => {
22
+ const { userAgent, ...userScope } = userAttributesInput;
23
+ if ("string" === typeof userAgent) userScope.userAgentHash = hashUserAgent(userAgent);
24
+ return userScope;
29
25
  });
30
- const hashUserAgent = (userAgent) => crypto.createHash("sha256").update(userAgent).digest("hex");
31
- const userIpSchema = z.object({
32
- numericIp: z.coerce.bigint().optional(),
33
- numericIpMaskMin: z.coerce.bigint().optional(),
34
- numericIpMaskMax: z.coerce.bigint().optional()
26
+ var hashUserAgent = (userAgent) => crypto.createHash("sha256").update(userAgent).digest("hex");
27
+ var userIpSchema = z.object({
28
+ numericIp: z.coerce.bigint().optional(),
29
+ numericIpMaskMin: z.coerce.bigint().optional(),
30
+ numericIpMaskMax: z.coerce.bigint().optional()
35
31
  });
36
- const userIpInput = z.object({
37
- ...userIpSchema.shape,
38
- ip: z.string().optional(),
39
- ipMask: z.string().optional()
40
- }).transform((userIpInput2) => {
41
- const { ip, ipMask, ...numericUserIp } = userIpInput2;
42
- if ("string" === typeof ip) {
43
- numericUserIp.numericIp = getIPAddress(ip).bigInt();
44
- }
45
- if ("string" === typeof ipMask) {
46
- const ipObject = Address4.isValid(ipMask) ? new Address4(ipMask) : new Address6(ipMask);
47
- numericUserIp.numericIpMaskMin = ipObject.startAddress().bigInt();
48
- numericUserIp.numericIpMaskMax = ipObject.endAddress().bigInt();
49
- }
50
- return numericUserIp;
32
+ var userIpInput = z.object({
33
+ ...userIpSchema.shape,
34
+ ip: z.string().optional(),
35
+ ipMask: z.string().optional()
36
+ }).transform((userIpInput) => {
37
+ const { ip, ipMask, ...numericUserIp } = userIpInput;
38
+ if ("string" === typeof ip) numericUserIp.numericIp = getIPAddress(ip).bigInt();
39
+ if ("string" === typeof ipMask) {
40
+ const ipObject = Address4.isValid(ipMask) ? new Address4(ipMask) : new Address6(ipMask);
41
+ numericUserIp.numericIpMaskMin = ipObject.startAddress().bigInt();
42
+ numericUserIp.numericIpMaskMax = ipObject.endAddress().bigInt();
43
+ }
44
+ return numericUserIp;
51
45
  });
52
- const userScopeSchema = z.object({
53
- ...userIpSchema.shape,
54
- ...userAttributesSchema.shape
46
+ var userScopeSchema = z.object({
47
+ ...userIpSchema.shape,
48
+ ...userAttributesSchema.shape
55
49
  });
56
- const userScopeInput = z.object({}).and(userIpInput).and(userAttributesInput).transform(
57
- // transform is used for type safety only - plain "satisfies ZodType<x>" doesn't work after ".and()"
58
- (userScopeInput2) => userScopeInput2
59
- );
60
- export {
61
- userScopeInput,
62
- userScopeSchema
63
- };
50
+ var userScopeInput = z.object({}).and(userIpInput).and(userAttributesInput).transform((userScopeInput) => userScopeInput);
51
+ //#endregion
52
+ export { userScopeInput, userScopeSchema };