@prosopo/user-access-policy 3.14.14 → 3.14.16

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 (70) hide show
  1. package/.turbo/turbo-build$colon$cjs.log +3 -6
  2. package/.turbo/turbo-build$colon$tsc.log +14 -17
  3. package/.turbo/turbo-build.log +4 -10
  4. package/CHANGELOG.md +37 -0
  5. package/LICENSE +201 -0
  6. package/dist/cjs/ruleInput/policyInput.cjs +1 -1
  7. package/dist/ruleInput/policyInput.d.ts +2 -2
  8. package/dist/ruleInput/policyInput.d.ts.map +1 -1
  9. package/dist/ruleInput/policyInput.js +2 -2
  10. package/dist/ruleInput/policyInput.js.map +1 -1
  11. package/package.json +83 -81
  12. package/src/.export.ts +0 -65
  13. package/src/api/.export.ts +0 -25
  14. package/src/api/accessRulesApiClient.ts +0 -13
  15. package/src/api/delete/.export.ts +0 -18
  16. package/src/api/delete/deleteAllRules.ts +0 -47
  17. package/src/api/delete/deleteRuleGroups.ts +0 -96
  18. package/src/api/delete/deleteRules.ts +0 -87
  19. package/src/api/read/.export.ts +0 -25
  20. package/src/api/read/fetchRules.ts +0 -96
  21. package/src/api/read/findRuleIds.ts +0 -97
  22. package/src/api/read/getMissingIds.ts +0 -81
  23. package/src/api/ruleApiRoutes.ts +0 -146
  24. package/src/api/rulesApiClient.ts +0 -154
  25. package/src/api/write/.export.ts +0 -15
  26. package/src/api/write/insertRules.ts +0 -185
  27. package/src/api/write/rehashRules.ts +0 -85
  28. package/src/classifyBrowser.ts +0 -77
  29. package/src/classifyOs.ts +0 -74
  30. package/src/headerMatch.ts +0 -180
  31. package/src/matchedRule.ts +0 -99
  32. package/src/mongoose/.export.ts +0 -15
  33. package/src/mongoose/mongooseRuleSchema.ts +0 -75
  34. package/src/redis/.export.ts +0 -17
  35. package/src/redis/reader/redisAggregate.ts +0 -157
  36. package/src/redis/reader/redisRulesQuery.ts +0 -268
  37. package/src/redis/reader/redisRulesReader.ts +0 -738
  38. package/src/redis/reader/redisRulesSplitQuery.ts +0 -234
  39. package/src/redis/redisClient.ts +0 -125
  40. package/src/redis/redisRuleIndex.ts +0 -121
  41. package/src/redis/redisRulesStorage.ts +0 -68
  42. package/src/redis/redisRulesWriter.ts +0 -172
  43. package/src/rule.ts +0 -122
  44. package/src/ruleInput/.export.ts +0 -19
  45. package/src/ruleInput/policyInput.ts +0 -120
  46. package/src/ruleInput/ruleInput.ts +0 -123
  47. package/src/ruleInput/userScopeInput.ts +0 -142
  48. package/src/ruleRecord.ts +0 -77
  49. package/src/rulesStorage.ts +0 -90
  50. package/src/tests/blockingRuleShapes.unit.test.ts +0 -244
  51. package/src/tests/classifyBrowser.unit.test.ts +0 -138
  52. package/src/tests/classifyOs.unit.test.ts +0 -97
  53. package/src/tests/headerMatch.unit.test.ts +0 -350
  54. package/src/tests/insertRulesEndpoint.unit.test.ts +0 -89
  55. package/src/tests/matchedRule.unit.test.ts +0 -184
  56. package/src/tests/policyInput.unit.test.ts +0 -218
  57. package/src/tests/redis/deferredPoolClause.benchmark.ts +0 -249
  58. package/src/tests/redis/reader/redisAggregate.unit.test.ts +0 -121
  59. package/src/tests/redis/reader/redisRulesQuery.unit.test.ts +0 -349
  60. package/src/tests/redis/reader/redisRulesSplitQuery.unit.test.ts +0 -297
  61. package/src/tests/redis/redisRulesReaderLoad.benchmark.integration.test.ts +0 -520
  62. package/src/tests/redis/redisRulesReaderRank.benchmark.integration.test.ts +0 -350
  63. package/src/tests/redis/redisRulesStorage.integration.test.ts +0 -1811
  64. package/src/tests/testLogger.ts +0 -38
  65. package/src/tests/transformRule.unit.test.ts +0 -345
  66. package/src/transformRule.ts +0 -133
  67. package/tsconfig.cjs.json +0 -41
  68. package/tsconfig.json +0 -47
  69. package/tsconfig.tsbuildinfo +0 -1
  70. package/tsconfig.types.json +0 -9
