@authup/access 1.0.0-beta.35 → 1.0.0-beta.37
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/dist/index.mjs +38 -39
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -395,11 +395,11 @@ var AttributesPolicyEvaluator = class {
|
|
|
395
395
|
this.validator = new AttributesPolicyValidator();
|
|
396
396
|
}
|
|
397
397
|
async accessData(ctx) {
|
|
398
|
-
if (!ctx.data.has(
|
|
399
|
-
if (ctx.data.isValidated(
|
|
400
|
-
const data = ctx.data.get(
|
|
401
|
-
ctx.data.set(
|
|
402
|
-
ctx.data.setValidated(
|
|
398
|
+
if (!ctx.data.has("attributes")) return null;
|
|
399
|
+
if (ctx.data.isValidated("attributes")) return ctx.data.get("attributes");
|
|
400
|
+
const data = ctx.data.get("attributes");
|
|
401
|
+
ctx.data.set("attributes", data);
|
|
402
|
+
ctx.data.setValidated("attributes");
|
|
403
403
|
return data;
|
|
404
404
|
}
|
|
405
405
|
async evaluate(value, ctx) {
|
|
@@ -408,7 +408,7 @@ var AttributesPolicyEvaluator = class {
|
|
|
408
408
|
if (!data) return {
|
|
409
409
|
success: false,
|
|
410
410
|
issues: [definePolicyIssueItem({
|
|
411
|
-
code:
|
|
411
|
+
code: "DATA_MISSING",
|
|
412
412
|
message: "The data property attributes is missing",
|
|
413
413
|
path: ctx.path
|
|
414
414
|
})]
|
|
@@ -452,7 +452,7 @@ var AttributeNamesPolicyEvaluator = class {
|
|
|
452
452
|
if (!data) return {
|
|
453
453
|
success: false,
|
|
454
454
|
issues: [definePolicyIssueItem({
|
|
455
|
-
code:
|
|
455
|
+
code: "DATA_MISSING",
|
|
456
456
|
message: "The data property attributes is missing",
|
|
457
457
|
path: ctx.path
|
|
458
458
|
})]
|
|
@@ -461,7 +461,7 @@ var AttributeNamesPolicyEvaluator = class {
|
|
|
461
461
|
const keys = Object.keys(attributes);
|
|
462
462
|
const issues = [];
|
|
463
463
|
for (const key of keys) if (policy.names.indexOf(key) === -1) issues.push(definePolicyIssueItem({
|
|
464
|
-
code:
|
|
464
|
+
code: "EVALUATION_DENIED",
|
|
465
465
|
message: `The attribute ${key} is not included`,
|
|
466
466
|
path: [...ctx.path, key]
|
|
467
467
|
}));
|
|
@@ -537,7 +537,7 @@ var CompositePolicyEvaluator = class {
|
|
|
537
537
|
//#endregion
|
|
538
538
|
//#region src/policy/built-in/composite/helper.ts
|
|
539
539
|
function isCompositePolicy(input) {
|
|
540
|
-
return input.type ===
|
|
540
|
+
return input.type === "composite";
|
|
541
541
|
}
|
|
542
542
|
//#endregion
|
|
543
543
|
//#region src/policy/built-in/date/validator.ts
|
|
@@ -567,11 +567,11 @@ var DatePolicyEvaluator = class {
|
|
|
567
567
|
async evaluate(value, ctx) {
|
|
568
568
|
const policy = await this.validator.run(value);
|
|
569
569
|
let now;
|
|
570
|
-
if (ctx.data.has(
|
|
570
|
+
if (ctx.data.has("date")) if (ctx.data.isValidated("date")) now = ctx.data.get("date");
|
|
571
571
|
else {
|
|
572
|
-
now = normalizeDate$1(toDate$1(ctx.data.get(
|
|
573
|
-
ctx.data.set(
|
|
574
|
-
ctx.data.setValidated(
|
|
572
|
+
now = normalizeDate$1(toDate$1(ctx.data.get("date")));
|
|
573
|
+
ctx.data.set("date", now);
|
|
574
|
+
ctx.data.setValidated("date");
|
|
575
575
|
}
|
|
576
576
|
else now = normalizeDate$1(/* @__PURE__ */ new Date());
|
|
577
577
|
if (policy.start) {
|
|
@@ -628,7 +628,7 @@ var IdentityPolicyEvaluator = class {
|
|
|
628
628
|
if (!data) return {
|
|
629
629
|
success: false,
|
|
630
630
|
issues: [definePolicyIssueItem({
|
|
631
|
-
code:
|
|
631
|
+
code: "DATA_MISSING",
|
|
632
632
|
message: "The data property identity is missing",
|
|
633
633
|
path: ctx.path
|
|
634
634
|
})]
|
|
@@ -639,7 +639,7 @@ var IdentityPolicyEvaluator = class {
|
|
|
639
639
|
return {
|
|
640
640
|
success: maybeInvertPolicyOutcome(typeAllowed, policy.invert),
|
|
641
641
|
issues: [definePolicyIssueItem({
|
|
642
|
-
code:
|
|
642
|
+
code: "EVALUATION_DENIED",
|
|
643
643
|
message: `The type ${data.type} is not covered by the policy configuration`,
|
|
644
644
|
path: ctx.path
|
|
645
645
|
})]
|
|
@@ -692,7 +692,7 @@ var RealmMatchPolicyEvaluator = class {
|
|
|
692
692
|
if (!identity) return {
|
|
693
693
|
success: false,
|
|
694
694
|
issues: [definePolicyIssueItem({
|
|
695
|
-
code:
|
|
695
|
+
code: "DATA_MISSING",
|
|
696
696
|
message: "The data property identity is missing",
|
|
697
697
|
path: ctx.path
|
|
698
698
|
})]
|
|
@@ -701,7 +701,7 @@ var RealmMatchPolicyEvaluator = class {
|
|
|
701
701
|
if (!attributes) return {
|
|
702
702
|
success: false,
|
|
703
703
|
issues: [definePolicyIssueItem({
|
|
704
|
-
code:
|
|
704
|
+
code: "DATA_MISSING",
|
|
705
705
|
message: "The data property attributes is missing",
|
|
706
706
|
path: ctx.path
|
|
707
707
|
})]
|
|
@@ -765,13 +765,13 @@ let TimePolicyInterval = /* @__PURE__ */ function(TimePolicyInterval) {
|
|
|
765
765
|
//#endregion
|
|
766
766
|
//#region src/policy/built-in/time/helpers.ts
|
|
767
767
|
function isIntervalForDayOfWeek(interval) {
|
|
768
|
-
return interval ===
|
|
768
|
+
return interval === "weekly" || interval === "monthly" || interval === "yearly";
|
|
769
769
|
}
|
|
770
770
|
function isIntervalForDayOfMonth(interval) {
|
|
771
|
-
return interval ===
|
|
771
|
+
return interval === "monthly" || interval === "yearly";
|
|
772
772
|
}
|
|
773
773
|
function isIntervalForDayOfYear(interval) {
|
|
774
|
-
return interval ===
|
|
774
|
+
return interval === "yearly";
|
|
775
775
|
}
|
|
776
776
|
//#endregion
|
|
777
777
|
//#region src/policy/built-in/time/validator.ts
|
|
@@ -821,11 +821,11 @@ var TimePolicyEvaluator = class {
|
|
|
821
821
|
async evaluate(value, ctx) {
|
|
822
822
|
const policy = await this.validator.run(value);
|
|
823
823
|
let now;
|
|
824
|
-
if (ctx.data.has(
|
|
824
|
+
if (ctx.data.has("time")) if (ctx.data.isValidated("time")) now = ctx.data.get("time");
|
|
825
825
|
else {
|
|
826
|
-
now = toDate(ctx.data.get(
|
|
827
|
-
ctx.data.set(
|
|
828
|
-
ctx.data.setValidated(
|
|
826
|
+
now = toDate(ctx.data.get("time"));
|
|
827
|
+
ctx.data.set("time", now);
|
|
828
|
+
ctx.data.setValidated("time");
|
|
829
829
|
}
|
|
830
830
|
else now = /* @__PURE__ */ new Date();
|
|
831
831
|
if (policy.start) {
|
|
@@ -863,14 +863,14 @@ function definePolicyWithType(type, data) {
|
|
|
863
863
|
//#endregion
|
|
864
864
|
//#region src/policy/constants.ts
|
|
865
865
|
const PolicyDefaultEvaluators = {
|
|
866
|
-
[
|
|
867
|
-
[
|
|
868
|
-
[
|
|
869
|
-
[
|
|
870
|
-
[
|
|
871
|
-
[
|
|
872
|
-
[
|
|
873
|
-
[
|
|
866
|
+
["composite"]: new CompositePolicyEvaluator(),
|
|
867
|
+
["attributes"]: new AttributesPolicyEvaluator(),
|
|
868
|
+
["attributeNames"]: new AttributeNamesPolicyEvaluator(),
|
|
869
|
+
["date"]: new DatePolicyEvaluator(),
|
|
870
|
+
["identity"]: new IdentityPolicyEvaluator(),
|
|
871
|
+
["permissionBinding"]: new PermissionBindingPolicyEvaluator(),
|
|
872
|
+
["realmMatch"]: new RealmMatchPolicyEvaluator(),
|
|
873
|
+
["time"]: new TimePolicyEvaluator()
|
|
874
874
|
};
|
|
875
875
|
//#endregion
|
|
876
876
|
//#region src/permission/evaluator/module.ts
|
|
@@ -931,11 +931,10 @@ var PermissionEvaluator = class {
|
|
|
931
931
|
continue;
|
|
932
932
|
}
|
|
933
933
|
const data = dataBase.clone();
|
|
934
|
-
data.set(
|
|
935
|
-
const policyDecisionStrategy = binding.permission.decision_strategy ?? DecisionStrategy.UNANIMOUS;
|
|
934
|
+
data.set("permissionBinding", binding);
|
|
936
935
|
const compositePolicy = {
|
|
937
|
-
type:
|
|
938
|
-
decision_strategy:
|
|
936
|
+
type: "composite",
|
|
937
|
+
decision_strategy: binding.permission.decision_strategy ?? DecisionStrategy.UNANIMOUS,
|
|
939
938
|
children: policies
|
|
940
939
|
};
|
|
941
940
|
const evaluationResult = await this.policyEngine.evaluate(compositePolicy, definePolicyEvaluationContext({
|
|
@@ -984,9 +983,9 @@ var PermissionEvaluator = class {
|
|
|
984
983
|
options: {
|
|
985
984
|
...ctx.options || {},
|
|
986
985
|
policiesExcluded: [
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
986
|
+
"attributes",
|
|
987
|
+
"attributeNames",
|
|
988
|
+
"realmMatch"
|
|
990
989
|
]
|
|
991
990
|
}
|
|
992
991
|
});
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["DecisionStrategy","normalizeDate","toDate"],"sources":["../src/permission/error/module.ts","../src/permission/helpers/equal.ts","../src/permission/helpers/key.ts","../src/permission/helpers/merge.ts","../src/permission/provider/memory.ts","../src/policy/helpers/invert.ts","../src/policy/error/module.ts","../src/policy/engine/module.ts","../src/policy/data.ts","../src/policy/evaluation/context/define.ts","../src/policy/issue/constants.ts","../src/policy/issue/define.ts","../src/policy/built-in/attribute-names/validator.ts","../src/policy/built-in/attributes/define.ts","../src/policy/built-in/constants.ts","../src/policy/built-in/attributes/validator.ts","../src/policy/built-in/attributes/evaluator.ts","../src/policy/built-in/attribute-names/evaluator.ts","../src/policy/built-in/composite/validator.ts","../src/policy/built-in/composite/evaluator.ts","../src/policy/built-in/composite/helper.ts","../src/policy/built-in/date/validator.ts","../src/policy/built-in/date/evaluator.ts","../src/policy/built-in/identity/data/validator.ts","../src/policy/built-in/identity/validator.ts","../src/policy/built-in/identity/evaluator.ts","../src/policy/built-in/permission-binding/validator.ts","../src/policy/built-in/permission-binding/module.ts","../src/policy/built-in/realm-match/validator.ts","../src/policy/built-in/realm-match/evaluator.ts","../src/policy/built-in/time/constants.ts","../src/policy/built-in/time/helpers.ts","../src/policy/built-in/time/validator.ts","../src/policy/built-in/time/evaluator.ts","../src/policy/built-in/define.ts","../src/policy/constants.ts","../src/permission/evaluator/module.ts"],"sourcesContent":["/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { AuthupErrorOptions } from '@authup/errors';\nimport { AuthupError, ErrorCode } from '@authup/errors';\nimport type { PolicyIssue } from '../../policy';\n\nexport class PermissionError extends AuthupError {\n constructor(options: AuthupErrorOptions = {}) {\n super({\n ...options,\n message: options.message || 'A permission error occurred.',\n statusCode: options.statusCode || 403,\n });\n }\n\n addIssue(data: PolicyIssue) {\n this.issues.push(data);\n }\n\n addIssues(data: PolicyIssue[]) {\n this.issues.push(...data);\n }\n\n static notFound(name: string) {\n return new PermissionError({\n message: `The permission ${name} was not found.`,\n code: ErrorCode.PERMISSION_NOT_FOUND,\n });\n }\n\n static denied(name: string) {\n return new PermissionError({\n message: `The permission ${name} has not been granted.`,\n code: ErrorCode.PERMISSION_DENIED,\n });\n }\n\n static deniedAll(names: string[]) {\n return new PermissionError({\n message: `None of the permissions ${names.join(', ')} has been granted.`,\n code: ErrorCode.PERMISSION_DENIED,\n });\n }\n\n static evaluationFailed(name: string | string[]) {\n if (Array.isArray(name)) {\n return new PermissionError({\n message: `The evaluation of permissions ${name.join(', ')} failed`,\n code: ErrorCode.PERMISSION_EVALUATION_FAILED,\n });\n }\n\n return new PermissionError({\n message: `The evaluation of permission ${name} failed`,\n code: ErrorCode.PERMISSION_EVALUATION_FAILED,\n });\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { PermissionPolicyBinding } from '../types';\n\nexport function isPermissionPolicyBindingEqual(a: PermissionPolicyBinding, b: PermissionPolicyBinding): boolean {\n if (a.permission.name !== b.permission.name) {\n return false;\n }\n\n if ((a.permission.realm_id ?? null) !== (b.permission.realm_id ?? null)) {\n return false;\n }\n\n if ((a.permission.client_id ?? null) !== (b.permission.client_id ?? null)) {\n return false;\n }\n\n return true;\n}\n","/*\n * Copyright (c) 2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\n\nimport type { BasePermission } from '../types.ts';\n\nfunction formatKeySegment(value?: string | null): string {\n return value || '*';\n}\n\nexport function buildPermissionKey(\n input: BasePermission,\n) {\n return `${formatKeySegment(input.realm_id)}/${formatKeySegment(input.client_id)}/${input.name}`;\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { DecisionStrategy } from '@authup/kit';\nimport type { BasePolicy } from '../../policy';\nimport type { PermissionPolicyBinding } from '../types';\nimport { buildPermissionKey } from './key';\n\ntype CompositePolicy = BasePolicy & {\n decision_strategy?: `${DecisionStrategy}`,\n children: BasePolicy[],\n};\n\nexport function mergePermissionPolicyBindings(input: PermissionPolicyBinding[]) : PermissionPolicyBinding[] {\n const grouped : Record<string, PermissionPolicyBinding[]> = input\n .reduce((previous, current) => {\n const key = buildPermissionKey(current.permission);\n if (!previous[key]) {\n previous[key] = [];\n }\n\n previous[key].push(current);\n\n return previous;\n }, {} as Record<string, PermissionPolicyBinding[]>);\n\n const output : PermissionPolicyBinding[] = [];\n const keys = Object.keys(grouped);\n for (const key of keys) {\n const group = grouped[key]!;\n const first = group[0]!;\n\n if (group.length === 1) {\n output.push(first);\n continue;\n }\n\n const children : BasePolicy[] = [];\n\n for (const element of group) {\n if (!element.policies || element.policies.length === 0) {\n continue;\n }\n\n const policy: CompositePolicy = {\n type: 'composite',\n decision_strategy: element.permission.decision_strategy || DecisionStrategy.UNANIMOUS,\n children: element.policies,\n };\n\n children.push(policy);\n }\n\n let mergedPolicies: BasePolicy[] | undefined;\n\n if (\n children.length > 0 &&\n children.length === group.length\n ) {\n const policy: CompositePolicy = {\n type: 'composite',\n decision_strategy: DecisionStrategy.AFFIRMATIVE,\n children,\n };\n\n mergedPolicies = [policy];\n }\n\n output.push({\n permission: {\n ...first.permission,\n decision_strategy: DecisionStrategy.AFFIRMATIVE,\n },\n policies: mergedPolicies,\n });\n }\n\n return output;\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { buildPermissionKey, mergePermissionPolicyBindings } from '../helpers';\nimport type { PermissionPolicyBinding } from '../types';\nimport type { IPermissionProvider, PermissionGetOptions } from './types';\n\nexport class PermissionMemoryProvider implements IPermissionProvider {\n protected items : Record<string, PermissionPolicyBinding> = {};\n\n constructor(items: PermissionPolicyBinding[] = []) {\n this.setMany(items);\n }\n\n async findOne(\n options: PermissionGetOptions,\n ): Promise<PermissionPolicyBinding | null> {\n const key = buildPermissionKey({\n name: options.name,\n client_id: options.clientId,\n realm_id: options.realmId,\n });\n\n const entry = this.items[key];\n if (entry) {\n return entry;\n }\n\n return null;\n }\n\n setMany(input: PermissionPolicyBinding[]) {\n this.items = mergePermissionPolicyBindings(input)\n .reduce((prev, current) => {\n const key = buildPermissionKey(current.permission);\n prev[key] = current;\n return prev;\n }, {} as Record<string, PermissionPolicyBinding>);\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\ntype InvertFn = (input: boolean) => boolean;\n\nexport function maybeInvertPolicyOutcome(\n outcome: boolean,\n invert?: boolean | InvertFn,\n) {\n if (typeof invert === 'undefined') {\n return outcome;\n }\n\n if (typeof invert === 'function') {\n return invert(outcome);\n }\n\n if (!invert) {\n return outcome;\n }\n\n return !outcome;\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { AuthupError, ErrorCode } from '@authup/errors';\nimport type { PolicyIssue } from '../issue';\n\nexport class PolicyError extends AuthupError {\n constructor(message?: string, code?: string | null) {\n super({\n message,\n code, \n });\n }\n\n addIssue(data: PolicyIssue) {\n this.issues.push(data);\n }\n\n addIssues(data: PolicyIssue[]) {\n this.issues.push(...data);\n }\n\n static evaluatorNotFound(type: string) {\n return new PolicyError(\n `No evaluator is registered to handle the policy: ${type}`,\n ErrorCode.POLICY_EVALUATOR_NOT_FOUND,\n );\n }\n\n static evaluatorNotProcessable() {\n return new PolicyError(\n 'The evaluator can not process the policy.',\n ErrorCode.POLICY_EVALUATOR_NOT_PROCESSABLE,\n );\n }\n\n static evaluatorContextInvalid() {\n return new PolicyError(\n 'The evaluator context is not valid.',\n ErrorCode.POLICY_EVALUATOR_CONTEXT_INVALID,\n );\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { ErrorCode } from '@authup/errors';\nimport { defineIssueItem } from 'validup';\nimport type {\n IPolicyEvaluator,\n PolicyEvaluationContext,\n PolicyEvaluationResult,\n PolicyEvaluators,\n} from '../evaluation';\nimport { maybeInvertPolicyOutcome } from '../helpers';\nimport type { PolicyIssue } from '../issue';\nimport type { IPolicyEngine } from './types.ts';\nimport { PolicyError } from '../error';\nimport type { BasePolicy } from '../types.ts';\n\n/**\n * The policy engine is a component that interprets defined policies and makes decisions\n * on whether to allow or deny a particular access.\n */\nexport class PolicyEngine implements IPolicyEngine {\n protected evaluators : Record<string, IPolicyEvaluator>;\n\n constructor(evaluators: PolicyEvaluators = {}) {\n this.evaluators = evaluators;\n }\n\n public registerEvaluator(\n type: string,\n evaluator: IPolicyEvaluator,\n ) : void {\n this.evaluators[type] = evaluator;\n }\n\n public registerEvaluators(evaluators: PolicyEvaluators) {\n const keys = Object.keys(evaluators);\n for (const key of keys) {\n this.registerEvaluator(key, evaluators[key]!);\n }\n }\n\n /**\n * @param policy\n * @param ctx\n */\n async evaluate(policy: BasePolicy, ctx: PolicyEvaluationContext) : Promise<PolicyEvaluationResult> {\n if (!policy.type) {\n return {\n success: maybeInvertPolicyOutcome(false, policy.invert),\n issues: [\n defineIssueItem({\n path: [],\n message: 'The policy can not be handled by any evaluator.',\n code: ErrorCode.POLICY_EVALUATOR_NOT_FOUND,\n }),\n ],\n };\n }\n if (\n ctx.exclude &&\n ctx.exclude.length > 0 &&\n ctx.exclude.includes(policy.type)\n ) {\n return { success: maybeInvertPolicyOutcome(true, policy.invert) };\n }\n\n if (\n ctx.include &&\n ctx.include.length > 0 &&\n !ctx.include.includes(policy.type)\n ) {\n return { success: maybeInvertPolicyOutcome(true, policy.invert) };\n }\n\n const issues : PolicyIssue[] = [];\n\n const evaluator = this.evaluators[policy.type];\n if (!evaluator) {\n // todo: add issue here instead + return false ?\n issues.push(defineIssueItem({\n path: [policy.type],\n message: `The policy ${policy.type} can not be handled by any evaluator.`,\n code: ErrorCode.POLICY_EVALUATOR_NOT_FOUND,\n }));\n\n return {\n success: maybeInvertPolicyOutcome(false, policy.invert),\n issues,\n };\n }\n\n try {\n return await evaluator.evaluate(policy, {\n ...ctx,\n evaluators: {\n ...this.evaluators,\n ...(ctx.evaluators || {}),\n },\n });\n } catch {\n issues.push(defineIssueItem({\n path: [policy.type],\n message: `The ${policy.type} evaluator can not process the policy specification.`,\n code: ErrorCode.POLICY_EVALUATOR_NOT_PROCESSABLE,\n }));\n\n return {\n success: maybeInvertPolicyOutcome(false, policy.invert),\n issues,\n };\n }\n }\n\n async evaluateOrFail(policy: BasePolicy, ctx: PolicyEvaluationContext) : Promise<void> {\n const issues : PolicyIssue[] = [];\n\n try {\n const outcome = await this.evaluate(policy, ctx);\n if (outcome.success) {\n return;\n }\n\n if (outcome.issues) {\n issues.push(...outcome.issues);\n }\n } catch (e) {\n if (e instanceof PolicyError) {\n throw e;\n }\n }\n\n const error = new PolicyError(`The policy ${policy.type} evaluation failed.`);\n error.addIssues(issues);\n\n throw error;\n }\n}\n","/*\n * Copyright (c) 2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport interface IPolicyData {\n set(key: string, value: unknown) : void;\n has(key: string): boolean;\n get<T = unknown>(key: string) : T;\n\n isValidated(key: string): boolean;\n setValidated(key: string) : void;\n\n clone() : IPolicyData\n}\n\nexport class PolicyData implements IPolicyData {\n protected data: Record<string, any>;\n\n protected validated : Set<string>;\n\n constructor(\n data: Record<string, any> = {},\n validated: Set<string> = new Set(),\n ) {\n this.data = data;\n this.validated = validated;\n }\n\n set<T = unknown>(key: string, value: T) : void {\n this.data[key] = value;\n this.validated.delete(key);\n }\n\n get<T = unknown>(key: string) : T {\n if (key in this.data) {\n return this.data[key];\n }\n\n throw new Error(`Policy data item ${key} does not exist.`);\n }\n\n has(key: string): boolean {\n return key in this.data;\n }\n\n setValidated(key: string) : void {\n this.validated.add(key);\n }\n\n isValidated(key: string) : boolean {\n return this.validated.has(key);\n }\n\n clone() {\n return new PolicyData({ ...this.data }, new Set(this.validated));\n }\n}\n","/*\n * Copyright (c) 2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { PolicyEvaluationContext, PolicyEvaluationContextInput } from './types.ts';\nimport { PolicyData } from '../../data.ts';\n\nexport function definePolicyEvaluationContext(\n input: PolicyEvaluationContextInput = {},\n) : PolicyEvaluationContext {\n return {\n evaluators: input.evaluators || {},\n path: input.path || [],\n data: input.data || new PolicyData(),\n include: input.include || [],\n exclude: input.exclude || [],\n };\n}\n","/*\n * Copyright (c) 2026-2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum PolicyIssueSeverity {\n WARNING = 'warning',\n ERROR = 'error',\n}\n\nexport enum PolicyIssueCode {\n // Data/Input\n DATA_MISSING = 'DATA_MISSING',\n DATA_INVALID = 'DATA_INVALID',\n\n // Policy Spec / Config\n INVALID = 'INVALID',\n TYPE_UNKNOWN = 'TYPE_UNKNOWN',\n FIELD_MISSING = 'FIELD_MISSING',\n FIELD_INVALID = 'FIELD_INVALID',\n\n // Composite / Tree evaluation\n CHILD_INVALID = 'CHILD_INVALID',\n CHILD_EVALUATION_FAILED = 'CHILD_EVALUATION_FAILED',\n\n // Engine / Evaluator registry\n EVALUATION_DENIED = 'EVALUATION_DENIED',\n EVALUATOR_NOT_FOUND = 'EVALUATOR_NOT_FOUND',\n EVALUATOR_ERROR = 'EVALUATOR_ERROR',\n\n // Execution control\n SKIPPED_EXCLUDED = 'SKIPPED_EXCLUDED',\n SKIPPED_NOT_INCLUDED = 'SKIPPED_NOT_INCLUDED',\n\n // Internal / unexpected\n INTERNAL_ERROR = 'INTERNAL_ERROR',\n}\n","/*\n * Copyright (c) 2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { defineIssueGroup, defineIssueItem } from 'validup';\nimport type { PolicyIssueGroup, PolicyIssueItem } from './types.ts';\n\nexport function definePolicyIssueItem(input: Omit<PolicyIssueItem, 'type'>) : PolicyIssueItem {\n return defineIssueItem(input);\n}\n\nexport function definePolicyIssueGroup(input: Omit<PolicyIssueGroup, 'type'>) : PolicyIssueGroup {\n return defineIssueGroup(input);\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { createValidator } from '@validup/adapter-zod';\nimport { Container } from 'validup';\nimport { z } from 'zod';\nimport type { AttributeNamesPolicy } from './types';\n\nexport class AttributeNamesPolicyValidator extends Container<AttributeNamesPolicy> {\n override initialize() {\n super.initialize();\n\n this.mount(\n 'names',\n createValidator(\n z.array(\n z.string()\n .min(3)\n .max(128),\n ),\n ),\n );\n\n this.mount(\n 'invert',\n createValidator(\n z.boolean()\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n }\n}\n","/*\n * Copyright (c) 2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { AttributesPolicy } from './types';\n\nexport function defineAttributesPolicy<\n T extends Record<string, any> = Record<string, any>,\n>(\n data: AttributesPolicy<T>,\n) : AttributesPolicy<T> {\n return data;\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum BuiltInPolicyType {\n /**\n * Bundles different policies.\n */\n COMPOSITE = 'composite',\n /**\n * Date Based Access Control (DBAC)\n */\n DATE = 'date',\n /**\n * Time Based Access Control (TBAC)\n */\n TIME = 'time',\n /**\n * Attribute Name Based Access Control (ANBAC)\n */\n ATTRIBUTE_NAMES = 'attributeNames',\n /**\n * Attribute Based Access Control (ABAC)\n */\n ATTRIBUTES = 'attributes',\n /**\n * Realm of Identity is for attribute realm.\n */\n REALM_MATCH = 'realmMatch',\n\n /**\n * Restriction based on identity (type, id, ...)\n */\n IDENTITY = 'identity',\n\n /**\n * Restriction based on a binding between identity <-> permission\n */\n PERMISSION_BINDING = 'permissionBinding',\n\n // Location (LBAC)\n // Device (DBAC)\n}\n\nexport const SystemPolicyName = {\n DEFAULT: 'system.default',\n IDENTITY: 'system.identity',\n PERMISSION_BINDING: 'system.permission-binding',\n REALM_MATCH: 'system.realm-match',\n REALM_BOUND: 'system.realm-bound',\n REALM_OR_GLOBAL: 'system.realm-or-global',\n} as const;\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { createValidator } from '@validup/adapter-zod';\nimport { Container } from 'validup';\nimport { z } from 'zod';\nimport type { AttributesPolicy } from './types';\n\nexport class AttributesPolicyValidator<\n T extends Record<string, any> = Record<string, any>,\n> extends Container<AttributesPolicy<T>> {\n override initialize() {\n super.initialize();\n\n this.mount(\n 'query',\n createValidator(\n z.looseObject({}),\n ),\n );\n\n this.mount(\n 'invert',\n createValidator(\n z.boolean()\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { guard } from '@ucast/mongo2js';\nimport { isObject } from '@authup/kit';\nimport type { IPolicyEvaluator, PolicyEvaluationContext, PolicyEvaluationResult } from '../../evaluation';\nimport { maybeInvertPolicyOutcome } from '../../helpers';\nimport { PolicyIssueCode, definePolicyIssueItem } from '../../issue';\nimport { BuiltInPolicyType } from '../constants.ts';\nimport { AttributesPolicyValidator } from './validator';\n\nexport class AttributesPolicyEvaluator<\n T extends Record<string, any> = Record<string, any>,\n> implements IPolicyEvaluator {\n protected validator : AttributesPolicyValidator<T>;\n\n constructor() {\n this.validator = new AttributesPolicyValidator<T>();\n }\n\n async accessData(ctx: PolicyEvaluationContext) : Promise<T | null> {\n if (!ctx.data.has(BuiltInPolicyType.ATTRIBUTES)) {\n return null;\n }\n\n if (ctx.data.isValidated(BuiltInPolicyType.ATTRIBUTES)) {\n return ctx.data.get<T>(BuiltInPolicyType.ATTRIBUTES);\n }\n\n // todo: run validator on attributes (isObject ...)\n const data = ctx.data.get<T>(BuiltInPolicyType.ATTRIBUTES);\n\n ctx.data.set(BuiltInPolicyType.ATTRIBUTES, data);\n ctx.data.setValidated(BuiltInPolicyType.ATTRIBUTES);\n\n return data;\n }\n\n async evaluate(value: Record<string, any>, ctx: PolicyEvaluationContext): Promise<PolicyEvaluationResult> {\n // todo: catch errors + transform to issue(s)\n const policy = await this.validator.run(value);\n\n const data = await this.accessData(ctx);\n if (!data) {\n return {\n success: false,\n issues: [\n definePolicyIssueItem({\n code: PolicyIssueCode.DATA_MISSING,\n message: 'The data property attributes is missing',\n path: ctx.path,\n }),\n ],\n };\n }\n\n this.fixQuery(policy.query);\n\n const testIt = guard<T>(policy.query);\n\n return { success: maybeInvertPolicyOutcome(testIt(data as T), policy.invert) };\n }\n\n protected fixQuery(\n query: unknown | unknown[],\n ) {\n if (Array.isArray(query)) {\n for (const element of query) {\n this.fixQuery(element);\n }\n\n return;\n }\n\n if (isObject(query)) {\n const keys = Object.keys(query);\n for (const key of keys) {\n const value = query[key];\n\n if (isObject(value) || Array.isArray(value)) {\n this.fixQuery(value);\n continue;\n }\n\n if (\n key === '$regex' &&\n typeof value === 'string'\n ) {\n const fragments = value.match(/\\/(.*?)\\/([a-z]*)?$/i);\n if (fragments && fragments[1] !== undefined) {\n query[key] = new RegExp(fragments[1], fragments[2] || '');\n }\n }\n }\n }\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { flattenObject } from '@authup/kit';\nimport type { IPolicyEvaluator, PolicyEvaluationContext, PolicyEvaluationResult } from '../../evaluation';\nimport { maybeInvertPolicyOutcome } from '../../helpers';\nimport type { PolicyIssue } from '../../issue';\nimport { PolicyIssueCode, definePolicyIssueItem } from '../../issue';\nimport { AttributeNamesPolicyValidator } from './validator';\nimport { AttributesPolicyEvaluator } from '../attributes';\n\nexport class AttributeNamesPolicyEvaluator implements IPolicyEvaluator {\n protected validator : AttributeNamesPolicyValidator;\n\n protected attributesEvaluator : AttributesPolicyEvaluator;\n\n constructor() {\n this.validator = new AttributeNamesPolicyValidator();\n this.attributesEvaluator = new AttributesPolicyEvaluator();\n }\n\n async evaluate(value: Record<string, any>, ctx: PolicyEvaluationContext): Promise<PolicyEvaluationResult> {\n // todo: catch errors + transform to issue(s)\n const policy = await this.validator.run(value);\n\n const data = await this.attributesEvaluator.accessData(ctx);\n if (!data) {\n return {\n success: false,\n issues: [\n definePolicyIssueItem({\n code: PolicyIssueCode.DATA_MISSING,\n message: 'The data property attributes is missing',\n path: ctx.path,\n }),\n ],\n };\n }\n\n const attributes = flattenObject(data);\n const keys = Object.keys(attributes);\n\n const issues : PolicyIssue[] = [];\n for (const key of keys) {\n const index = policy.names.indexOf(key);\n if (index === -1) {\n issues.push(definePolicyIssueItem({\n code: PolicyIssueCode.EVALUATION_DENIED,\n message: `The attribute ${key} is not included`,\n path: [...ctx.path, key],\n }));\n }\n }\n\n return {\n success: maybeInvertPolicyOutcome(issues.length === 0, policy.invert),\n issues,\n };\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { createValidator } from '@validup/adapter-zod';\nimport { Container } from 'validup';\nimport { z } from 'zod';\nimport { DecisionStrategy } from '../../../constants';\nimport type { CompositePolicy } from './types';\n\nexport class CompositePolicyValidator extends Container<CompositePolicy> {\n override initialize() {\n super.initialize();\n\n this.mount(\n 'decision_strategy',\n createValidator(\n z.enum(DecisionStrategy)\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n\n this.mount(\n 'children',\n createValidator(\n z.array(z.looseObject({ type: z.string().min(3) })),\n ),\n );\n\n this.mount(\n 'invert',\n createValidator(\n z.boolean()\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { defineIssueGroup } from 'validup';\nimport { DecisionStrategy } from '../../../constants';\nimport { PolicyEngine } from '../../engine';\nimport type { IPolicyEvaluator, PolicyEvaluationContext, PolicyEvaluationResult } from '../../evaluation';\nimport { maybeInvertPolicyOutcome } from '../../helpers';\nimport type { PolicyIssue } from '../../issue';\nimport { CompositePolicyValidator } from './validator';\n\nexport class CompositePolicyEvaluator implements IPolicyEvaluator {\n protected validator : CompositePolicyValidator;\n\n constructor() {\n this.validator = new CompositePolicyValidator();\n }\n\n async evaluate(value: Record<string, any>, ctx: PolicyEvaluationContext): Promise<PolicyEvaluationResult> {\n // todo: catch errors + transform to issue(s)\n const policy = await this.validator.run(value);\n\n let count = 0;\n\n const decision_strategy = policy.decision_strategy ??\n DecisionStrategy.UNANIMOUS;\n\n const engine = new PolicyEngine(ctx.evaluators);\n const issues : PolicyIssue[] = [];\n\n for (const childPolicy of policy.children) {\n const path = [\n ...(ctx.path || []),\n ...(childPolicy.type ? [childPolicy.type] : []),\n ];\n\n const outcome = await engine.evaluate(childPolicy, {\n ...ctx,\n path,\n });\n\n if (outcome.success) {\n if (decision_strategy === DecisionStrategy.AFFIRMATIVE) {\n return {\n success: maybeInvertPolicyOutcome(true, policy.invert),\n issues: [],\n };\n }\n\n count++;\n } else {\n if (outcome.issues) {\n issues.push(defineIssueGroup({\n message: `The evaluation of child policy ${childPolicy.type} failed`,\n issues: outcome.issues || [],\n path,\n }));\n }\n\n if (decision_strategy === DecisionStrategy.UNANIMOUS) {\n return {\n success: maybeInvertPolicyOutcome(false, policy.invert),\n issues: [\n defineIssueGroup({\n message: `The evaluation of composite policy failed (${DecisionStrategy.UNANIMOUS})`,\n issues,\n path: ctx.path,\n }),\n ],\n };\n }\n\n count--;\n }\n }\n\n if (count > 0) {\n return { success: maybeInvertPolicyOutcome(true, policy.invert) };\n }\n\n return {\n success: maybeInvertPolicyOutcome(false, policy.invert),\n issues: [\n defineIssueGroup({\n message: `The evaluation of composite policy failed (${DecisionStrategy.CONSENSUS})`,\n issues: issues || [],\n path: ctx.path,\n }),\n ],\n };\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { PolicyWithType } from '../../types';\nimport { BuiltInPolicyType } from '../constants';\nimport type { CompositePolicy } from './types';\n\nexport function isCompositePolicy(\n input: PolicyWithType,\n) : input is PolicyWithType<CompositePolicy> {\n return input.type === BuiltInPolicyType.COMPOSITE;\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { createValidator } from '@validup/adapter-zod';\nimport { Container } from 'validup';\nimport { z } from 'zod';\nimport type { DatePolicy } from './types';\n\nexport class DatePolicyValidator extends Container<DatePolicy> {\n override initialize() {\n super.initialize();\n\n this.mount('start', createValidator(\n z.date()\n .or(z.iso.date())\n .or(z.number())\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ));\n this.mount('end', createValidator(\n z.date()\n .or(z.iso.date())\n .or(z.number())\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ));\n\n this.mount('invert', createValidator(\n z.boolean()\n .or(z.undefined())\n .or(z.null())\n .optional(),\n ));\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { IPolicyEvaluator, PolicyEvaluationContext, PolicyEvaluationResult } from '../../evaluation';\nimport { maybeInvertPolicyOutcome } from '../../helpers';\nimport { BuiltInPolicyType } from '../constants.ts';\nimport { DatePolicyValidator } from './validator';\n\nfunction normalizeDate(input: Date) {\n return new Date(input.getFullYear(), input.getMonth(), input.getDate());\n}\n\nfunction toDate(input: Date | string | number) : Date {\n if (typeof input === 'string') {\n return new Date(input);\n }\n\n if (typeof input === 'number') {\n return new Date(input);\n }\n\n return input;\n}\n\nexport class DatePolicyEvaluator implements IPolicyEvaluator {\n protected validator : DatePolicyValidator;\n\n constructor() {\n this.validator = new DatePolicyValidator();\n }\n\n async evaluate(value: Record<string, any>, ctx: PolicyEvaluationContext): Promise<PolicyEvaluationResult> {\n // todo: catch errors + transform to issue(s)\n const policy = await this.validator.run(value);\n\n let now : Date;\n\n if (ctx.data.has(BuiltInPolicyType.DATE)) {\n if (ctx.data.isValidated(BuiltInPolicyType.DATE)) {\n now = ctx.data.get<Date>(BuiltInPolicyType.DATE);\n } else {\n // todo: run validator on attributes (isObject ...)\n now = normalizeDate(toDate(ctx.data.get(BuiltInPolicyType.DATE)));\n\n ctx.data.set(BuiltInPolicyType.DATE, now);\n ctx.data.setValidated(BuiltInPolicyType.DATE);\n }\n } else {\n now = normalizeDate(new Date());\n }\n\n if (policy.start) {\n const start = normalizeDate(toDate(policy.start));\n if (now < start) {\n return { success: maybeInvertPolicyOutcome(false, policy.invert) };\n }\n }\n\n if (policy.end) {\n const end = normalizeDate(toDate(policy.end));\n if (now > end) {\n return { success: maybeInvertPolicyOutcome(false, policy.invert) };\n }\n }\n\n return { success: maybeInvertPolicyOutcome(true, policy.invert) };\n }\n}\n","/*\n * Copyright (c) 2024-2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { createValidator } from '@validup/adapter-zod';\nimport { Container } from 'validup';\nimport { z } from 'zod';\n\nimport type { IdentityPolicyData } from '../types.ts';\n\nexport class PolicyIdentityDataValidator extends Container<IdentityPolicyData> {\n override initialize() {\n super.initialize();\n\n this.mount(\n 'type',\n createValidator(\n z.string().min(3).max(128),\n ),\n );\n\n this.mount(\n 'id',\n createValidator(\n z.uuid(),\n ),\n );\n\n this.mount(\n 'clientId',\n createValidator(\n z.uuid()\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n\n this.mount(\n 'realmId',\n createValidator(\n z.uuid()\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n\n this.mount(\n 'realmName',\n createValidator(\n z.string().min(3).max(128)\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { createValidator } from '@validup/adapter-zod';\nimport { Container } from 'validup';\nimport { z } from 'zod';\nimport type { IdentityPolicy } from './types';\n\nexport class IdentityPolicyValidator extends Container<IdentityPolicy> {\n override initialize() {\n this.mount(\n 'types',\n createValidator(\n z.array(z.string())\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n\n this.mount(\n 'invert',\n createValidator(\n z.boolean()\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { IPolicyEvaluator, PolicyEvaluationContext, PolicyEvaluationResult } from '../../evaluation';\nimport { PolicyIssueCode, definePolicyIssueItem } from '../../issue';\nimport { maybeInvertPolicyOutcome } from '../../helpers';\nimport { PolicyIdentityDataValidator } from './data';\nimport type { IdentityPolicyData } from './types';\nimport { IdentityPolicyValidator } from './validator';\n\nexport class IdentityPolicyEvaluator implements IPolicyEvaluator {\n protected validator : IdentityPolicyValidator;\n\n protected dataValidator : PolicyIdentityDataValidator;\n\n constructor() {\n this.validator = new IdentityPolicyValidator();\n this.dataValidator = new PolicyIdentityDataValidator();\n }\n\n async accessData(ctx: PolicyEvaluationContext) : Promise<IdentityPolicyData | null> {\n if (!ctx.data.has('identity')) {\n return null;\n }\n\n if (ctx.data.isValidated('identity')) {\n return ctx.data.get<IdentityPolicyData>('identity');\n }\n\n const data = await this.dataValidator.run(ctx.data.get('identity'));\n\n ctx.data.set('identity', data);\n ctx.data.setValidated('identity');\n\n return data;\n }\n\n async evaluate(value: Record<string, any>, ctx: PolicyEvaluationContext): Promise<PolicyEvaluationResult> {\n // todo: catch errors + transform to issue(s)\n const policy = await this.validator.run(value);\n\n const data = await this.accessData(ctx);\n if (!data) {\n return {\n success: false,\n issues: [\n definePolicyIssueItem({\n code: PolicyIssueCode.DATA_MISSING,\n message: 'The data property identity is missing',\n path: ctx.path,\n }),\n ],\n };\n }\n\n if (!policy.types || policy.types.length === 0) {\n return { success: maybeInvertPolicyOutcome(true, policy.invert) };\n }\n\n const typeAllowed = policy.types.includes(data.type);\n if (typeAllowed) {\n return { success: maybeInvertPolicyOutcome(typeAllowed, policy.invert) };\n }\n\n return {\n success: maybeInvertPolicyOutcome(typeAllowed, policy.invert),\n issues: [\n definePolicyIssueItem({\n code: PolicyIssueCode.EVALUATION_DENIED,\n message: `The type ${data.type} is not covered by the policy configuration`,\n path: ctx.path,\n }),\n ],\n };\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { Container } from 'validup';\nimport type { PermissionBindingPolicy } from './types';\n\nexport class PermissionBindingPolicyValidator extends Container<PermissionBindingPolicy> {\n override initialize() {\n\n }\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { IPolicyEvaluator, PolicyEvaluationResult } from '../../evaluation';\nimport { maybeInvertPolicyOutcome } from '../../helpers';\nimport { PermissionBindingPolicyValidator } from './validator';\n\nexport class PermissionBindingPolicyEvaluator implements IPolicyEvaluator {\n protected validator: PermissionBindingPolicyValidator;\n\n constructor() {\n this.validator = new PermissionBindingPolicyValidator();\n }\n\n async evaluate(value: Record<string, any>): Promise<PolicyEvaluationResult> {\n const policy = await this.validator.run(value);\n\n // todo: this must be changed when the permission-checker not only checks owned permissions.\n return { success: maybeInvertPolicyOutcome(true, policy.invert) };\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { createValidator } from '@validup/adapter-zod';\nimport { Container } from 'validup';\nimport { z } from 'zod';\nimport { DecisionStrategy } from '../../../constants';\nimport type { RealmMatchPolicy } from './types';\n\nexport class RealmMatchPolicyValidator extends Container<RealmMatchPolicy> {\n override initialize() {\n super.initialize();\n\n this.mount(\n 'decision_strategy',\n createValidator(\n z.enum(DecisionStrategy)\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n\n this.mount(\n 'attribute_name',\n createValidator(\n z.string()\n .min(3)\n .or(z.array(z.string().min(3)))\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n this.mount(\n 'attribute_name_strict',\n createValidator(\n z.boolean()\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n this.mount(\n 'attribute_null_match_all',\n createValidator(\n z.boolean()\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n\n this.mount(\n 'identity_master_match_all',\n createValidator(\n z.boolean()\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n\n this.mount(\n 'invert',\n createValidator(\n z.boolean()\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { hasOwnProperty } from '@authup/kit';\nimport { DecisionStrategy } from '../../../constants';\nimport type { IPolicyEvaluator, PolicyEvaluationContext, PolicyEvaluationResult } from '../../evaluation';\nimport { maybeInvertPolicyOutcome } from '../../helpers';\nimport { PolicyIssueCode, definePolicyIssueItem } from '../../issue';\nimport { AttributesPolicyEvaluator } from '../attributes';\nimport { IdentityPolicyEvaluator } from '../identity';\nimport { RealmMatchPolicyValidator } from './validator';\n\nexport class RealmMatchPolicyEvaluator implements IPolicyEvaluator {\n protected validator : RealmMatchPolicyValidator;\n\n protected identityEvaluator: IdentityPolicyEvaluator;\n\n protected attributesEvaluator : AttributesPolicyEvaluator;\n\n constructor() {\n this.validator = new RealmMatchPolicyValidator();\n this.identityEvaluator = new IdentityPolicyEvaluator();\n this.attributesEvaluator = new AttributesPolicyEvaluator();\n }\n\n async evaluate(value: Record<string, any>, ctx: PolicyEvaluationContext): Promise<PolicyEvaluationResult> {\n // todo: catch errors + transform to issue(s)\n const policy = await this.validator.run(value);\n\n const identity = await this.identityEvaluator.accessData(ctx);\n if (!identity) {\n return {\n success: false,\n issues: [\n definePolicyIssueItem({\n code: PolicyIssueCode.DATA_MISSING,\n message: 'The data property identity is missing',\n path: ctx.path,\n }),\n ],\n };\n }\n\n const attributes = await this.attributesEvaluator.accessData(ctx);\n if (!attributes) {\n return {\n success: false,\n issues: [\n definePolicyIssueItem({\n code: PolicyIssueCode.DATA_MISSING,\n message: 'The data property attributes is missing',\n path: ctx.path,\n }),\n ],\n };\n }\n\n const identityMasterMatchAll = policy.identity_master_match_all ?? true;\n if (\n identityMasterMatchAll &&\n identity.realmName &&\n identity.realmName === 'master'\n ) {\n return { success: maybeInvertPolicyOutcome(true, policy.invert) };\n }\n\n let keys : string[];\n if (policy.attribute_name) {\n if (Array.isArray(policy.attribute_name)) {\n keys = policy.attribute_name;\n } else {\n keys = [policy.attribute_name];\n }\n } else {\n keys = [\n 'realm_id',\n 'realm_name',\n 'realmId',\n 'realmName',\n ];\n\n policy.decision_strategy = DecisionStrategy.CONSENSUS;\n }\n\n const attribute_name_strict = policy.attribute_name_strict ?? true;\n if (!attribute_name_strict) {\n const resourceKeys = Object.keys(attributes);\n const keysToAdd : string[] = [];\n for (const resourceKey of resourceKeys) {\n let contains : boolean = false;\n\n for (const key of keys) {\n if (\n resourceKey !== key &&\n resourceKey.includes(key)\n ) {\n contains = true;\n break;\n }\n }\n\n if (contains) {\n keysToAdd.push(resourceKey);\n }\n }\n\n if (keysToAdd.length > 0) {\n keys.push(...keysToAdd);\n }\n }\n\n let count = 0;\n let evaluated = false;\n\n for (const key of keys) {\n if (!hasOwnProperty(attributes, key)) {\n continue;\n }\n\n evaluated = true;\n\n let outcome : boolean = false;\n\n const attributeValue = attributes[key];\n\n if (\n attributeValue === null &&\n policy.attribute_null_match_all\n ) {\n outcome = true;\n } else if (\n attributeValue === identity.realmId ||\n attributeValue === identity.realmName\n ) {\n outcome = true;\n }\n\n if (outcome) {\n if (policy.decision_strategy === DecisionStrategy.AFFIRMATIVE) {\n return { success: maybeInvertPolicyOutcome(true, policy.invert) };\n }\n\n count++;\n } else {\n if (policy.decision_strategy === DecisionStrategy.UNANIMOUS) {\n return { success: maybeInvertPolicyOutcome(false, policy.invert) };\n }\n\n count--;\n }\n }\n\n if (!evaluated) {\n return { success: maybeInvertPolicyOutcome(true, policy.invert) };\n }\n\n return { success: maybeInvertPolicyOutcome(count > 0, policy.invert) };\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum TimePolicyInterval {\n DAILY = 'daily',\n WEEKLY = 'weekly',\n MONTHLY = 'monthly',\n YEARLY = 'yearly',\n}\n","/*\n * Copyright (c) 2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { TimePolicyInterval } from './constants';\n\nexport function isIntervalForDayOfWeek(\n interval: string,\n) {\n return interval === TimePolicyInterval.WEEKLY ||\n interval === TimePolicyInterval.MONTHLY ||\n interval === TimePolicyInterval.YEARLY;\n}\n\nexport function isIntervalForDayOfMonth(\n interval: string,\n) {\n return interval === TimePolicyInterval.MONTHLY ||\n interval === TimePolicyInterval.YEARLY;\n}\n\nexport function isIntervalForDayOfYear(\n interval: string,\n) {\n return interval === TimePolicyInterval.YEARLY;\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { createValidator } from '@validup/adapter-zod';\nimport { Container } from 'validup';\nimport { z } from 'zod';\nimport type { TimePolicy } from './types';\nimport { TimePolicyInterval } from './constants';\n\nexport class TimePolicyValidator extends Container<TimePolicy> {\n override initialize() {\n super.initialize();\n\n this.mount('day_of_week', createValidator(\n z.number()\n .min(0).max(6)\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ));\n this.mount('day_of_month', createValidator(\n z.number()\n .min(1)\n .max(31)\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ));\n this.mount('day_of_year', createValidator(\n z.number()\n .min(1)\n .max(365)\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ));\n\n this.mount('start', createValidator(\n z.date()\n .or(z.iso.datetime())\n .or(z.iso.time())\n .or(z.number())\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ));\n this.mount('end', createValidator(\n z.date()\n .or(z.iso.datetime())\n .or(z.iso.time())\n .or(z.number())\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ));\n\n this.mount(\n 'interval',\n createValidator(\n z.enum(TimePolicyInterval)\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n\n this.mount(\n 'invert',\n createValidator(\n z.boolean()\n .or(z.undefined())\n .or(z.null())\n .optional(),\n ),\n );\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { IPolicyEvaluator, PolicyEvaluationContext, PolicyEvaluationResult } from '../../evaluation';\nimport { maybeInvertPolicyOutcome } from '../../helpers';\nimport { BuiltInPolicyType } from '../constants';\nimport { isIntervalForDayOfMonth, isIntervalForDayOfWeek, isIntervalForDayOfYear } from './helpers';\nimport { TimePolicyValidator } from './validator';\n\nconst timeRegex = /^(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d)?$/;\n\nfunction normalizeDate(input: Date, dateRef?: Date) {\n const date = dateRef ? new Date(dateRef) : new Date();\n date.setHours(input.getHours(), input.getMinutes());\n\n return date;\n}\n\nfunction toDate(\n input: Date | string | number,\n dateRef?: Date,\n) : Date {\n if (typeof input === 'string') {\n if (timeRegex.test(input)) {\n const parts = input.split(':');\n\n const startHours = Number(parts[0]);\n const startMinutes = Number(parts[1]);\n const startSeconds = parts[2] !== undefined ? Number(parts[2]) : 0;\n\n if (\n Number.isFinite(startHours) &&\n Number.isFinite(startMinutes) &&\n Number.isFinite(startSeconds)\n ) {\n const date = dateRef ? new Date(dateRef) : new Date();\n date.setHours(startHours, startMinutes, startSeconds, 0);\n\n return date;\n }\n }\n\n return new Date(input);\n }\n\n if (typeof input === 'number') {\n return new Date(input);\n }\n\n return input;\n}\n\nexport class TimePolicyEvaluator implements IPolicyEvaluator {\n protected validator : TimePolicyValidator;\n\n constructor() {\n this.validator = new TimePolicyValidator();\n }\n\n async evaluate(value: Record<string, any>, ctx: PolicyEvaluationContext): Promise<PolicyEvaluationResult> {\n // todo: catch errors + transform to issue(s)\n const policy = await this.validator.run(value);\n\n let now : Date;\n\n if (ctx.data.has(BuiltInPolicyType.TIME)) {\n if (ctx.data.isValidated(BuiltInPolicyType.TIME)) {\n now = ctx.data.get<Date>(BuiltInPolicyType.TIME);\n } else {\n // todo: run validator on attributes (isObject ...)\n now = toDate(ctx.data.get(BuiltInPolicyType.TIME));\n\n ctx.data.set(BuiltInPolicyType.TIME, now);\n ctx.data.setValidated(BuiltInPolicyType.TIME);\n }\n } else {\n now = new Date();\n }\n\n if (policy.start) {\n const start = normalizeDate(toDate(policy.start, now), now);\n if (now < start) {\n return { success: maybeInvertPolicyOutcome(false, policy.invert) };\n }\n }\n\n if (policy.end) {\n const end = normalizeDate(toDate(policy.end, now), now);\n if (now > end) {\n return { success: maybeInvertPolicyOutcome(false, policy.invert) };\n }\n }\n\n if (policy.interval) {\n if (\n isIntervalForDayOfWeek(policy.interval) &&\n policy.day_of_week\n ) {\n if (now.getDay() !== policy.day_of_week) {\n return { success: maybeInvertPolicyOutcome(false, policy.invert) };\n }\n }\n\n if (\n isIntervalForDayOfMonth(policy.interval) &&\n policy.day_of_month\n ) {\n if (now.getDate() !== policy.day_of_month) {\n return { success: maybeInvertPolicyOutcome(false, policy.invert) };\n }\n }\n\n if (\n isIntervalForDayOfYear(policy.interval) &&\n policy.day_of_year\n ) {\n const start = new Date(now.getFullYear(), 0, 0);\n const diff = (now.getTime() - start.getTime()) +\n ((start.getTimezoneOffset() - now.getTimezoneOffset()) * 60 * 1000);\n\n const oneDay = 1000 * 60 * 60 * 24;\n const dayOfYear = Math.floor(diff / oneDay);\n\n if (dayOfYear !== policy.day_of_year) {\n return { success: maybeInvertPolicyOutcome(false, policy.invert) };\n }\n }\n }\n\n return { success: maybeInvertPolicyOutcome(true, policy.invert) };\n }\n}\n","/*\n * Copyright (c) 2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { PolicyWithType } from '../types';\nimport type { BuiltInPolicyTypeMap } from './types';\n\nexport function definePolicyWithType<\n K extends keyof BuiltInPolicyTypeMap,\n D extends BuiltInPolicyTypeMap<any>[K],\n>(\n type: K,\n data: D,\n) : PolicyWithType<D, K> {\n return {\n ...data,\n type,\n };\n}\n","/*\n * Copyright (c) 2026-2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport {\n AttributeNamesPolicyEvaluator,\n AttributesPolicyEvaluator,\n BuiltInPolicyType,\n CompositePolicyEvaluator,\n DatePolicyEvaluator,\n IdentityPolicyEvaluator,\n PermissionBindingPolicyEvaluator,\n RealmMatchPolicyEvaluator,\n TimePolicyEvaluator,\n} from './built-in';\n\nexport const PolicyDefaultEvaluators = {\n [BuiltInPolicyType.COMPOSITE]: new CompositePolicyEvaluator(),\n [BuiltInPolicyType.ATTRIBUTES]: new AttributesPolicyEvaluator(),\n [BuiltInPolicyType.ATTRIBUTE_NAMES]: new AttributeNamesPolicyEvaluator(),\n [BuiltInPolicyType.DATE]: new DatePolicyEvaluator(),\n [BuiltInPolicyType.IDENTITY]: new IdentityPolicyEvaluator(),\n [BuiltInPolicyType.PERMISSION_BINDING]: new PermissionBindingPolicyEvaluator(),\n [BuiltInPolicyType.REALM_MATCH]: new RealmMatchPolicyEvaluator(),\n [BuiltInPolicyType.TIME]: new TimePolicyEvaluator(),\n} as const;\n","/*\n * Copyright (c) 2021-2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { ErrorCode } from '@authup/errors';\nimport type { Issue } from 'validup';\nimport { defineIssueItem } from 'validup';\nimport { DecisionStrategy } from '../../constants.ts';\nimport type { CompositePolicy, IPolicyEngine } from '../../policy';\nimport {\n BuiltInPolicyType,\n PolicyData,\n PolicyDefaultEvaluators,\n PolicyEngine,\n definePolicyEvaluationContext,\n definePolicyIssueGroup,\n} from '../../policy';\nimport { PermissionError } from '../error';\nimport type { IPermissionProvider } from '../provider';\n\nimport type { PermissionPolicyBinding } from '../types.ts';\nimport type { IPermissionEvaluator, PermissionEvaluationContext, PermissionEvaluatorOptions } from './types.ts';\n\nexport class PermissionEvaluator implements IPermissionEvaluator {\n protected provider : IPermissionProvider;\n\n protected policyEngine : IPolicyEngine;\n\n protected clientId?: string | null;\n\n protected realmId?: string | null;\n\n // ----------------------------------------------\n\n constructor(options: PermissionEvaluatorOptions) {\n this.provider = options.provider;\n\n this.clientId = options.clientId || null;\n this.realmId = options.realmId || null;\n\n if (options.policyEngine) {\n this.policyEngine = options.policyEngine;\n } else {\n this.policyEngine = new PolicyEngine(PolicyDefaultEvaluators);\n }\n }\n\n // ----------------------------------------------\n\n protected async findOne(\n input: string,\n overrides: {\n realmId?: string | null,\n clientId?: string | null\n } = {},\n ) : Promise<PermissionPolicyBinding | null> {\n return this.provider.findOne({\n name: input,\n clientId: overrides.clientId ?? this.clientId,\n realmId: overrides.realmId ?? this.realmId,\n });\n }\n\n // ----------------------------------------------\n\n async evaluate(ctx: PermissionEvaluationContext) : Promise<void> {\n if (!Array.isArray(ctx.name)) {\n await this.evaluate({\n ...ctx,\n name: [ctx.name],\n });\n return;\n }\n\n const { options = {} } = ctx;\n\n const decisionStrategy = options.decisionStrategy ??\n DecisionStrategy.UNANIMOUS;\n\n const issues : Issue[] = [];\n\n let count = 0;\n\n const dataBase = ctx.input || new PolicyData();\n\n for (const name of ctx.name) {\n const binding = await this.findOne(name, {\n realmId: ctx.realmId,\n clientId: ctx.clientId,\n });\n if (!binding) {\n issues.push(defineIssueItem({\n code: ErrorCode.PERMISSION_NOT_FOUND,\n message: `The ${name} permission could not be resolved`,\n path: [name],\n }));\n\n if (decisionStrategy === DecisionStrategy.UNANIMOUS) {\n const error = PermissionError.evaluationFailed(ctx.name);\n error.addIssues(issues);\n throw error;\n }\n\n continue;\n }\n\n const policies = binding.policies ?? [];\n if (policies.length === 0) {\n if (decisionStrategy === DecisionStrategy.AFFIRMATIVE) {\n return;\n }\n\n count++;\n\n continue;\n }\n\n const data = dataBase.clone();\n data.set(BuiltInPolicyType.PERMISSION_BINDING, binding);\n\n const policyDecisionStrategy = binding.permission.decision_strategy ??\n DecisionStrategy.UNANIMOUS;\n\n const compositePolicy : CompositePolicy = {\n type: BuiltInPolicyType.COMPOSITE,\n decision_strategy: policyDecisionStrategy,\n children: policies,\n };\n\n const evaluationResult = await this.policyEngine.evaluate(\n compositePolicy,\n definePolicyEvaluationContext({\n include: options.policiesIncluded,\n exclude: options.policiesExcluded,\n data,\n }),\n );\n\n if (evaluationResult.success) {\n if (decisionStrategy === DecisionStrategy.AFFIRMATIVE) {\n return;\n }\n\n count++;\n } else {\n issues.push(definePolicyIssueGroup({\n code: ErrorCode.PERMISSION_EVALUATION_FAILED,\n issues: evaluationResult.issues || [],\n message: `The ${binding.permission.name} permissions policy evaluation failed`,\n path: [binding.permission.name],\n }));\n\n if (decisionStrategy === DecisionStrategy.UNANIMOUS) {\n const error = PermissionError.evaluationFailed(binding.permission.name);\n error.addIssues(issues);\n throw error;\n }\n\n count--;\n }\n }\n\n if (count > 0) {\n return;\n }\n\n if (issues.length === 0) {\n throw PermissionError.deniedAll(ctx.name);\n } else {\n const error = PermissionError.evaluationFailed(ctx.name);\n error.addIssues(issues);\n throw error;\n }\n }\n\n async evaluateOneOf(ctx: PermissionEvaluationContext) : Promise<void> {\n return this.evaluate({\n ...ctx,\n options: {\n ...(ctx.options || {}),\n decisionStrategy: DecisionStrategy.AFFIRMATIVE,\n },\n });\n }\n\n // ----------------------------------------------\n\n async preEvaluate(ctx: PermissionEvaluationContext) : Promise<void> {\n return this.evaluate({\n ...ctx,\n options: {\n ...(ctx.options || {}),\n policiesExcluded: [\n BuiltInPolicyType.ATTRIBUTES,\n BuiltInPolicyType.ATTRIBUTE_NAMES,\n BuiltInPolicyType.REALM_MATCH,\n ],\n },\n });\n }\n\n async preEvaluateOneOf(ctx: PermissionEvaluationContext) : Promise<void> {\n return this.preEvaluate({\n ...ctx,\n options: {\n ...(ctx.options || {}),\n decisionStrategy: DecisionStrategy.AFFIRMATIVE,\n },\n });\n }\n}\n"],"mappings":";;;;;;;AAWA,IAAa,kBAAb,MAAa,wBAAwB,YAAY;CAC7C,YAAY,UAA8B,EAAE,EAAE;AAC1C,QAAM;GACF,GAAG;GACH,SAAS,QAAQ,WAAW;GAC5B,YAAY,QAAQ,cAAc;GACrC,CAAC;;CAGN,SAAS,MAAmB;AACxB,OAAK,OAAO,KAAK,KAAK;;CAG1B,UAAU,MAAqB;AAC3B,OAAK,OAAO,KAAK,GAAG,KAAK;;CAG7B,OAAO,SAAS,MAAc;AAC1B,SAAO,IAAI,gBAAgB;GACvB,SAAS,kBAAkB,KAAK;GAChC,MAAM,UAAU;GACnB,CAAC;;CAGN,OAAO,OAAO,MAAc;AACxB,SAAO,IAAI,gBAAgB;GACvB,SAAS,kBAAkB,KAAK;GAChC,MAAM,UAAU;GACnB,CAAC;;CAGN,OAAO,UAAU,OAAiB;AAC9B,SAAO,IAAI,gBAAgB;GACvB,SAAS,2BAA2B,MAAM,KAAK,KAAK,CAAC;GACrD,MAAM,UAAU;GACnB,CAAC;;CAGN,OAAO,iBAAiB,MAAyB;AAC7C,MAAI,MAAM,QAAQ,KAAK,CACnB,QAAO,IAAI,gBAAgB;GACvB,SAAS,iCAAiC,KAAK,KAAK,KAAK,CAAC;GAC1D,MAAM,UAAU;GACnB,CAAC;AAGN,SAAO,IAAI,gBAAgB;GACvB,SAAS,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S;GACjB,GAAG;GACH,SAAS;IACL,GAAI,IAAI,WAAW,EAAE;IACrB,kBAAkB,iBAAiB;IACtC;GACJ,CAAC;;CAKN,MAAM,YAAY,KAAkD;AAChE,SAAO,KAAK,SAAS;GACjB,GAAG;GACH,SAAS;IACL,GAAI,IAAI,WAAW,EAAE;IACrB,kBAAkB;KACd,kBAAkB;KAClB,kBAAkB;KAClB,kBAAkB;KACrB;IACJ;GACJ,CAAC;;CAGN,MAAM,iBAAiB,KAAkD;AACrE,SAAO,KAAK,YAAY;GACpB,GAAG;GACH,SAAS;IACL,GAAI,IAAI,WAAW,EAAE;IACrB,kBAAkB,iBAAiB;IACtC;GACJ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["DecisionStrategy","normalizeDate","toDate"],"sources":["../src/permission/error/module.ts","../src/permission/helpers/equal.ts","../src/permission/helpers/key.ts","../src/permission/helpers/merge.ts","../src/permission/provider/memory.ts","../src/policy/helpers/invert.ts","../src/policy/error/module.ts","../src/policy/engine/module.ts","../src/policy/data.ts","../src/policy/evaluation/context/define.ts","../src/policy/issue/constants.ts","../src/policy/issue/define.ts","../src/policy/built-in/attribute-names/validator.ts","../src/policy/built-in/attributes/define.ts","../src/policy/built-in/constants.ts","../src/policy/built-in/attributes/validator.ts","../src/policy/built-in/attributes/evaluator.ts","../src/policy/built-in/attribute-names/evaluator.ts","../src/policy/built-in/composite/validator.ts","../src/policy/built-in/composite/evaluator.ts","../src/policy/built-in/composite/helper.ts","../src/policy/built-in/date/validator.ts","../src/policy/built-in/date/evaluator.ts","../src/policy/built-in/identity/data/validator.ts","../src/policy/built-in/identity/validator.ts","../src/policy/built-in/identity/evaluator.ts","../src/policy/built-in/permission-binding/validator.ts","../src/policy/built-in/permission-binding/module.ts","../src/policy/built-in/realm-match/validator.ts","../src/policy/built-in/realm-match/evaluator.ts","../src/policy/built-in/time/constants.ts","../src/policy/built-in/time/helpers.ts","../src/policy/built-in/time/validator.ts","../src/policy/built-in/time/evaluator.ts","../src/policy/built-in/define.ts","../src/policy/constants.ts","../src/permission/evaluator/module.ts"],"sourcesContent":["/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { AuthupErrorOptions } from '@authup/errors';\nimport { AuthupError, ErrorCode } from '@authup/errors';\nimport type { PolicyIssue } from '../../policy';\n\nexport class PermissionError extends AuthupError {\n constructor(options: AuthupErrorOptions = {}) {\n super({\n ...options,\n message: options.message || 'A permission error occurred.',\n statusCode: options.statusCode || 403,\n });\n }\n\n addIssue(data: PolicyIssue) {\n this.issues.push(data);\n }\n\n addIssues(data: PolicyIssue[]) {\n this.issues.push(...data);\n }\n\n static notFound(name: string) {\n return new PermissionError({\n message: `The permission ${name} was not found.`,\n code: ErrorCode.PERMISSION_NOT_FOUND,\n });\n }\n\n static denied(name: string) {\n return new PermissionError({\n message: `The permission ${name} has not been granted.`,\n code: ErrorCode.PERMISSION_DENIED,\n });\n }\n\n static deniedAll(names: string[]) {\n return new PermissionError({\n message: `None of the permissions ${names.join(', ')} has been granted.`,\n code: ErrorCode.PERMISSION_DENIED,\n });\n }\n\n static evaluationFailed(name: string | string[]) {\n if (Array.isArray(name)) {\n return new PermissionError({\n message: `The evaluation of permissions ${name.join(', ')} failed`,\n code: ErrorCode.PERMISSION_EVALUATION_FAILED,\n });\n }\n\n return new PermissionError({\n message: `The evaluation of permission ${name} failed`,\n code: ErrorCode.PERMISSION_EVALUATION_FAILED,\n });\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { PermissionPolicyBinding } from '../types';\n\nexport function isPermissionPolicyBindingEqual(a: PermissionPolicyBinding, b: PermissionPolicyBinding): boolean {\n if (a.permission.name !== b.permission.name) {\n return false;\n }\n\n if ((a.permission.realm_id ?? null) !== (b.permission.realm_id ?? null)) {\n return false;\n }\n\n if ((a.permission.client_id ?? null) !== (b.permission.client_id ?? null)) {\n return false;\n }\n\n return true;\n}\n","/*\n * Copyright (c) 2025-2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\n\nimport type { BasePermission } from '../types.ts';\n\nfunction formatKeySegment(value?: string | null): string {\n return value || '*';\n}\n\nexport function buildPermissionKey(\n input: BasePermission,\n) {\n return `${formatKeySegment(input.realm_id)}/${formatKeySegment(input.client_id)}/${input.name}`;\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { DecisionStrategy } from '@authup/kit';\nimport type { BasePolicy } from '../../policy';\nimport type { PermissionPolicyBinding } from '../types';\nimport { buildPermissionKey } from './key';\n\ntype CompositePolicy = BasePolicy & {\n decision_strategy?: `${DecisionStrategy}`,\n children: BasePolicy[],\n};\n\nexport function mergePermissionPolicyBindings(input: PermissionPolicyBinding[]) : PermissionPolicyBinding[] {\n const grouped : Record<string, PermissionPolicyBinding[]> = input\n .reduce((previous, current) => {\n const key = buildPermissionKey(current.permission);\n if (!previous[key]) {\n previous[key] = [];\n }\n\n previous[key].push(current);\n\n return previous;\n }, {} as Record<string, PermissionPolicyBinding[]>);\n\n const output : PermissionPolicyBinding[] = [];\n const keys = Object.keys(grouped);\n for (const key of keys) {\n const group = grouped[key]!;\n const first = group[0]!;\n\n if (group.length === 1) {\n output.push(first);\n continue;\n }\n\n const children : BasePolicy[] = [];\n\n for (const element of group) {\n if (!element.policies || element.policies.length === 0) {\n continue;\n }\n\n const policy: CompositePolicy = {\n type: 'composite',\n decision_strategy: element.permission.decision_strategy || DecisionStrategy.UNANIMOUS,\n children: element.policies,\n };\n\n children.push(policy);\n }\n\n let mergedPolicies: BasePolicy[] | undefined;\n\n if (\n children.length > 0 &&\n children.length === group.length\n ) {\n const policy: CompositePolicy = {\n type: 'composite',\n decision_strategy: DecisionStrategy.AFFIRMATIVE,\n children,\n };\n\n mergedPolicies = [policy];\n }\n\n output.push({\n permission: {\n ...first.permission,\n decision_strategy: DecisionStrategy.AFFIRMATIVE,\n },\n policies: mergedPolicies,\n });\n }\n\n return output;\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { buildPermissionKey, mergePermissionPolicyBindings } from '../helpers';\nimport type { PermissionPolicyBinding } from '../types';\nimport type { IPermissionProvider, PermissionGetOptions } from './types';\n\nexport class PermissionMemoryProvider implements IPermissionProvider {\n protected items : Record<string, PermissionPolicyBinding> = {};\n\n constructor(items: PermissionPolicyBinding[] = []) {\n this.setMany(items);\n }\n\n async findOne(\n options: PermissionGetOptions,\n ): Promise<PermissionPolicyBinding | null> {\n const key = buildPermissionKey({\n name: options.name,\n client_id: options.clientId,\n realm_id: options.realmId,\n });\n\n const entry = this.items[key];\n if (entry) {\n return entry;\n }\n\n return null;\n }\n\n setMany(input: PermissionPolicyBinding[]) {\n this.items = mergePermissionPolicyBindings(input)\n .reduce((prev, current) => {\n const key = buildPermissionKey(current.permission);\n prev[key] = current;\n return prev;\n }, {} as Record<string, PermissionPolicyBinding>);\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\ntype InvertFn = (input: boolean) => boolean;\n\nexport function maybeInvertPolicyOutcome(\n outcome: boolean,\n invert?: boolean | InvertFn,\n) {\n if (typeof invert === 'undefined') {\n return outcome;\n }\n\n if (typeof invert === 'function') {\n return invert(outcome);\n }\n\n if (!invert) {\n return outcome;\n }\n\n return !outcome;\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { AuthupError, ErrorCode } from '@authup/errors';\nimport type { PolicyIssue } from '../issue';\n\nexport class PolicyError extends AuthupError {\n constructor(message?: string, code?: string | null) {\n super({\n message,\n code, \n });\n }\n\n addIssue(data: PolicyIssue) {\n this.issues.push(data);\n }\n\n addIssues(data: PolicyIssue[]) {\n this.issues.push(...data);\n }\n\n static evaluatorNotFound(type: string) {\n return new PolicyError(\n `No evaluator is registered to handle the policy: ${type}`,\n ErrorCode.POLICY_EVALUATOR_NOT_FOUND,\n );\n }\n\n static evaluatorNotProcessable() {\n return new PolicyError(\n 'The evaluator can not process the policy.',\n ErrorCode.POLICY_EVALUATOR_NOT_PROCESSABLE,\n );\n }\n\n static evaluatorContextInvalid() {\n return new PolicyError(\n 'The evaluator context is not valid.',\n ErrorCode.POLICY_EVALUATOR_CONTEXT_INVALID,\n );\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { ErrorCode } from '@authup/errors';\nimport { defineIssueItem } from 'validup';\nimport type {\n IPolicyEvaluator,\n PolicyEvaluationContext,\n PolicyEvaluationResult,\n PolicyEvaluators,\n} from '../evaluation';\nimport { maybeInvertPolicyOutcome } from '../helpers';\nimport type { PolicyIssue } from '../issue';\nimport type { IPolicyEngine } from './types.ts';\nimport { PolicyError } from '../error';\nimport type { BasePolicy } from '../types.ts';\n\n/**\n * The policy engine is a component that interprets defined policies and makes decisions\n * on whether to allow or deny a particular access.\n */\nexport class PolicyEngine implements IPolicyEngine {\n protected evaluators : Record<string, IPolicyEvaluator>;\n\n constructor(evaluators: PolicyEvaluators = {}) {\n this.evaluators = evaluators;\n }\n\n public registerEvaluator(\n type: string,\n evaluator: IPolicyEvaluator,\n ) : void {\n this.evaluators[type] = evaluator;\n }\n\n public registerEvaluators(evaluators: PolicyEvaluators) {\n const keys = Object.keys(evaluators);\n for (const key of keys) {\n this.registerEvaluator(key, evaluators[key]!);\n }\n }\n\n /**\n * @param policy\n * @param ctx\n */\n async evaluate(policy: BasePolicy, ctx: PolicyEvaluationContext) : Promise<PolicyEvaluationResult> {\n if (!policy.type) {\n return {\n success: maybeInvertPolicyOutcome(false, policy.invert),\n issues: [\n defineIssueItem({\n path: [],\n message: 'The policy can not be handled by any evaluator.',\n code: ErrorCode.POLICY_EVALUATOR_NOT_FOUND,\n }),\n ],\n };\n }\n if (\n ctx.exclude &&\n ctx.exclude.length > 0 &&\n ctx.exclude.includes(policy.type)\n ) {\n return { success: maybeInvertPolicyOutcome(true, policy.invert) };\n }\n\n if (\n ctx.include &&\n ctx.include.length > 0 &&\n !ctx.include.includes(policy.type)\n ) {\n return { success: maybeInvertPolicyOutcome(true, policy.invert) };\n }\n\n const issues : PolicyIssue[] = [];\n\n const evaluator = this.evaluators[policy.type];\n if (!evaluator) {\n // todo: add issue here instead + return false ?\n issues.push(defineIssueItem({\n path: [policy.type],\n message: `The policy ${policy.type} can not be handled by any evaluator.`,\n code: ErrorCode.POLICY_EVALUATOR_NOT_FOUND,\n }));\n\n return {\n success: maybeInvertPolicyOutcome(false, policy.invert),\n issues,\n };\n }\n\n try {\n return await evaluator.evaluate(policy, {\n ...ctx,\n evaluators: {\n ...this.evaluators,\n ...(ctx.evaluators || {}),\n },\n });\n } catch {\n issues.push(defineIssueItem({\n path: [policy.type],\n message: `The ${policy.type} evaluator can not process the policy specification.`,\n code: ErrorCode.POLICY_EVALUATOR_NOT_PROCESSABLE,\n }));\n\n return {\n success: maybeInvertPolicyOutcome(false, policy.invert),\n issues,\n };\n }\n }\n\n async evaluateOrFail(policy: BasePolicy, ctx: PolicyEvaluationContext) : Promise<void> {\n const issues : PolicyIssue[] = [];\n\n try {\n const outcome = await this.evaluate(policy, ctx);\n if (outcome.success) {\n return;\n }\n\n if (outcome.issues) {\n issues.push(...outcome.issues);\n }\n } catch (e) {\n if (e instanceof PolicyError) {\n throw e;\n }\n }\n\n const error = new PolicyError(`The policy ${policy.type} evaluation failed.`);\n error.addIssues(issues);\n\n throw error;\n }\n}\n","/*\n * Copyright (c) 2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport interface IPolicyData {\n set(key: string, value: unknown) : void;\n has(key: string): boolean;\n get<T = unknown>(key: string) : T;\n\n isValidated(key: string): boolean;\n setValidated(key: string) : void;\n\n clone() : IPolicyData\n}\n\nexport class PolicyData implements IPolicyData {\n protected data: Record<string, any>;\n\n protected validated : Set<string>;\n\n constructor(\n data: Record<string, any> = {},\n validated: Set<string> = new Set(),\n ) {\n this.data = data;\n this.validated = validated;\n }\n\n set<T = unknown>(key: string, value: T) : void {\n this.data[key] = value;\n this.validated.delete(key);\n }\n\n get<T = unknown>(key: string) : T {\n if (key in this.data) {\n return this.data[key];\n }\n\n throw new Error(`Policy data item ${key} does not exist.`);\n }\n\n has(key: string): boolean {\n return key in this.data;\n }\n\n setValidated(key: string) : void {\n this.validated.add(key);\n }\n\n isValidated(key: string) : boolean {\n return this.validated.has(key);\n }\n\n clone() {\n return new PolicyData({ ...this.data }, new Set(this.validated));\n }\n}\n","/*\n * Copyright (c) 2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { PolicyEvaluationContext, PolicyEvaluationContextInput } from './types.ts';\nimport { PolicyData } from '../../data.ts';\n\nexport function definePolicyEvaluationContext(\n input: PolicyEvaluationContextInput = {},\n) : PolicyEvaluationContext {\n return {\n evaluators: input.evaluators || {},\n path: input.path || [],\n data: input.data || new PolicyData(),\n include: input.include || [],\n exclude: input.exclude || [],\n };\n}\n","/*\n * Copyright (c) 2026-2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum PolicyIssueSeverity {\n WARNING = 'warning',\n ERROR = 'error',\n}\n\nexport enum PolicyIssueCode {\n // Data/Input\n DATA_MISSING = 'DATA_MISSING',\n DATA_INVALID = 'DATA_INVALID',\n\n // Policy Spec / Config\n INVALID = 'INVALID',\n TYPE_UNKNOWN = 'TYPE_UNKNOWN',\n FIELD_MISSING = 'FIELD_MISSING',\n FIELD_INVALID = 'FIELD_INVALID',\n\n // Composite / Tree evaluation\n CHILD_INVALID = 'CHILD_INVALID',\n CHILD_EVALUATION_FAILED = 'CHILD_EVALUATION_FAILED',\n\n // Engine / Evaluator registry\n EVALUATION_DENIED = 'EVALUATION_DENIED',\n EVALUATOR_NOT_FOUND = 'EVALUATOR_NOT_FOUND',\n EVALUATOR_ERROR = 'EVALUATOR_ERROR',\n\n // Execution control\n SKIPPED_EXCLUDED = 'SKIPPED_EXCLUDED',\n SKIPPED_NOT_INCLUDED = 'SKIPPED_NOT_INCLUDED',\n\n // Internal / unexpected\n INTERNAL_ERROR = 'INTERNAL_ERROR',\n}\n","/*\n * Copyright (c) 2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { defineIssueGroup, defineIssueItem } from 'validup';\nimport type { PolicyIssueGroup, PolicyIssueItem } from './types.ts';\n\nexport function definePolicyIssueItem(input: Omit<PolicyIssueItem, 'type'>) : PolicyIssueItem {\n return defineIssueItem(input);\n}\n\nexport function definePolicyIssueGroup(input: Omit<PolicyIssueGroup, 'type'>) : PolicyIssueGroup {\n return defineIssueGroup(input);\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { createValidator } from '@validup/adapter-zod';\nimport { Container } from 'validup';\nimport { z } from 'zod';\nimport type { AttributeNamesPolicy } from './types';\n\nexport class AttributeNamesPolicyValidator extends Container<AttributeNamesPolicy> {\n override initialize() {\n super.initialize();\n\n this.mount(\n 'names',\n createValidator(\n z.array(\n z.string()\n .min(3)\n .max(128),\n ),\n ),\n );\n\n this.mount(\n 'invert',\n createValidator(\n z.boolean()\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n }\n}\n","/*\n * Copyright (c) 2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { AttributesPolicy } from './types';\n\nexport function defineAttributesPolicy<\n T extends Record<string, any> = Record<string, any>,\n>(\n data: AttributesPolicy<T>,\n) : AttributesPolicy<T> {\n return data;\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum BuiltInPolicyType {\n /**\n * Bundles different policies.\n */\n COMPOSITE = 'composite',\n /**\n * Date Based Access Control (DBAC)\n */\n DATE = 'date',\n /**\n * Time Based Access Control (TBAC)\n */\n TIME = 'time',\n /**\n * Attribute Name Based Access Control (ANBAC)\n */\n ATTRIBUTE_NAMES = 'attributeNames',\n /**\n * Attribute Based Access Control (ABAC)\n */\n ATTRIBUTES = 'attributes',\n /**\n * Realm of Identity is for attribute realm.\n */\n REALM_MATCH = 'realmMatch',\n\n /**\n * Restriction based on identity (type, id, ...)\n */\n IDENTITY = 'identity',\n\n /**\n * Restriction based on a binding between identity <-> permission\n */\n PERMISSION_BINDING = 'permissionBinding',\n\n // Location (LBAC)\n // Device (DBAC)\n}\n\nexport const SystemPolicyName = {\n DEFAULT: 'system.default',\n IDENTITY: 'system.identity',\n PERMISSION_BINDING: 'system.permission-binding',\n REALM_MATCH: 'system.realm-match',\n REALM_BOUND: 'system.realm-bound',\n REALM_OR_GLOBAL: 'system.realm-or-global',\n} as const;\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { createValidator } from '@validup/adapter-zod';\nimport { Container } from 'validup';\nimport { z } from 'zod';\nimport type { AttributesPolicy } from './types';\n\nexport class AttributesPolicyValidator<\n T extends Record<string, any> = Record<string, any>,\n> extends Container<AttributesPolicy<T>> {\n override initialize() {\n super.initialize();\n\n this.mount(\n 'query',\n createValidator(\n z.looseObject({}),\n ),\n );\n\n this.mount(\n 'invert',\n createValidator(\n z.boolean()\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { guard } from '@ucast/mongo2js';\nimport { isObject } from '@authup/kit';\nimport type { IPolicyEvaluator, PolicyEvaluationContext, PolicyEvaluationResult } from '../../evaluation';\nimport { maybeInvertPolicyOutcome } from '../../helpers';\nimport { PolicyIssueCode, definePolicyIssueItem } from '../../issue';\nimport { BuiltInPolicyType } from '../constants.ts';\nimport { AttributesPolicyValidator } from './validator';\n\nexport class AttributesPolicyEvaluator<\n T extends Record<string, any> = Record<string, any>,\n> implements IPolicyEvaluator {\n protected validator : AttributesPolicyValidator<T>;\n\n constructor() {\n this.validator = new AttributesPolicyValidator<T>();\n }\n\n async accessData(ctx: PolicyEvaluationContext) : Promise<T | null> {\n if (!ctx.data.has(BuiltInPolicyType.ATTRIBUTES)) {\n return null;\n }\n\n if (ctx.data.isValidated(BuiltInPolicyType.ATTRIBUTES)) {\n return ctx.data.get<T>(BuiltInPolicyType.ATTRIBUTES);\n }\n\n // todo: run validator on attributes (isObject ...)\n const data = ctx.data.get<T>(BuiltInPolicyType.ATTRIBUTES);\n\n ctx.data.set(BuiltInPolicyType.ATTRIBUTES, data);\n ctx.data.setValidated(BuiltInPolicyType.ATTRIBUTES);\n\n return data;\n }\n\n async evaluate(value: Record<string, any>, ctx: PolicyEvaluationContext): Promise<PolicyEvaluationResult> {\n // todo: catch errors + transform to issue(s)\n const policy = await this.validator.run(value);\n\n const data = await this.accessData(ctx);\n if (!data) {\n return {\n success: false,\n issues: [\n definePolicyIssueItem({\n code: PolicyIssueCode.DATA_MISSING,\n message: 'The data property attributes is missing',\n path: ctx.path,\n }),\n ],\n };\n }\n\n this.fixQuery(policy.query);\n\n const testIt = guard<T>(policy.query);\n\n return { success: maybeInvertPolicyOutcome(testIt(data as T), policy.invert) };\n }\n\n protected fixQuery(\n query: unknown | unknown[],\n ) {\n if (Array.isArray(query)) {\n for (const element of query) {\n this.fixQuery(element);\n }\n\n return;\n }\n\n if (isObject(query)) {\n const keys = Object.keys(query);\n for (const key of keys) {\n const value = query[key];\n\n if (isObject(value) || Array.isArray(value)) {\n this.fixQuery(value);\n continue;\n }\n\n if (\n key === '$regex' &&\n typeof value === 'string'\n ) {\n const fragments = value.match(/\\/(.*?)\\/([a-z]*)?$/i);\n if (fragments && fragments[1] !== undefined) {\n query[key] = new RegExp(fragments[1], fragments[2] || '');\n }\n }\n }\n }\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { flattenObject } from '@authup/kit';\nimport type { IPolicyEvaluator, PolicyEvaluationContext, PolicyEvaluationResult } from '../../evaluation';\nimport { maybeInvertPolicyOutcome } from '../../helpers';\nimport type { PolicyIssue } from '../../issue';\nimport { PolicyIssueCode, definePolicyIssueItem } from '../../issue';\nimport { AttributeNamesPolicyValidator } from './validator';\nimport { AttributesPolicyEvaluator } from '../attributes';\n\nexport class AttributeNamesPolicyEvaluator implements IPolicyEvaluator {\n protected validator : AttributeNamesPolicyValidator;\n\n protected attributesEvaluator : AttributesPolicyEvaluator;\n\n constructor() {\n this.validator = new AttributeNamesPolicyValidator();\n this.attributesEvaluator = new AttributesPolicyEvaluator();\n }\n\n async evaluate(value: Record<string, any>, ctx: PolicyEvaluationContext): Promise<PolicyEvaluationResult> {\n // todo: catch errors + transform to issue(s)\n const policy = await this.validator.run(value);\n\n const data = await this.attributesEvaluator.accessData(ctx);\n if (!data) {\n return {\n success: false,\n issues: [\n definePolicyIssueItem({\n code: PolicyIssueCode.DATA_MISSING,\n message: 'The data property attributes is missing',\n path: ctx.path,\n }),\n ],\n };\n }\n\n const attributes = flattenObject(data);\n const keys = Object.keys(attributes);\n\n const issues : PolicyIssue[] = [];\n for (const key of keys) {\n const index = policy.names.indexOf(key);\n if (index === -1) {\n issues.push(definePolicyIssueItem({\n code: PolicyIssueCode.EVALUATION_DENIED,\n message: `The attribute ${key} is not included`,\n path: [...ctx.path, key],\n }));\n }\n }\n\n return {\n success: maybeInvertPolicyOutcome(issues.length === 0, policy.invert),\n issues,\n };\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { createValidator } from '@validup/adapter-zod';\nimport { Container } from 'validup';\nimport { z } from 'zod';\nimport { DecisionStrategy } from '../../../constants';\nimport type { CompositePolicy } from './types';\n\nexport class CompositePolicyValidator extends Container<CompositePolicy> {\n override initialize() {\n super.initialize();\n\n this.mount(\n 'decision_strategy',\n createValidator(\n z.enum(DecisionStrategy)\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n\n this.mount(\n 'children',\n createValidator(\n z.array(z.looseObject({ type: z.string().min(3) })),\n ),\n );\n\n this.mount(\n 'invert',\n createValidator(\n z.boolean()\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { defineIssueGroup } from 'validup';\nimport { DecisionStrategy } from '../../../constants';\nimport { PolicyEngine } from '../../engine';\nimport type { IPolicyEvaluator, PolicyEvaluationContext, PolicyEvaluationResult } from '../../evaluation';\nimport { maybeInvertPolicyOutcome } from '../../helpers';\nimport type { PolicyIssue } from '../../issue';\nimport { CompositePolicyValidator } from './validator';\n\nexport class CompositePolicyEvaluator implements IPolicyEvaluator {\n protected validator : CompositePolicyValidator;\n\n constructor() {\n this.validator = new CompositePolicyValidator();\n }\n\n async evaluate(value: Record<string, any>, ctx: PolicyEvaluationContext): Promise<PolicyEvaluationResult> {\n // todo: catch errors + transform to issue(s)\n const policy = await this.validator.run(value);\n\n let count = 0;\n\n const decision_strategy = policy.decision_strategy ??\n DecisionStrategy.UNANIMOUS;\n\n const engine = new PolicyEngine(ctx.evaluators);\n const issues : PolicyIssue[] = [];\n\n for (const childPolicy of policy.children) {\n const path = [\n ...(ctx.path || []),\n ...(childPolicy.type ? [childPolicy.type] : []),\n ];\n\n const outcome = await engine.evaluate(childPolicy, {\n ...ctx,\n path,\n });\n\n if (outcome.success) {\n if (decision_strategy === DecisionStrategy.AFFIRMATIVE) {\n return {\n success: maybeInvertPolicyOutcome(true, policy.invert),\n issues: [],\n };\n }\n\n count++;\n } else {\n if (outcome.issues) {\n issues.push(defineIssueGroup({\n message: `The evaluation of child policy ${childPolicy.type} failed`,\n issues: outcome.issues || [],\n path,\n }));\n }\n\n if (decision_strategy === DecisionStrategy.UNANIMOUS) {\n return {\n success: maybeInvertPolicyOutcome(false, policy.invert),\n issues: [\n defineIssueGroup({\n message: `The evaluation of composite policy failed (${DecisionStrategy.UNANIMOUS})`,\n issues,\n path: ctx.path,\n }),\n ],\n };\n }\n\n count--;\n }\n }\n\n if (count > 0) {\n return { success: maybeInvertPolicyOutcome(true, policy.invert) };\n }\n\n return {\n success: maybeInvertPolicyOutcome(false, policy.invert),\n issues: [\n defineIssueGroup({\n message: `The evaluation of composite policy failed (${DecisionStrategy.CONSENSUS})`,\n issues: issues || [],\n path: ctx.path,\n }),\n ],\n };\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { PolicyWithType } from '../../types';\nimport { BuiltInPolicyType } from '../constants';\nimport type { CompositePolicy } from './types';\n\nexport function isCompositePolicy(\n input: PolicyWithType,\n) : input is PolicyWithType<CompositePolicy> {\n return input.type === BuiltInPolicyType.COMPOSITE;\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { createValidator } from '@validup/adapter-zod';\nimport { Container } from 'validup';\nimport { z } from 'zod';\nimport type { DatePolicy } from './types';\n\nexport class DatePolicyValidator extends Container<DatePolicy> {\n override initialize() {\n super.initialize();\n\n this.mount('start', createValidator(\n z.date()\n .or(z.iso.date())\n .or(z.number())\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ));\n this.mount('end', createValidator(\n z.date()\n .or(z.iso.date())\n .or(z.number())\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ));\n\n this.mount('invert', createValidator(\n z.boolean()\n .or(z.undefined())\n .or(z.null())\n .optional(),\n ));\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { IPolicyEvaluator, PolicyEvaluationContext, PolicyEvaluationResult } from '../../evaluation';\nimport { maybeInvertPolicyOutcome } from '../../helpers';\nimport { BuiltInPolicyType } from '../constants.ts';\nimport { DatePolicyValidator } from './validator';\n\nfunction normalizeDate(input: Date) {\n return new Date(input.getFullYear(), input.getMonth(), input.getDate());\n}\n\nfunction toDate(input: Date | string | number) : Date {\n if (typeof input === 'string') {\n return new Date(input);\n }\n\n if (typeof input === 'number') {\n return new Date(input);\n }\n\n return input;\n}\n\nexport class DatePolicyEvaluator implements IPolicyEvaluator {\n protected validator : DatePolicyValidator;\n\n constructor() {\n this.validator = new DatePolicyValidator();\n }\n\n async evaluate(value: Record<string, any>, ctx: PolicyEvaluationContext): Promise<PolicyEvaluationResult> {\n // todo: catch errors + transform to issue(s)\n const policy = await this.validator.run(value);\n\n let now : Date;\n\n if (ctx.data.has(BuiltInPolicyType.DATE)) {\n if (ctx.data.isValidated(BuiltInPolicyType.DATE)) {\n now = ctx.data.get<Date>(BuiltInPolicyType.DATE);\n } else {\n // todo: run validator on attributes (isObject ...)\n now = normalizeDate(toDate(ctx.data.get(BuiltInPolicyType.DATE)));\n\n ctx.data.set(BuiltInPolicyType.DATE, now);\n ctx.data.setValidated(BuiltInPolicyType.DATE);\n }\n } else {\n now = normalizeDate(new Date());\n }\n\n if (policy.start) {\n const start = normalizeDate(toDate(policy.start));\n if (now < start) {\n return { success: maybeInvertPolicyOutcome(false, policy.invert) };\n }\n }\n\n if (policy.end) {\n const end = normalizeDate(toDate(policy.end));\n if (now > end) {\n return { success: maybeInvertPolicyOutcome(false, policy.invert) };\n }\n }\n\n return { success: maybeInvertPolicyOutcome(true, policy.invert) };\n }\n}\n","/*\n * Copyright (c) 2024-2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { createValidator } from '@validup/adapter-zod';\nimport { Container } from 'validup';\nimport { z } from 'zod';\n\nimport type { IdentityPolicyData } from '../types.ts';\n\nexport class PolicyIdentityDataValidator extends Container<IdentityPolicyData> {\n override initialize() {\n super.initialize();\n\n this.mount(\n 'type',\n createValidator(\n z.string().min(3).max(128),\n ),\n );\n\n this.mount(\n 'id',\n createValidator(\n z.uuid(),\n ),\n );\n\n this.mount(\n 'clientId',\n createValidator(\n z.uuid()\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n\n this.mount(\n 'realmId',\n createValidator(\n z.uuid()\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n\n this.mount(\n 'realmName',\n createValidator(\n z.string().min(3).max(128)\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { createValidator } from '@validup/adapter-zod';\nimport { Container } from 'validup';\nimport { z } from 'zod';\nimport type { IdentityPolicy } from './types';\n\nexport class IdentityPolicyValidator extends Container<IdentityPolicy> {\n override initialize() {\n this.mount(\n 'types',\n createValidator(\n z.array(z.string())\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n\n this.mount(\n 'invert',\n createValidator(\n z.boolean()\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { IPolicyEvaluator, PolicyEvaluationContext, PolicyEvaluationResult } from '../../evaluation';\nimport { PolicyIssueCode, definePolicyIssueItem } from '../../issue';\nimport { maybeInvertPolicyOutcome } from '../../helpers';\nimport { PolicyIdentityDataValidator } from './data';\nimport type { IdentityPolicyData } from './types';\nimport { IdentityPolicyValidator } from './validator';\n\nexport class IdentityPolicyEvaluator implements IPolicyEvaluator {\n protected validator : IdentityPolicyValidator;\n\n protected dataValidator : PolicyIdentityDataValidator;\n\n constructor() {\n this.validator = new IdentityPolicyValidator();\n this.dataValidator = new PolicyIdentityDataValidator();\n }\n\n async accessData(ctx: PolicyEvaluationContext) : Promise<IdentityPolicyData | null> {\n if (!ctx.data.has('identity')) {\n return null;\n }\n\n if (ctx.data.isValidated('identity')) {\n return ctx.data.get<IdentityPolicyData>('identity');\n }\n\n const data = await this.dataValidator.run(ctx.data.get('identity'));\n\n ctx.data.set('identity', data);\n ctx.data.setValidated('identity');\n\n return data;\n }\n\n async evaluate(value: Record<string, any>, ctx: PolicyEvaluationContext): Promise<PolicyEvaluationResult> {\n // todo: catch errors + transform to issue(s)\n const policy = await this.validator.run(value);\n\n const data = await this.accessData(ctx);\n if (!data) {\n return {\n success: false,\n issues: [\n definePolicyIssueItem({\n code: PolicyIssueCode.DATA_MISSING,\n message: 'The data property identity is missing',\n path: ctx.path,\n }),\n ],\n };\n }\n\n if (!policy.types || policy.types.length === 0) {\n return { success: maybeInvertPolicyOutcome(true, policy.invert) };\n }\n\n const typeAllowed = policy.types.includes(data.type);\n if (typeAllowed) {\n return { success: maybeInvertPolicyOutcome(typeAllowed, policy.invert) };\n }\n\n return {\n success: maybeInvertPolicyOutcome(typeAllowed, policy.invert),\n issues: [\n definePolicyIssueItem({\n code: PolicyIssueCode.EVALUATION_DENIED,\n message: `The type ${data.type} is not covered by the policy configuration`,\n path: ctx.path,\n }),\n ],\n };\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { Container } from 'validup';\nimport type { PermissionBindingPolicy } from './types';\n\nexport class PermissionBindingPolicyValidator extends Container<PermissionBindingPolicy> {\n override initialize() {\n\n }\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { IPolicyEvaluator, PolicyEvaluationResult } from '../../evaluation';\nimport { maybeInvertPolicyOutcome } from '../../helpers';\nimport { PermissionBindingPolicyValidator } from './validator';\n\nexport class PermissionBindingPolicyEvaluator implements IPolicyEvaluator {\n protected validator: PermissionBindingPolicyValidator;\n\n constructor() {\n this.validator = new PermissionBindingPolicyValidator();\n }\n\n async evaluate(value: Record<string, any>): Promise<PolicyEvaluationResult> {\n const policy = await this.validator.run(value);\n\n // todo: this must be changed when the permission-checker not only checks owned permissions.\n return { success: maybeInvertPolicyOutcome(true, policy.invert) };\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { createValidator } from '@validup/adapter-zod';\nimport { Container } from 'validup';\nimport { z } from 'zod';\nimport { DecisionStrategy } from '../../../constants';\nimport type { RealmMatchPolicy } from './types';\n\nexport class RealmMatchPolicyValidator extends Container<RealmMatchPolicy> {\n override initialize() {\n super.initialize();\n\n this.mount(\n 'decision_strategy',\n createValidator(\n z.enum(DecisionStrategy)\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n\n this.mount(\n 'attribute_name',\n createValidator(\n z.string()\n .min(3)\n .or(z.array(z.string().min(3)))\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n this.mount(\n 'attribute_name_strict',\n createValidator(\n z.boolean()\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n this.mount(\n 'attribute_null_match_all',\n createValidator(\n z.boolean()\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n\n this.mount(\n 'identity_master_match_all',\n createValidator(\n z.boolean()\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n\n this.mount(\n 'invert',\n createValidator(\n z.boolean()\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { hasOwnProperty } from '@authup/kit';\nimport { DecisionStrategy } from '../../../constants';\nimport type { IPolicyEvaluator, PolicyEvaluationContext, PolicyEvaluationResult } from '../../evaluation';\nimport { maybeInvertPolicyOutcome } from '../../helpers';\nimport { PolicyIssueCode, definePolicyIssueItem } from '../../issue';\nimport { AttributesPolicyEvaluator } from '../attributes';\nimport { IdentityPolicyEvaluator } from '../identity';\nimport { RealmMatchPolicyValidator } from './validator';\n\nexport class RealmMatchPolicyEvaluator implements IPolicyEvaluator {\n protected validator : RealmMatchPolicyValidator;\n\n protected identityEvaluator: IdentityPolicyEvaluator;\n\n protected attributesEvaluator : AttributesPolicyEvaluator;\n\n constructor() {\n this.validator = new RealmMatchPolicyValidator();\n this.identityEvaluator = new IdentityPolicyEvaluator();\n this.attributesEvaluator = new AttributesPolicyEvaluator();\n }\n\n async evaluate(value: Record<string, any>, ctx: PolicyEvaluationContext): Promise<PolicyEvaluationResult> {\n // todo: catch errors + transform to issue(s)\n const policy = await this.validator.run(value);\n\n const identity = await this.identityEvaluator.accessData(ctx);\n if (!identity) {\n return {\n success: false,\n issues: [\n definePolicyIssueItem({\n code: PolicyIssueCode.DATA_MISSING,\n message: 'The data property identity is missing',\n path: ctx.path,\n }),\n ],\n };\n }\n\n const attributes = await this.attributesEvaluator.accessData(ctx);\n if (!attributes) {\n return {\n success: false,\n issues: [\n definePolicyIssueItem({\n code: PolicyIssueCode.DATA_MISSING,\n message: 'The data property attributes is missing',\n path: ctx.path,\n }),\n ],\n };\n }\n\n const identityMasterMatchAll = policy.identity_master_match_all ?? true;\n if (\n identityMasterMatchAll &&\n identity.realmName &&\n identity.realmName === 'master'\n ) {\n return { success: maybeInvertPolicyOutcome(true, policy.invert) };\n }\n\n let keys : string[];\n if (policy.attribute_name) {\n if (Array.isArray(policy.attribute_name)) {\n keys = policy.attribute_name;\n } else {\n keys = [policy.attribute_name];\n }\n } else {\n keys = [\n 'realm_id',\n 'realm_name',\n 'realmId',\n 'realmName',\n ];\n\n policy.decision_strategy = DecisionStrategy.CONSENSUS;\n }\n\n const attribute_name_strict = policy.attribute_name_strict ?? true;\n if (!attribute_name_strict) {\n const resourceKeys = Object.keys(attributes);\n const keysToAdd : string[] = [];\n for (const resourceKey of resourceKeys) {\n let contains : boolean = false;\n\n for (const key of keys) {\n if (\n resourceKey !== key &&\n resourceKey.includes(key)\n ) {\n contains = true;\n break;\n }\n }\n\n if (contains) {\n keysToAdd.push(resourceKey);\n }\n }\n\n if (keysToAdd.length > 0) {\n keys.push(...keysToAdd);\n }\n }\n\n let count = 0;\n let evaluated = false;\n\n for (const key of keys) {\n if (!hasOwnProperty(attributes, key)) {\n continue;\n }\n\n evaluated = true;\n\n let outcome : boolean = false;\n\n const attributeValue = attributes[key];\n\n if (\n attributeValue === null &&\n policy.attribute_null_match_all\n ) {\n outcome = true;\n } else if (\n attributeValue === identity.realmId ||\n attributeValue === identity.realmName\n ) {\n outcome = true;\n }\n\n if (outcome) {\n if (policy.decision_strategy === DecisionStrategy.AFFIRMATIVE) {\n return { success: maybeInvertPolicyOutcome(true, policy.invert) };\n }\n\n count++;\n } else {\n if (policy.decision_strategy === DecisionStrategy.UNANIMOUS) {\n return { success: maybeInvertPolicyOutcome(false, policy.invert) };\n }\n\n count--;\n }\n }\n\n if (!evaluated) {\n return { success: maybeInvertPolicyOutcome(true, policy.invert) };\n }\n\n return { success: maybeInvertPolicyOutcome(count > 0, policy.invert) };\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum TimePolicyInterval {\n DAILY = 'daily',\n WEEKLY = 'weekly',\n MONTHLY = 'monthly',\n YEARLY = 'yearly',\n}\n","/*\n * Copyright (c) 2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { TimePolicyInterval } from './constants';\n\nexport function isIntervalForDayOfWeek(\n interval: string,\n) {\n return interval === TimePolicyInterval.WEEKLY ||\n interval === TimePolicyInterval.MONTHLY ||\n interval === TimePolicyInterval.YEARLY;\n}\n\nexport function isIntervalForDayOfMonth(\n interval: string,\n) {\n return interval === TimePolicyInterval.MONTHLY ||\n interval === TimePolicyInterval.YEARLY;\n}\n\nexport function isIntervalForDayOfYear(\n interval: string,\n) {\n return interval === TimePolicyInterval.YEARLY;\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { createValidator } from '@validup/adapter-zod';\nimport { Container } from 'validup';\nimport { z } from 'zod';\nimport type { TimePolicy } from './types';\nimport { TimePolicyInterval } from './constants';\n\nexport class TimePolicyValidator extends Container<TimePolicy> {\n override initialize() {\n super.initialize();\n\n this.mount('day_of_week', createValidator(\n z.number()\n .min(0).max(6)\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ));\n this.mount('day_of_month', createValidator(\n z.number()\n .min(1)\n .max(31)\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ));\n this.mount('day_of_year', createValidator(\n z.number()\n .min(1)\n .max(365)\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ));\n\n this.mount('start', createValidator(\n z.date()\n .or(z.iso.datetime())\n .or(z.iso.time())\n .or(z.number())\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ));\n this.mount('end', createValidator(\n z.date()\n .or(z.iso.datetime())\n .or(z.iso.time())\n .or(z.number())\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ));\n\n this.mount(\n 'interval',\n createValidator(\n z.enum(TimePolicyInterval)\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n\n this.mount(\n 'invert',\n createValidator(\n z.boolean()\n .or(z.undefined())\n .or(z.null())\n .optional(),\n ),\n );\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { IPolicyEvaluator, PolicyEvaluationContext, PolicyEvaluationResult } from '../../evaluation';\nimport { maybeInvertPolicyOutcome } from '../../helpers';\nimport { BuiltInPolicyType } from '../constants';\nimport { isIntervalForDayOfMonth, isIntervalForDayOfWeek, isIntervalForDayOfYear } from './helpers';\nimport { TimePolicyValidator } from './validator';\n\nconst timeRegex = /^(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d)?$/;\n\nfunction normalizeDate(input: Date, dateRef?: Date) {\n const date = dateRef ? new Date(dateRef) : new Date();\n date.setHours(input.getHours(), input.getMinutes());\n\n return date;\n}\n\nfunction toDate(\n input: Date | string | number,\n dateRef?: Date,\n) : Date {\n if (typeof input === 'string') {\n if (timeRegex.test(input)) {\n const parts = input.split(':');\n\n const startHours = Number(parts[0]);\n const startMinutes = Number(parts[1]);\n const startSeconds = parts[2] !== undefined ? Number(parts[2]) : 0;\n\n if (\n Number.isFinite(startHours) &&\n Number.isFinite(startMinutes) &&\n Number.isFinite(startSeconds)\n ) {\n const date = dateRef ? new Date(dateRef) : new Date();\n date.setHours(startHours, startMinutes, startSeconds, 0);\n\n return date;\n }\n }\n\n return new Date(input);\n }\n\n if (typeof input === 'number') {\n return new Date(input);\n }\n\n return input;\n}\n\nexport class TimePolicyEvaluator implements IPolicyEvaluator {\n protected validator : TimePolicyValidator;\n\n constructor() {\n this.validator = new TimePolicyValidator();\n }\n\n async evaluate(value: Record<string, any>, ctx: PolicyEvaluationContext): Promise<PolicyEvaluationResult> {\n // todo: catch errors + transform to issue(s)\n const policy = await this.validator.run(value);\n\n let now : Date;\n\n if (ctx.data.has(BuiltInPolicyType.TIME)) {\n if (ctx.data.isValidated(BuiltInPolicyType.TIME)) {\n now = ctx.data.get<Date>(BuiltInPolicyType.TIME);\n } else {\n // todo: run validator on attributes (isObject ...)\n now = toDate(ctx.data.get(BuiltInPolicyType.TIME));\n\n ctx.data.set(BuiltInPolicyType.TIME, now);\n ctx.data.setValidated(BuiltInPolicyType.TIME);\n }\n } else {\n now = new Date();\n }\n\n if (policy.start) {\n const start = normalizeDate(toDate(policy.start, now), now);\n if (now < start) {\n return { success: maybeInvertPolicyOutcome(false, policy.invert) };\n }\n }\n\n if (policy.end) {\n const end = normalizeDate(toDate(policy.end, now), now);\n if (now > end) {\n return { success: maybeInvertPolicyOutcome(false, policy.invert) };\n }\n }\n\n if (policy.interval) {\n if (\n isIntervalForDayOfWeek(policy.interval) &&\n policy.day_of_week\n ) {\n if (now.getDay() !== policy.day_of_week) {\n return { success: maybeInvertPolicyOutcome(false, policy.invert) };\n }\n }\n\n if (\n isIntervalForDayOfMonth(policy.interval) &&\n policy.day_of_month\n ) {\n if (now.getDate() !== policy.day_of_month) {\n return { success: maybeInvertPolicyOutcome(false, policy.invert) };\n }\n }\n\n if (\n isIntervalForDayOfYear(policy.interval) &&\n policy.day_of_year\n ) {\n const start = new Date(now.getFullYear(), 0, 0);\n const diff = (now.getTime() - start.getTime()) +\n ((start.getTimezoneOffset() - now.getTimezoneOffset()) * 60 * 1000);\n\n const oneDay = 1000 * 60 * 60 * 24;\n const dayOfYear = Math.floor(diff / oneDay);\n\n if (dayOfYear !== policy.day_of_year) {\n return { success: maybeInvertPolicyOutcome(false, policy.invert) };\n }\n }\n }\n\n return { success: maybeInvertPolicyOutcome(true, policy.invert) };\n }\n}\n","/*\n * Copyright (c) 2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { PolicyWithType } from '../types';\nimport type { BuiltInPolicyTypeMap } from './types';\n\nexport function definePolicyWithType<\n K extends keyof BuiltInPolicyTypeMap,\n D extends BuiltInPolicyTypeMap<any>[K],\n>(\n type: K,\n data: D,\n) : PolicyWithType<D, K> {\n return {\n ...data,\n type,\n };\n}\n","/*\n * Copyright (c) 2026-2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport {\n AttributeNamesPolicyEvaluator,\n AttributesPolicyEvaluator,\n BuiltInPolicyType,\n CompositePolicyEvaluator,\n DatePolicyEvaluator,\n IdentityPolicyEvaluator,\n PermissionBindingPolicyEvaluator,\n RealmMatchPolicyEvaluator,\n TimePolicyEvaluator,\n} from './built-in';\n\nexport const PolicyDefaultEvaluators = {\n [BuiltInPolicyType.COMPOSITE]: new CompositePolicyEvaluator(),\n [BuiltInPolicyType.ATTRIBUTES]: new AttributesPolicyEvaluator(),\n [BuiltInPolicyType.ATTRIBUTE_NAMES]: new AttributeNamesPolicyEvaluator(),\n [BuiltInPolicyType.DATE]: new DatePolicyEvaluator(),\n [BuiltInPolicyType.IDENTITY]: new IdentityPolicyEvaluator(),\n [BuiltInPolicyType.PERMISSION_BINDING]: new PermissionBindingPolicyEvaluator(),\n [BuiltInPolicyType.REALM_MATCH]: new RealmMatchPolicyEvaluator(),\n [BuiltInPolicyType.TIME]: new TimePolicyEvaluator(),\n} as const;\n","/*\n * Copyright (c) 2021-2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { ErrorCode } from '@authup/errors';\nimport type { Issue } from 'validup';\nimport { defineIssueItem } from 'validup';\nimport { DecisionStrategy } from '../../constants.ts';\nimport type { CompositePolicy, IPolicyEngine } from '../../policy';\nimport {\n BuiltInPolicyType,\n PolicyData,\n PolicyDefaultEvaluators,\n PolicyEngine,\n definePolicyEvaluationContext,\n definePolicyIssueGroup,\n} from '../../policy';\nimport { PermissionError } from '../error';\nimport type { IPermissionProvider } from '../provider';\n\nimport type { PermissionPolicyBinding } from '../types.ts';\nimport type { IPermissionEvaluator, PermissionEvaluationContext, PermissionEvaluatorOptions } from './types.ts';\n\nexport class PermissionEvaluator implements IPermissionEvaluator {\n protected provider : IPermissionProvider;\n\n protected policyEngine : IPolicyEngine;\n\n protected clientId?: string | null;\n\n protected realmId?: string | null;\n\n // ----------------------------------------------\n\n constructor(options: PermissionEvaluatorOptions) {\n this.provider = options.provider;\n\n this.clientId = options.clientId || null;\n this.realmId = options.realmId || null;\n\n if (options.policyEngine) {\n this.policyEngine = options.policyEngine;\n } else {\n this.policyEngine = new PolicyEngine(PolicyDefaultEvaluators);\n }\n }\n\n // ----------------------------------------------\n\n protected async findOne(\n input: string,\n overrides: {\n realmId?: string | null,\n clientId?: string | null\n } = {},\n ) : Promise<PermissionPolicyBinding | null> {\n return this.provider.findOne({\n name: input,\n clientId: overrides.clientId ?? this.clientId,\n realmId: overrides.realmId ?? this.realmId,\n });\n }\n\n // ----------------------------------------------\n\n async evaluate(ctx: PermissionEvaluationContext) : Promise<void> {\n if (!Array.isArray(ctx.name)) {\n await this.evaluate({\n ...ctx,\n name: [ctx.name],\n });\n return;\n }\n\n const { options = {} } = ctx;\n\n const decisionStrategy = options.decisionStrategy ??\n DecisionStrategy.UNANIMOUS;\n\n const issues : Issue[] = [];\n\n let count = 0;\n\n const dataBase = ctx.input || new PolicyData();\n\n for (const name of ctx.name) {\n const binding = await this.findOne(name, {\n realmId: ctx.realmId,\n clientId: ctx.clientId,\n });\n if (!binding) {\n issues.push(defineIssueItem({\n code: ErrorCode.PERMISSION_NOT_FOUND,\n message: `The ${name} permission could not be resolved`,\n path: [name],\n }));\n\n if (decisionStrategy === DecisionStrategy.UNANIMOUS) {\n const error = PermissionError.evaluationFailed(ctx.name);\n error.addIssues(issues);\n throw error;\n }\n\n continue;\n }\n\n const policies = binding.policies ?? [];\n if (policies.length === 0) {\n if (decisionStrategy === DecisionStrategy.AFFIRMATIVE) {\n return;\n }\n\n count++;\n\n continue;\n }\n\n const data = dataBase.clone();\n data.set(BuiltInPolicyType.PERMISSION_BINDING, binding);\n\n const policyDecisionStrategy = binding.permission.decision_strategy ??\n DecisionStrategy.UNANIMOUS;\n\n const compositePolicy : CompositePolicy = {\n type: BuiltInPolicyType.COMPOSITE,\n decision_strategy: policyDecisionStrategy,\n children: policies,\n };\n\n const evaluationResult = await this.policyEngine.evaluate(\n compositePolicy,\n definePolicyEvaluationContext({\n include: options.policiesIncluded,\n exclude: options.policiesExcluded,\n data,\n }),\n );\n\n if (evaluationResult.success) {\n if (decisionStrategy === DecisionStrategy.AFFIRMATIVE) {\n return;\n }\n\n count++;\n } else {\n issues.push(definePolicyIssueGroup({\n code: ErrorCode.PERMISSION_EVALUATION_FAILED,\n issues: evaluationResult.issues || [],\n message: `The ${binding.permission.name} permissions policy evaluation failed`,\n path: [binding.permission.name],\n }));\n\n if (decisionStrategy === DecisionStrategy.UNANIMOUS) {\n const error = PermissionError.evaluationFailed(binding.permission.name);\n error.addIssues(issues);\n throw error;\n }\n\n count--;\n }\n }\n\n if (count > 0) {\n return;\n }\n\n if (issues.length === 0) {\n throw PermissionError.deniedAll(ctx.name);\n } else {\n const error = PermissionError.evaluationFailed(ctx.name);\n error.addIssues(issues);\n throw error;\n }\n }\n\n async evaluateOneOf(ctx: PermissionEvaluationContext) : Promise<void> {\n return this.evaluate({\n ...ctx,\n options: {\n ...(ctx.options || {}),\n decisionStrategy: DecisionStrategy.AFFIRMATIVE,\n },\n });\n }\n\n // ----------------------------------------------\n\n async preEvaluate(ctx: PermissionEvaluationContext) : Promise<void> {\n return this.evaluate({\n ...ctx,\n options: {\n ...(ctx.options || {}),\n policiesExcluded: [\n BuiltInPolicyType.ATTRIBUTES,\n BuiltInPolicyType.ATTRIBUTE_NAMES,\n BuiltInPolicyType.REALM_MATCH,\n ],\n },\n });\n }\n\n async preEvaluateOneOf(ctx: PermissionEvaluationContext) : Promise<void> {\n return this.preEvaluate({\n ...ctx,\n options: {\n ...(ctx.options || {}),\n decisionStrategy: DecisionStrategy.AFFIRMATIVE,\n },\n });\n }\n}\n"],"mappings":";;;;;;;AAWA,IAAa,kBAAb,MAAa,wBAAwB,YAAY;CAC7C,YAAY,UAA8B,EAAE,EAAE;AAC1C,QAAM;GACF,GAAG;GACH,SAAS,QAAQ,WAAW;GAC5B,YAAY,QAAQ,cAAc;GACrC,CAAC;;CAGN,SAAS,MAAmB;AACxB,OAAK,OAAO,KAAK,KAAK;;CAG1B,UAAU,MAAqB;AAC3B,OAAK,OAAO,KAAK,GAAG,KAAK;;CAG7B,OAAO,SAAS,MAAc;AAC1B,SAAO,IAAI,gBAAgB;GACvB,SAAS,kBAAkB,KAAK;GAChC,MAAM,UAAU;GACnB,CAAC;;CAGN,OAAO,OAAO,MAAc;AACxB,SAAO,IAAI,gBAAgB;GACvB,SAAS,kBAAkB,KAAK;GAChC,MAAM,UAAU;GACnB,CAAC;;CAGN,OAAO,UAAU,OAAiB;AAC9B,SAAO,IAAI,gBAAgB;GACvB,SAAS,2BAA2B,MAAM,KAAK,KAAK,CAAC;GACrD,MAAM,UAAU;GACnB,CAAC;;CAGN,OAAO,iBAAiB,MAAyB;AAC7C,MAAI,MAAM,QAAQ,KAAK,CACnB,QAAO,IAAI,gBAAgB;GACvB,SAAS,iCAAiC,KAAK,KAAK,KAAK,CAAC;GAC1D,MAAM,UAAU;GACnB,CAAC;AAGN,SAAO,IAAI,gBAAgB;GACvB,SAAS,gCAAgC,KAAK;GAC9C,MAAM,UAAU;GACnB,CAAC;;;;;ACnDV,SAAgB,+BAA+B,GAA4B,GAAqC;AAC5G,KAAI,EAAE,WAAW,SAAS,EAAE,WAAW,KACnC,QAAO;AA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5
|
"description": "A library for evaluating permissions and policies.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"exports": {
|
|
@@ -60,14 +60,14 @@
|
|
|
60
60
|
"zod": "^4.3.6"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@authup/errors": "^1.0.0-beta.
|
|
64
|
-
"@authup/kit": "^1.0.0-beta.
|
|
63
|
+
"@authup/errors": "^1.0.0-beta.37",
|
|
64
|
+
"@authup/kit": "^1.0.0-beta.37",
|
|
65
65
|
"unplugin-swc": "^1.5.9",
|
|
66
66
|
"vitest": "^4.0.14"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@authup/errors": "^1.0.0-beta.
|
|
70
|
-
"@authup/kit": "^1.0.0-beta.
|
|
69
|
+
"@authup/errors": "^1.0.0-beta.37",
|
|
70
|
+
"@authup/kit": "^1.0.0-beta.37"
|
|
71
71
|
},
|
|
72
72
|
"publishConfig": {
|
|
73
73
|
"access": "public"
|