package/src/.export.ts DELETED
@@ -1,65 +0,0 @@
1
- // Copyright 2021-2026 Prosopo (UK) Ltd.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- export * from "./ruleInput/.export.js";
16
-
17
- export {
18
- makeAccessRuleHash,
19
- transformAccessRuleRecordIntoRule,
20
- transformAccessRuleIntoRecord,
21
- } from "./transformRule.js";
22
-
23
- export {
24
- type AccessRule,
25
- type AccessPolicy,
26
- type PolicyScope,
27
- type UserScope,
28
- AccessPolicyType,
29
- } from "./rule.js";
30
-
31
- export { describeMatchedRule } from "./matchedRule.js";
32
-
33
- export { classifyOs, OS_NAMES, type OsName } from "./classifyOs.js";
34
-
35
- export {
36
- classifyBrowser,
37
- BROWSER_NAMES,
38
- type BrowserName,
39
- } from "./classifyBrowser.js";
40
-
41
- export {
42
- HEADER_OPERATORS,
43
- type HeaderOperator,
44
- HEADER_RULE_MARKER,
45
- isHeaderOperator,
46
- evaluateHeaderCondition,
47
- accessRuleHeaderMatches,
48
- encodeHeaderValueList,
49
- decodeHeaderValueList,
50
- } from "./headerMatch.js";
51
-
52
- export {
53
- type AccessRulesFilter,
54
- type AccessRulesStorage,
55
- type AccessRuleEntry,
56
- FilterScopeMatch,
57
- } from "./rulesStorage.js";
58
-
59
- export {
60
- type AccessRuleRecord,
61
- type UserScopeRecord,
62
- type UserScopeRecordField,
63
- userScopeRecordFields,
64
- getUserScopeRecordFromAccessRuleRecord,
65
- } from "./ruleRecord.js";
@@ -1,25 +0,0 @@
1
- // Copyright 2021-2026 Prosopo (UK) Ltd.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- export * from "./delete/.export.js";
16
- export * from "./read/.export.js";
17
- export * from "./write/.export.js";
18
-
19
- export {
20
- accessRuleApiPaths,
21
- getExpressApiRuleRateLimits,
22
- } from "./ruleApiRoutes.js";
23
-
24
- export { AccessRulesApiClient } from "./rulesApiClient.js";
25
- export { AccessRuleApiRoutes } from "./ruleApiRoutes.js";
@@ -1,13 +0,0 @@
1
- // Copyright 2021-2026 Prosopo (UK) Ltd.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
@@ -1,18 +0,0 @@
1
- // Copyright 2021-2026 Prosopo (UK) Ltd.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- export type {
16
- DeleteSiteGroup,
17
- DeleteSiteGroups,
18
- } from "./deleteRuleGroups.js";
@@ -1,47 +0,0 @@
1
- // Copyright 2021-2026 Prosopo (UK) Ltd.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import {
16
- type ApiEndpoint,
17
- type ApiEndpointResponse,
18
- ApiEndpointResponseStatus,
19
- } from "@prosopo/api-route";
20
- import type { Logger } from "@prosopo/logger";
21
- import type { AccessRulesStorage } from "#policy/rulesStorage.js";
22
-
23
- export class DeleteAllRulesEndpoint implements ApiEndpoint<undefined> {
24
- public constructor(
25
- private readonly accessRulesStorage: AccessRulesStorage,
26
- private readonly logger: Logger,
27
- ) {}
28
-
29
- public getRequestArgsSchema(): undefined {}
30
-
31
- async processRequest(logger?: Logger): Promise<ApiEndpointResponse> {
32
- const log = logger ?? this.logger;
33
- const deletedCount = await this.accessRulesStorage.deleteAllRules();
34
-
35
- log.info(() => ({
36
- msg: "Endpoint deleted all access rules",
37
- data: { deletedCount },
38
- }));
39
-
40
- return {
41
- status: ApiEndpointResponseStatus.SUCCESS,
42
- data: {
43
- deleted_count: deletedCount,
44
- },
45
- };
46
- }
47
- }
@@ -1,96 +0,0 @@
1
- // Copyright 2021-2026 Prosopo (UK) Ltd.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import {
16
- type ApiEndpoint,
17
- type ApiEndpointResponse,
18
- ApiEndpointResponseStatus,
19
- } from "@prosopo/api-route";
20
- import type { AllKeys } from "@prosopo/common";
21
- import type { Logger } from "@prosopo/logger";
22
- import { type ZodType, z } from "zod";
23
- import {
24
- type AccessRulesStorage,
25
- FilterScopeMatch,
26
- } from "#policy/rulesStorage.js";
27
-
28
- export type DeleteSiteGroup = {
29
- clientIds: string[];
30
- groupId: string;
31
- };
32
-
33
- export type DeleteSiteGroups = DeleteSiteGroup[];
34
-
35
- type DeleteRuleGroupsSchema = ZodType<DeleteSiteGroups>;
36
-
37
- export class DeleteRuleGroupsEndpoint
38
- implements ApiEndpoint<DeleteRuleGroupsSchema>
39
- {
40
- public constructor(
41
- private readonly accessRulesStorage: AccessRulesStorage,
42
- private readonly logger: Logger,
43
- ) {}
44
-
45
- public getRequestArgsSchema(): DeleteRuleGroupsSchema {
46
- return z.array(
47
- z.object({
48
- clientIds: z.string().array(),
49
- groupId: z.string(),
50
- } satisfies AllKeys<DeleteSiteGroup>),
51
- );
52
- }
53
-
54
- async processRequest(
55
- args: DeleteSiteGroups,
56
- logger?: Logger,
57
- ): Promise<ApiEndpointResponse> {
58
- const log = logger ?? this.logger;
59
- const foundRuleIdPromises = args.flatMap((ruleToDelete) =>
60
- ruleToDelete.clientIds.map((clientId) =>
61
- this.accessRulesStorage.findRuleIds({
62
- policyScope: {
63
- clientId: clientId,
64
- },
65
- policyScopeMatch: FilterScopeMatch.Exact,
66
- groupId: ruleToDelete.groupId,
67
- }),
68
- ),
69
- );
70
-
71
- const foundRuleIds = await Promise.all(foundRuleIdPromises);
72
- const ruleIds = foundRuleIds.flat();
73
-
74
- // Set() automatically removes duplicates
75
- const uniqueRuleIds = [...new Set(ruleIds)];
76
-
77
- if (uniqueRuleIds.length > 0) {
78
- await this.accessRulesStorage.deleteRules(uniqueRuleIds);
79
- }
80
-
81
- log.info(() => ({
82
- msg: "Endpoint deleted rule groups",
83
- data: {
84
- args,
85
- uniqueRuleIds,
86
- },
87
- }));
88
-
89
- return {
90
- status: ApiEndpointResponseStatus.SUCCESS,
91
- data: {
92
- deleted_count: uniqueRuleIds.length,
93
- },
94
- };
95
- }
96
- }
@@ -1,87 +0,0 @@
1
- // Copyright 2021-2026 Prosopo (UK) Ltd.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import {
16
- type ApiEndpoint,
17
- type ApiEndpointResponse,
18
- ApiEndpointResponseStatus,
19
- } from "@prosopo/api-route";
20
- import { executeBatchesSequentially } from "@prosopo/common";
21
- import type { Logger } from "@prosopo/logger";
22
- import { type ZodType, z } from "zod";
23
- import {
24
- type AccessRulesFilterInput,
25
- accessRulesFilterInput,
26
- getAccessRuleFiltersFromInput,
27
- } from "#policy/ruleInput/ruleInput.js";
28
- import type { AccessRulesStorage } from "#policy/rulesStorage.js";
29
-
30
- // `unknown` input position — see accessRulesFilterInput's block comment
31
- // for why the strict-identity form doesn't fit here.
32
- type DeleteRulesSchema = ZodType<
33
- AccessRulesFilterInput[],
34
- z.ZodTypeDef,
35
- unknown
36
- >;
37
-
38
- export class DeleteRulesEndpoint implements ApiEndpoint<DeleteRulesSchema> {
39
- public constructor(
40
- private readonly accessRulesStorage: AccessRulesStorage,
41
- private readonly logger: Logger,
42
- ) {}
43
-
44
- public getRequestArgsSchema(): DeleteRulesSchema {
45
- return z.array(accessRulesFilterInput);
46
- }
47
-
48
- async processRequest(
49
- args: AccessRulesFilterInput[],
50
- logger?: Logger,
51
- ): Promise<ApiEndpointResponse> {
52
- const log = logger ?? this.logger;
53
- let deletedCount = 0;
54
-
55
- for (const rulesFilterInput of args) {
56
- const ruleFilters = getAccessRuleFiltersFromInput(rulesFilterInput);
57
-
58
- await executeBatchesSequentially(ruleFilters, async (ruleFilter) => {
59
- const ruleIds = await this.accessRulesStorage.findRuleIds(ruleFilter);
60
-
61
- // Set() automatically removes duplicates
62
- const uniqueRuleIds = [...new Set(ruleIds)];
63
-
64
- if (uniqueRuleIds.length > 0) {
65
- await this.accessRulesStorage.deleteRules(uniqueRuleIds);
66
-
67
- deletedCount += uniqueRuleIds.length;
68
-
69
- log.info(() => ({
70
- msg: "Endpoint deleted rules",
71
- data: {
72
- rulesFilterInput,
73
- uniqueRuleIds,
74
- },
75
- }));
76
- }
77
- });
78
- }
79
-
80
- return {
81
- status: ApiEndpointResponseStatus.SUCCESS,
82
- data: {
83
- deleted_count: deletedCount,
84
- },
85
- };
86
- }
87
- }
@@ -1,25 +0,0 @@
1
- // Copyright 2021-2026 Prosopo (UK) Ltd.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- export type {
16
- RuleIdsResponse,
17
- RuleIdsEndpointResponse,
18
- } from "./findRuleIds.js";
19
-
20
- export type {
21
- FetchRulesOptions,
22
- FetchRulesResponse,
23
- } from "./fetchRules.js";
24
-
25
- export type { MissingIds } from "./getMissingIds.js";
@@ -1,96 +0,0 @@
1
- // Copyright 2021-2026 Prosopo (UK) Ltd.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import {
16
- type ApiEndpoint,
17
- type ApiEndpointResponse,
18
- ApiEndpointResponseStatus,
19
- } from "@prosopo/api-route";
20
- import type { AllKeys } from "@prosopo/common";
21
- import type { Logger } from "@prosopo/logger";
22
- import { type ZodType, z } from "zod";
23
- import { ruleEntryInput } from "#policy/ruleInput/ruleInput.js";
24
- import type {
25
- AccessRuleEntry,
26
- AccessRulesStorage,
27
- } from "#policy/rulesStorage.js";
28
-
29
- export type FetchRulesOptions = {
30
- ids: string[];
31
- };
32
-
33
- type FetchRulesSchema = ZodType<FetchRulesOptions>;
34
-
35
- export type FetchRulesResponse = {
36
- ruleEntries: AccessRuleEntry[];
37
- };
38
-
39
- // Explicit annotation with `unknown` input position rather than the
40
- // strict identity form because `ruleEntryInput.rule` transitively uses
41
- // `z.preprocess` on `deferToVerify`. Required for portable declaration
42
- // emit; the `AllKeys<...>` constraint still catches missing fields.
43
- export const fetchRulesResponse: ZodType<
44
- FetchRulesResponse,
45
- z.ZodTypeDef,
46
- unknown
47
- > = z.object({
48
- ruleEntries: ruleEntryInput.array(),
49
- } satisfies AllKeys<FetchRulesResponse>);
50
-
51
- export type FetchRulesEndpointResponse = ApiEndpointResponse & {
52
- data?: FetchRulesResponse;
53
- };
54
-
55
- export class FetchRulesEndpoint implements ApiEndpoint<FetchRulesSchema> {
56
- public constructor(
57
- private readonly accessRulesStorage: AccessRulesStorage,
58
- private readonly logger: Logger,
59
- ) {}
60
-
61
- public getRequestArgsSchema(): FetchRulesSchema {
62
- return z.object({
63
- ids: z.string().array(),
64
- } satisfies AllKeys<FetchRulesOptions>);
65
- }
66
-
67
- async processRequest(
68
- args: FetchRulesOptions,
69
- logger?: Logger,
70
- ): Promise<FetchRulesEndpointResponse> {
71
- const log = logger ?? this.logger;
72
- const ruleEntries = await this.accessRulesStorage.fetchRules(args.ids);
73
-
74
- log.info(() => ({
75
- msg: "Endpoint fetched rules",
76
- data: {
77
- requestedCount: args.ids.length,
78
- foundCount: ruleEntries.length,
79
- },
80
- }));
81
-
82
- log.debug(() => ({
83
- msg: "Fetched rule details",
84
- data: {
85
- ruleEntries: ruleEntries,
86
- },
87
- }));
88
-
89
- return {
90
- status: ApiEndpointResponseStatus.SUCCESS,
91
- data: {
92
- ruleEntries: ruleEntries,
93
- },
94
- };
95
- }
96
- }
@@ -1,97 +0,0 @@
1
- // Copyright 2021-2026 Prosopo (UK) Ltd.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import {
16
- type ApiEndpoint,
17
- type ApiEndpointResponse,
18
- ApiEndpointResponseStatus,
19
- } from "@prosopo/api-route";
20
- import { type AllKeys, executeBatchesSequentially } from "@prosopo/common";
21
- import type { Logger } from "@prosopo/logger";
22
- import { type ZodType, z } from "zod";
23
- import {
24
- type AccessRulesFilterInput,
25
- accessRulesFilterInput,
26
- getAccessRuleFiltersFromInput,
27
- } from "#policy/ruleInput/ruleInput.js";
28
- import type { AccessRulesStorage } from "#policy/rulesStorage.js";
29
-
30
- // `unknown` input position — see accessRulesFilterInput's block comment
31
- // for why the strict-identity form doesn't fit here.
32
- type FindRulesSchema = ZodType<AccessRulesFilterInput[], z.ZodTypeDef, unknown>;
33
-
34
- export type RuleIdsResponse = {
35
- ruleIds: string[];
36
- };
37
-
38
- export const ruleIdsResponse = z.object({
39
- ruleIds: z.string().array(),
40
- } satisfies AllKeys<RuleIdsResponse>) satisfies ZodType<RuleIdsResponse>;
41
-
42
- export type RuleIdsEndpointResponse = ApiEndpointResponse & {
43
- data?: RuleIdsResponse;
44
- };
45
-
46
- export class FindRuleIdsEndpoint implements ApiEndpoint<FindRulesSchema> {
47
- public constructor(
48
- private readonly accessRulesStorage: AccessRulesStorage,
49
- private readonly logger: Logger,
50
- ) {}
51
-
52
- public getRequestArgsSchema(): FindRulesSchema {
53
- return z.array(accessRulesFilterInput);
54
- }
55
-
56
- async processRequest(
57
- args: AccessRulesFilterInput[],
58
- logger?: Logger,
59
- ): Promise<RuleIdsEndpointResponse> {
60
- const log = logger ?? this.logger;
61
- const ruleIdBatches = await executeBatchesSequentially(
62
- args,
63
- async (rulesFilterInput) => {
64
- const ruleFilters = getAccessRuleFiltersFromInput(rulesFilterInput);
65
-
66
- const ruleIds = await executeBatchesSequentially(
67
- ruleFilters,
68
- (ruleFilter) => this.accessRulesStorage.findRuleIds(ruleFilter),
69
- );
70
-
71
- return ruleIds.flat();
72
- },
73
- );
74
-
75
- const ruleIds = ruleIdBatches.flat();
76
-
77
- // Set() automatically removes duplicates
78
- const uniqueRuleIds = [...new Set(ruleIds)];
79
-
80
- log.info(() => ({
81
- msg: "Endpoint found rules",
82
- data: {
83
- totalFoundCount: ruleIds.length,
84
- uniqueFoundCount: uniqueRuleIds.length,
85
- searchFilters: args,
86
- foundIds: uniqueRuleIds,
87
- },
88
- }));
89
-
90
- return {
91
- status: ApiEndpointResponseStatus.SUCCESS,
92
- data: {
93
- ruleIds: uniqueRuleIds,
94
- },
95
- };
96
- }
97
- }
@@ -1,81 +0,0 @@
1
- // Copyright 2021-2026 Prosopo (UK) Ltd.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import {
16
- type ApiEndpoint,
17
- type ApiEndpointResponse,
18
- ApiEndpointResponseStatus,
19
- } from "@prosopo/api-route";
20
- import type { AllKeys } from "@prosopo/common";
21
- import type { Logger } from "@prosopo/logger";
22
- import { type ZodType, z } from "zod";
23
- import type { AccessRulesStorage } from "#policy/rulesStorage.js";
24
-
25
- export type MissingIds = string[];
26
-
27
- type MissingIdsSchema = ZodType<MissingIds>;
28
-
29
- export type MissingIdsResponse = {
30
- ids: string[];
31
- };
32
-
33
- export const missingIdsResponse = z.object({
34
- ids: z.string().array(),
35
- } satisfies AllKeys<MissingIdsResponse>) satisfies ZodType<MissingIdsResponse>;
36
-
37
- export type MissingIdsEndpointResponse = ApiEndpointResponse & {
38
- data?: MissingIdsResponse;
39
- };
40
-
41
- export class GetMissingIdsEndpoint implements ApiEndpoint<MissingIdsSchema> {
42
- public constructor(
43
- private readonly accessRulesStorage: AccessRulesStorage,
44
- private readonly logger: Logger,
45
- ) {}
46
-
47
- public getRequestArgsSchema(): MissingIdsSchema {
48
- return z.string().array();
49
- }
50
-
51
- async processRequest(
52
- args: MissingIds,
53
- logger?: Logger,
54
- ): Promise<MissingIdsEndpointResponse> {
55
- const log = logger ?? this.logger;
56
- const missingIds = await this.accessRulesStorage.getMissingRuleIds(args);
57
-
58
- log.info(() => ({
59
- msg: "Endpoint checked missing ids",
60
- data: {
61
- idsToCheck: args.length,
62
- missingIds: missingIds.length,
63
- },
64
- }));
65
-
66
- log.debug(() => ({
67
- msg: "Missing id details",
68
- data: {
69
- idsToCheck: args,
70
- missingIds: missingIds,
71
- },
72
- }));
73
-
74
- return {
75
- status: ApiEndpointResponseStatus.SUCCESS,
76
- data: {
77
- ids: missingIds,
78
- },
79
- };
80
- }
81
- }