@twin.org/rights-management-plugins 0.0.3-next.23 → 0.0.3-next.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/es/policyArbiters/defaultPolicyArbiter.js +25 -25
  2. package/dist/es/policyArbiters/defaultPolicyArbiter.js.map +1 -1
  3. package/dist/es/policyArbiters/passThroughPolicyArbiter.js.map +1 -1
  4. package/dist/es/policyEnforcementProcessor/defaultPolicyEnforcementProcessor.js.map +1 -1
  5. package/dist/es/policyEnforcementProcessor/passThroughPolicyEnforcementProcessor.js.map +1 -1
  6. package/dist/es/policyExecutionActions/loggingPolicyExecutionAction.js.map +1 -1
  7. package/dist/es/policyInformationSources/identityPolicyInformationSource.js.map +1 -1
  8. package/dist/es/policyInformationSources/staticPolicyInformationSource.js.map +1 -1
  9. package/dist/es/policyNegotiators/passThroughPolicyNegotiator.js +5 -4
  10. package/dist/es/policyNegotiators/passThroughPolicyNegotiator.js.map +1 -1
  11. package/dist/es/policyObligationEnforcers/passThroughPolicyObligationEnforcer.js.map +1 -1
  12. package/dist/types/policyArbiters/defaultPolicyArbiter.d.ts +2 -2
  13. package/dist/types/policyArbiters/passThroughPolicyArbiter.d.ts +2 -2
  14. package/dist/types/policyEnforcementProcessor/defaultPolicyEnforcementProcessor.d.ts +2 -2
  15. package/dist/types/policyEnforcementProcessor/passThroughPolicyEnforcementProcessor.d.ts +2 -2
  16. package/dist/types/policyExecutionActions/loggingPolicyExecutionAction.d.ts +2 -2
  17. package/dist/types/policyInformationSources/identityPolicyInformationSource.d.ts +2 -2
  18. package/dist/types/policyInformationSources/staticPolicyInformationSource.d.ts +2 -2
  19. package/dist/types/policyObligationEnforcers/passThroughPolicyObligationEnforcer.d.ts +2 -2
  20. package/docs/changelog.md +44 -0
  21. package/docs/reference/classes/IdentityPolicyInformationSource.md +2 -2
  22. package/docs/reference/classes/LoggingPolicyExecutionAction.md +2 -2
  23. package/docs/reference/classes/PassThroughPolicyNegotiator.md +2 -2
  24. package/docs/reference/classes/StaticPolicyInformationSource.md +2 -2
  25. package/docs/reference/interfaces/IDefaultPolicyArbiterConfig.md +7 -1
  26. package/docs/reference/interfaces/IDefaultPolicyArbiterConstructorOptions.md +15 -3
  27. package/docs/reference/interfaces/IDefaultPolicyEnforcementProcessorConstructorOptions.md +7 -1
  28. package/docs/reference/interfaces/IIdentityPolicyInformationSourceConstructorOptions.md +14 -2
  29. package/docs/reference/interfaces/ILoggingPolicyExecutionActionConfig.md +22 -4
  30. package/docs/reference/interfaces/ILoggingPolicyExecutionActionConstructorOptions.md +8 -2
  31. package/docs/reference/interfaces/IPassThroughPolicyArbiterConstructorOptions.md +7 -1
  32. package/docs/reference/interfaces/IPassThroughPolicyEnforcementProcessorConstructorOptions.md +7 -1
  33. package/docs/reference/interfaces/IPassThroughPolicyNegotiatorConstructorOptions.md +7 -1
  34. package/docs/reference/interfaces/IPassThroughPolicyObligationEnforcerConstructorOptions.md +7 -1
  35. package/docs/reference/interfaces/IPassThroughPolicyRequesterConstructorOptions.md +7 -1
  36. package/docs/reference/interfaces/IStaticPolicyInformationSource.md +5 -5
  37. package/docs/reference/interfaces/IStaticPolicyInformationSourceConfig.md +1 -1
  38. package/docs/reference/interfaces/IStaticPolicyInformationSourceConstructorOptions.md +8 -2
  39. package/package.json +2 -2
@@ -3,7 +3,7 @@
3
3
  import { ArrayHelper, Coerce, ComponentFactory, GeneralError, Guards, Is, ObjectHelper } from "@twin.org/core";
4
4
  import { JsonPathHelper } from "@twin.org/data-json-path";
5
5
  import { OdrlPolicyHelper, PolicyDecision, PolicyObligationEnforcerFactory } from "@twin.org/rights-management-models";
6
- import { ConflictStrategyType, LogicalConstraintType, OperatorType } from "@twin.org/standards-w3c-odrl";
6
+ import { OdrlConflictStrategyType, OdrlLogicalConstraintType, OdrlOperatorType } from "@twin.org/standards-w3c-odrl";
7
7
  /**
8
8
  * Default Policy Arbiter.
9
9
  */
@@ -111,15 +111,15 @@ export class DefaultPolicyArbiter {
111
111
  break;
112
112
  }
113
113
  }
114
- const conflictStrategy = mergedPolicy.conflict ?? ConflictStrategyType.Invalid;
114
+ const conflictStrategy = mergedPolicy.conflict ?? OdrlConflictStrategyType.Invalid;
115
115
  let decision;
116
116
  if (permissionApplies && prohibitionApplies) {
117
117
  switch (conflictStrategy) {
118
- case ConflictStrategyType.Perm:
118
+ case OdrlConflictStrategyType.Perm:
119
119
  decision = PolicyDecision.Granted;
120
120
  break;
121
- case ConflictStrategyType.Prohibit:
122
- case ConflictStrategyType.Invalid:
121
+ case OdrlConflictStrategyType.Prohibit:
122
+ case OdrlConflictStrategyType.Invalid:
123
123
  default:
124
124
  decision = PolicyDecision.Denied;
125
125
  break;
@@ -197,7 +197,7 @@ export class DefaultPolicyArbiter {
197
197
  mergedConflict = Array.from(conflictStrategies)[0];
198
198
  }
199
199
  else if (conflictStrategies.size > 1) {
200
- mergedConflict = ConflictStrategyType.Invalid;
200
+ mergedConflict = OdrlConflictStrategyType.Invalid;
201
201
  }
202
202
  // Return a new policy with merged rules
203
203
  return {
@@ -528,7 +528,7 @@ export class DefaultPolicyArbiter {
528
528
  */
529
529
  getLogicalConstraintOperands(constraint) {
530
530
  const logicalConstraint = constraint;
531
- const operators = Object.values(LogicalConstraintType);
531
+ const operators = Object.values(OdrlLogicalConstraintType);
532
532
  for (const operator of operators) {
533
533
  const value = logicalConstraint[operator];
534
534
  if (!Is.undefined(value)) {
@@ -599,9 +599,9 @@ export class DefaultPolicyArbiter {
599
599
  return false;
600
600
  }
601
601
  switch (operator) {
602
- case LogicalConstraintType.And:
602
+ case OdrlLogicalConstraintType.And:
603
603
  return constraints.every(item => this.evaluateConstraint(item, ruleDataContext));
604
- case LogicalConstraintType.AndSequence: {
604
+ case OdrlLogicalConstraintType.AndSequence: {
605
605
  for (const item of constraints) {
606
606
  if (!this.evaluateConstraint(item, ruleDataContext)) {
607
607
  return false;
@@ -609,9 +609,9 @@ export class DefaultPolicyArbiter {
609
609
  }
610
610
  return true;
611
611
  }
612
- case LogicalConstraintType.Or:
612
+ case OdrlLogicalConstraintType.Or:
613
613
  return constraints.some(item => this.evaluateConstraint(item, ruleDataContext));
614
- case LogicalConstraintType.Xone: {
614
+ case OdrlLogicalConstraintType.Xone: {
615
615
  let satisfied = 0;
616
616
  for (const item of constraints) {
617
617
  if (this.evaluateConstraint(item, ruleDataContext)) {
@@ -697,19 +697,19 @@ export class DefaultPolicyArbiter {
697
697
  // Handle array/collection left values (e.g. JSONPath returning multiple matches).
698
698
  const leftValues = ArrayHelper.fromObjectOrArray(left ?? []);
699
699
  switch (operator) {
700
- case OperatorType.Eq:
700
+ case OdrlOperatorType.Eq:
701
701
  return leftValues.some(v => ObjectHelper.equal(v, right, false));
702
- case OperatorType.Neq:
702
+ case OdrlOperatorType.Neq:
703
703
  return leftValues.every(v => !ObjectHelper.equal(v, right, false));
704
- case OperatorType.Gt:
704
+ case OdrlOperatorType.Gt:
705
705
  return leftValues.some(v => this.compareOrdered(v, right, (a, b) => a > b));
706
- case OperatorType.Gteq:
706
+ case OdrlOperatorType.Gteq:
707
707
  return leftValues.some(v => this.compareOrdered(v, right, (a, b) => a >= b));
708
- case OperatorType.Lt:
708
+ case OdrlOperatorType.Lt:
709
709
  return leftValues.some(v => this.compareOrdered(v, right, (a, b) => a < b));
710
- case OperatorType.Lteq:
710
+ case OdrlOperatorType.Lteq:
711
711
  return leftValues.some(v => this.compareOrdered(v, right, (a, b) => a <= b));
712
- case OperatorType.IsAnyOf: {
712
+ case OdrlOperatorType.IsAnyOf: {
713
713
  return leftValues.some(v => {
714
714
  const stringValue = typeof v === "string" || typeof v === "number" || typeof v === "boolean"
715
715
  ? String(v)
@@ -717,19 +717,19 @@ export class DefaultPolicyArbiter {
717
717
  return (ArrayHelper.fromObjectOrArray(right) ?? []).includes(stringValue);
718
718
  });
719
719
  }
720
- case OperatorType.IsAllOf: {
720
+ case OdrlOperatorType.IsAllOf: {
721
721
  return ObjectHelper.equal(leftValues, ArrayHelper.fromObjectOrArray(right) ?? [], false);
722
722
  }
723
- case OperatorType.IsNoneOf: {
723
+ case OdrlOperatorType.IsNoneOf: {
724
724
  return leftValues.every(v => !(ArrayHelper.fromObjectOrArray(right) ?? []).includes(v));
725
725
  }
726
- case OperatorType.LocTimeEq:
726
+ case OdrlOperatorType.LocTimeEq:
727
727
  return leftValues.some(v => ObjectHelper.equal(v, right, false));
728
- case OperatorType.LocTimeGteq:
728
+ case OdrlOperatorType.LocTimeGteq:
729
729
  return leftValues.some(v => this.compareOrdered(v, right, (a, b) => a >= b));
730
- case OperatorType.IsA:
731
- case OperatorType.HasPart:
732
- case OperatorType.IsPartOf:
730
+ case OdrlOperatorType.IsA:
731
+ case OdrlOperatorType.HasPart:
732
+ case OdrlOperatorType.IsPartOf:
733
733
  // For now, treat these as simple equality/ordering semantics where meaningful.
734
734
  // Profiles can introduce richer semantics via additional arbiters.
735
735
  return leftValues.some(v => ObjectHelper.equal(v, right, false));
@@ -1 +1 @@
1
- {"version":3,"file":"defaultPolicyArbiter.js","sourceRoot":"","sources":["../../../src/policyArbiters/defaultPolicyArbiter.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,WAAW,EACX,MAAM,EACN,gBAAgB,EAChB,YAAY,EACZ,MAAM,EACN,EAAE,EACF,YAAY,EACZ,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG1D,OAAO,EACN,gBAAgB,EAChB,cAAc,EACd,+BAA+B,EAI/B,MAAM,oCAAoC,CAAC;AAK5C,OAAO,EACN,oBAAoB,EACpB,qBAAqB,EACrB,YAAY,EASZ,MAAM,8BAA8B,CAAC;AAGtC;;GAEG;AACH,MAAM,OAAO,oBAAoB;IAChC;;OAEG;IACI,MAAM,CAAU,UAAU,0BAA0C;IAE3E;;;OAGG;IACK,MAAM,CAAU,eAAe,GAAG,UAAU,CAAC;IAErD;;;OAGG;IACK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;QAC9B,CAAC;aAAM,IAAI,CAAC,UAAU,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACpE,4BAA4B;YAC5B,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,SAAS,CAAC;IAClB,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tArrayHelper,\n\tCoerce,\n\tComponentFactory,\n\tGeneralError,\n\tGuards,\n\tIs,\n\tObjectHelper\n} from \"@twin.org/core\";\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport { JsonPathHelper } from \"@twin.org/data-json-path\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tOdrlPolicyHelper,\n\tPolicyDecision,\n\tPolicyObligationEnforcerFactory,\n\ttype IPolicyAdministrationPointComponent,\n\ttype IPolicyArbiter,\n\ttype IPolicyDecision\n} from \"@twin.org/rights-management-models\";\nimport type {\n\tIDataspaceProtocolAgreement,\n\tIDataspaceProtocolPolicy\n} from \"@twin.org/standards-dataspace-protocol\";\nimport {\n\tConflictStrategyType,\n\tLogicalConstraintType,\n\tOperatorType,\n\ttype ActionType,\n\ttype IOdrlConstraint,\n\ttype IOdrlDuty,\n\ttype IOdrlLogicalConstraint,\n\ttype IOdrlLogicalConstraintOperand,\n\ttype IOdrlPermission,\n\ttype IOdrlProhibition,\n\ttype IOdrlRule\n} from \"@twin.org/standards-w3c-odrl\";\nimport type { IDefaultPolicyArbiterConstructorOptions } from \"../models/IDefaultPolicyArbiterConstructorOptions.js\";\n\n/**\n * Default Policy Arbiter.\n */\nexport class DefaultPolicyArbiter implements IPolicyArbiter {\n\t/**\n\t * The class name of the Default Policy Arbiter.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<DefaultPolicyArbiter>();\n\n\t/**\n\t * Type indicating the operand type is JSONPath.\n\t * @internal\n\t */\n\tprivate static readonly _JSON_PATH_TYPE = \"jsonpath\";\n\n\t/**\n\t * Prefix indicating the operand encodes a JSONPath.\n\t * @internal\n\t */\n\tprivate static readonly _JSON_PATH_OPERAND_PREFIX = `twin:${DefaultPolicyArbiter._JSON_PATH_TYPE}`;\n\n\t/**\n\t * Prefix indicating the permission target references an item in the information map.\n\t * @internal\n\t */\n\tprivate static readonly _INFORMATION_TARGET_PREFIX = \"twin:information:\";\n\n\t/**\n\t * Default maximum inheritance depth.\n\t * @internal\n\t */\n\tprivate static readonly _DEFAULT_MAX_INHERITANCE_DEPTH = 10;\n\n\t/**\n\t * The logging component.\n\t * @internal\n\t */\n\tprivate readonly _logging: ILoggingComponent;\n\n\t/**\n\t * The policy administration point component.\n\t * @internal\n\t */\n\tprivate readonly _policyAdministrationPoint: IPolicyAdministrationPointComponent;\n\n\t/**\n\t * The maximum depth to traverse when resolving inherited policies.\n\t * @internal\n\t */\n\tprivate readonly _maxInheritanceDepth: number;\n\n\t/**\n\t * Create a new instance of DefaultPolicyArbiter.\n\t * @param options The options for the default policy arbiter.\n\t */\n\tconstructor(options?: IDefaultPolicyArbiterConstructorOptions) {\n\t\tthis._logging = ComponentFactory.get<ILoggingComponent>(\n\t\t\toptions?.loggingComponentType ?? \"logging\"\n\t\t);\n\n\t\tthis._policyAdministrationPoint = ComponentFactory.get<IPolicyAdministrationPointComponent>(\n\t\t\toptions?.policyAdministrationPointComponentType ?? \"policy-administration-point\"\n\t\t);\n\n\t\tthis._maxInheritanceDepth =\n\t\t\tCoerce.integer(options?.config?.maxInheritanceDepth) ??\n\t\t\tDefaultPolicyArbiter._DEFAULT_MAX_INHERITANCE_DEPTH;\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn DefaultPolicyArbiter.CLASS_NAME;\n\t}\n\n\t/**\n\t * Makes decisions regarding policy access to data.\n\t * @param agreement The agreement to evaluate.\n\t * @param information Information provided by the requester to determine if a policy can be created.\n\t * @param data The data to make a decision on.\n\t * @param action Optional action to make a decision on, if not provided, the arbiter will evaluate all actions in the agreement.\n\t * @returns The decisions about access to the data.\n\t */\n\tpublic async decide<D = unknown>(\n\t\tagreement: IDataspaceProtocolAgreement,\n\t\tinformation?: { [id: string]: IJsonLdNodeObject },\n\t\tdata?: D,\n\t\taction?: ActionType | string\n\t): Promise<IPolicyDecision[]> {\n\t\tGuards.object<IDataspaceProtocolAgreement>(\n\t\t\tDefaultPolicyArbiter.CLASS_NAME,\n\t\t\tnameof(agreement),\n\t\t\tagreement\n\t\t);\n\n\t\tawait this._logging.log({\n\t\t\tlevel: \"info\",\n\t\t\tsource: DefaultPolicyArbiter.CLASS_NAME,\n\t\t\tts: Date.now(),\n\t\t\tmessage: \"decidingPolicy\",\n\t\t\tdata: {\n\t\t\t\tpolicyId: OdrlPolicyHelper.getUid(agreement) ?? \"\"\n\t\t\t}\n\t\t});\n\n\t\t// Resolve and merge inherited policies.\n\t\tconst mergedPolicy = await this.mergeInheritedPolicies(agreement);\n\n\t\t// Extract agreement parties once for use in rule evaluation\n\t\tconst agreementAssigner = OdrlPolicyHelper.getPartyIds(agreement.assigner);\n\t\tconst agreementAssignee = OdrlPolicyHelper.getPartyIds(agreement.assignee);\n\n\t\t// ODRL-style rule evaluation:\n\t\t// - Permission rules authorize if ANY applicable permission matches (OR across permissions).\n\t\t// - Default to denied when there are no permissions (closed-world for access control).\n\t\t// - Conflict strategy controls how applicable permissions/prohibitions are resolved.\n\t\tconst permissions = ArrayHelper.fromObjectOrArray(mergedPolicy.permission ?? []);\n\t\tlet permissionApplies = false;\n\t\tif (permissions.length > 0) {\n\t\t\tfor (const permission of permissions) {\n\t\t\t\tif (\n\t\t\t\t\tawait this.evaluatePermission(\n\t\t\t\t\t\tagreementAssigner,\n\t\t\t\t\t\tagreementAssignee,\n\t\t\t\t\t\tmergedPolicy,\n\t\t\t\t\t\tpermission,\n\t\t\t\t\t\tinformation,\n\t\t\t\t\t\tdata,\n\t\t\t\t\t\taction\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tpermissionApplies = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst prohibitions = ArrayHelper.fromObjectOrArray<IOdrlProhibition>(\n\t\t\tmergedPolicy.prohibition ?? []\n\t\t);\n\t\tlet prohibitionApplies = false;\n\t\tfor (const prohibition of prohibitions) {\n\t\t\tif (\n\t\t\t\tthis.evaluateProhibition(agreementAssigner, agreementAssignee, prohibition, data, action)\n\t\t\t) {\n\t\t\t\tprohibitionApplies = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tconst conflictStrategy = mergedPolicy.conflict ?? ConflictStrategyType.Invalid;\n\t\tlet decision: PolicyDecision;\n\t\tif (permissionApplies && prohibitionApplies) {\n\t\t\tswitch (conflictStrategy) {\n\t\t\t\tcase ConflictStrategyType.Perm:\n\t\t\t\t\tdecision = PolicyDecision.Granted;\n\t\t\t\t\tbreak;\n\t\t\t\tcase ConflictStrategyType.Prohibit:\n\t\t\t\tcase ConflictStrategyType.Invalid:\n\t\t\t\tdefault:\n\t\t\t\t\tdecision = PolicyDecision.Denied;\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t} else {\n\t\t\tdecision = permissionApplies ? PolicyDecision.Granted : PolicyDecision.Denied;\n\t\t}\n\n\t\treturn [{ target: \"$\", decision }];\n\t}\n\n\t/**\n\t * Evaluate whether a prohibition applies.\n\t * @param agreementAssigner The assigner ID from the agreement.\n\t * @param agreementAssignee The assignee ID from the agreement.\n\t * @param prohibition The prohibition to evaluate.\n\t * @param data The request data/context.\n\t * @param action Optional action to check against the prohibition's applicable actions.\n\t * @returns True if the prohibition applies.\n\t * @internal\n\t */\n\tprivate evaluateProhibition(\n\t\tagreementAssigner: string[] | undefined,\n\t\tagreementAssignee: string[] | undefined,\n\t\tprohibition: IOdrlProhibition,\n\t\tdata?: unknown,\n\t\taction?: ActionType | string\n\t): boolean {\n\t\tif (!this.isRuleApplicableToParties(prohibition, agreementAssigner, agreementAssignee)) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Check if the prohibition's action(s) match the requested action\n\t\tif (!this.isActionApplicable(prohibition.action, action)) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// ODRL semantics: a rule without constraints is unconditional.\n\t\tconst constraints = ArrayHelper.fromObjectOrArray(prohibition.constraint ?? []);\n\t\tif (constraints.length === 0) {\n\t\t\treturn true;\n\t\t}\n\n\t\treturn constraints.every(c => this.evaluateConstraint(c, data));\n\t}\n\n\t/**\n\t * Merge inherited policies into the current policy.\n\t * Inherited policies' permissions, prohibitions, and obligations are combined with the current policy's rules.\n\t * @param policy The policy to evaluate.\n\t * @returns A new policy with merged rules from all ancestors.\n\t * @internal\n\t */\n\tprivate async mergeInheritedPolicies(\n\t\tpolicy: IDataspaceProtocolPolicy\n\t): Promise<IDataspaceProtocolPolicy> {\n\t\tconst visitedPolicyIds: string[] = [];\n\t\tvisitedPolicyIds.push(OdrlPolicyHelper.getUid(policy) ?? \"\");\n\t\tconst inheritedPolicies = await this.resolveInheritedPolicies(policy, visitedPolicyIds, 0);\n\t\tconst conflictStrategies = new Set<string>();\n\t\tif (Is.stringValue(policy.conflict)) {\n\t\t\tconflictStrategies.add(policy.conflict);\n\t\t}\n\n\t\t// Start with copies of the current policy's rules\n\t\tconst mergedPermissions: IOdrlPermission[] = ArrayHelper.fromObjectOrArray(\n\t\t\tpolicy.permission ?? []\n\t\t).map(permission => this.applyPolicyPartiesToRule(policy, permission));\n\n\t\tconst mergedProhibitions: IOdrlProhibition[] = ArrayHelper.fromObjectOrArray(\n\t\t\tpolicy.prohibition ?? []\n\t\t).map(prohibition => this.applyPolicyPartiesToRule(policy, prohibition));\n\n\t\tconst mergedObligations: IOdrlDuty[] = ArrayHelper.fromObjectOrArray(\n\t\t\tpolicy.obligation ?? []\n\t\t).map(obligation => this.applyPolicyPartiesToRule(policy, obligation));\n\n\t\t// Merge rules from each inherited policy\n\t\tfor (const inheritedPolicy of inheritedPolicies) {\n\t\t\tif (Is.stringValue(inheritedPolicy.conflict)) {\n\t\t\t\tconflictStrategies.add(inheritedPolicy.conflict);\n\t\t\t}\n\t\t\tconst inheritedPermissions = ArrayHelper.fromObjectOrArray(inheritedPolicy.permission ?? []);\n\t\t\tif (inheritedPermissions.length > 0) {\n\t\t\t\tmergedPermissions.push(\n\t\t\t\t\t...inheritedPermissions.map(permission =>\n\t\t\t\t\t\tthis.applyPolicyPartiesToRule(inheritedPolicy, permission)\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst inheritedProhibitions = ArrayHelper.fromObjectOrArray(\n\t\t\t\tinheritedPolicy.prohibition ?? []\n\t\t\t);\n\t\t\tif (inheritedProhibitions.length > 0) {\n\t\t\t\tmergedProhibitions.push(\n\t\t\t\t\t...inheritedProhibitions.map(prohibition =>\n\t\t\t\t\t\tthis.applyPolicyPartiesToRule(inheritedPolicy, prohibition)\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst inheritedObligations = ArrayHelper.fromObjectOrArray(inheritedPolicy.obligation ?? []);\n\t\t\tif (inheritedObligations.length > 0) {\n\t\t\t\tmergedObligations.push(\n\t\t\t\t\t...inheritedObligations.map(obligation =>\n\t\t\t\t\t\tthis.applyPolicyPartiesToRule(inheritedPolicy, obligation)\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tlet mergedConflict: IDataspaceProtocolPolicy[\"conflict\"] | undefined;\n\t\tif (conflictStrategies.size === 1) {\n\t\t\tmergedConflict = Array.from(conflictStrategies)[0] as IDataspaceProtocolPolicy[\"conflict\"];\n\t\t} else if (conflictStrategies.size > 1) {\n\t\t\tmergedConflict = ConflictStrategyType.Invalid;\n\t\t}\n\n\t\t// Return a new policy with merged rules\n\t\treturn {\n\t\t\t...policy,\n\t\t\tconflict: mergedConflict,\n\t\t\tpermission: mergedPermissions.length > 0 ? mergedPermissions : undefined,\n\t\t\tprohibition: mergedProhibitions.length > 0 ? mergedProhibitions : undefined,\n\t\t\tobligation: mergedObligations.length > 0 ? mergedObligations : undefined\n\t\t};\n\t}\n\n\t/**\n\t * Resolve inherited policies by their UIDs from the Policy Administration Point.\n\t * Policies can inherit from other policies via the inheritFrom property.\n\t * Detects circular inheritance and throws an exception if detected.\n\t * @param policy The policy that may have inheritFrom references.\n\t * @param visitedPolicyIds Array of policy UIDs already visited in this inheritance chain.\n\t * @returns Array of inherited policies fetched from the PAP.\n\t * @throws GeneralError if a parent policy cannot be found or if circular inheritance is detected.\n\t * @internal\n\t */\n\tprivate async resolveInheritedPolicies(\n\t\tpolicy: IDataspaceProtocolPolicy,\n\t\tvisitedPolicyIds: string[],\n\t\tcurrentDepth: number\n\t): Promise<IDataspaceProtocolPolicy[]> {\n\t\tconst inheritedPolicies: IDataspaceProtocolPolicy[] = [];\n\n\t\t// If policy has no inheritFrom, return empty array\n\t\tif (Is.empty(policy.inheritFrom)) {\n\t\t\treturn inheritedPolicies;\n\t\t}\n\n\t\tconst inheritFromIds = ArrayHelper.fromObjectOrArray<string>(policy.inheritFrom) ?? [];\n\n\t\tfor (const inheritFromId of inheritFromIds) {\n\t\t\tconst nextDepth = currentDepth + 1;\n\t\t\tif (nextDepth > this._maxInheritanceDepth) {\n\t\t\t\tthrow new GeneralError(DefaultPolicyArbiter.CLASS_NAME, \"maxInheritanceDepthExceeded\", {\n\t\t\t\t\tpolicyId: OdrlPolicyHelper.getUid(policy) ?? \"\",\n\t\t\t\t\tinheritFromId,\n\t\t\t\t\tmaxInheritanceDepth: this._maxInheritanceDepth\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Check for circular inheritance\n\t\t\tif (visitedPolicyIds.includes(inheritFromId)) {\n\t\t\t\tthrow new GeneralError(DefaultPolicyArbiter.CLASS_NAME, \"circularInheritanceDetected\", {\n\t\t\t\t\tpolicyId: OdrlPolicyHelper.getUid(policy) ?? \"\",\n\t\t\t\t\tinheritFromId\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Fetch the inherited policy from the PAP\n\t\t\tconst inheritedPolicy = await this._policyAdministrationPoint.get(inheritFromId);\n\t\t\tif (Is.empty(inheritedPolicy)) {\n\t\t\t\tthrow new GeneralError(DefaultPolicyArbiter.CLASS_NAME, \"inheritedPolicyNotFound\", {\n\t\t\t\t\tinheritFromId\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Mark this policy as visited\n\t\t\tvisitedPolicyIds.push(inheritFromId);\n\n\t\t\tinheritedPolicies.push(inheritedPolicy);\n\n\t\t\t// Recursively resolve inherited policies of the parent\n\t\t\tconst grandparentPolicies = await this.resolveInheritedPolicies(\n\t\t\t\tinheritedPolicy,\n\t\t\t\tvisitedPolicyIds,\n\t\t\t\tnextDepth\n\t\t\t);\n\t\t\tinheritedPolicies.push(...grandparentPolicies);\n\t\t}\n\n\t\treturn inheritedPolicies;\n\t}\n\n\t/**\n\t * Apply policy-level assigner/assignee values to rules that don't override them.\n\t * @param policy The policy providing defaults.\n\t * @param rule The rule to apply defaults to.\n\t * @returns The rule with policy-level assigner/assignee applied.\n\t * @internal\n\t */\n\tprivate applyPolicyPartiesToRule<T extends IOdrlRule>(\n\t\tpolicy: IDataspaceProtocolPolicy,\n\t\trule: T\n\t): T {\n\t\tconst assigner = Is.empty(rule.assigner) ? policy.assigner : rule.assigner;\n\t\tconst assignee = Is.empty(rule.assignee) ? policy.assignee : rule.assignee;\n\n\t\tconst assignerIds = OdrlPolicyHelper.getPartyIds(assigner);\n\t\tconst ruleAssignerIds = OdrlPolicyHelper.getPartyIds(rule.assigner);\n\t\tconst assigneeIds = OdrlPolicyHelper.getPartyIds(assignee);\n\t\tconst ruleAssigneeIds = OdrlPolicyHelper.getPartyIds(rule.assignee);\n\n\t\tlet assignerEqual = false;\n\t\tif (Is.empty(assignerIds) && Is.empty(ruleAssignerIds)) {\n\t\t\tassignerEqual = true;\n\t\t} else if (!Is.empty(assignerIds) && !Is.empty(ruleAssignerIds)) {\n\t\t\tassignerEqual =\n\t\t\t\tassignerIds.length === ruleAssignerIds.length &&\n\t\t\t\tassignerIds.every(id => ruleAssignerIds.includes(id));\n\t\t}\n\n\t\tlet assigneeEqual = false;\n\t\tif (Is.empty(assigneeIds) && Is.empty(ruleAssigneeIds)) {\n\t\t\tassigneeEqual = true;\n\t\t} else if (!Is.empty(assigneeIds) && !Is.empty(ruleAssigneeIds)) {\n\t\t\tassigneeEqual =\n\t\t\t\tassigneeIds.length === ruleAssigneeIds.length &&\n\t\t\t\tassigneeIds.every(id => ruleAssigneeIds.includes(id));\n\t\t}\n\n\t\tif (assignerEqual && assigneeEqual) {\n\t\t\treturn rule;\n\t\t}\n\n\t\treturn {\n\t\t\t...rule,\n\t\t\tassigner,\n\t\t\tassignee\n\t\t};\n\t}\n\n\t/**\n\t * Determine whether a rule applies to the agreement parties based on assigner/assignee.\n\t * @param rule The rule to evaluate.\n\t * @param agreementAssigner The assigner ID from the agreement.\n\t * @param agreementAssignee The assignee ID from the agreement.\n\t * @returns True if the rule is applicable to the agreement parties.\n\t * @internal\n\t */\n\tprivate isRuleApplicableToParties(\n\t\trule: IOdrlRule,\n\t\tagreementAssigner: string[] | undefined,\n\t\tagreementAssignee: string[] | undefined\n\t): boolean {\n\t\tconst ruleAssigners = OdrlPolicyHelper.getPartyIds(rule.assigner);\n\t\tconst ruleAssignees = OdrlPolicyHelper.getPartyIds(rule.assignee);\n\n\t\tif (!this.isPartyApplicable(ruleAssigners, agreementAssigner)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (!this.isPartyApplicable(ruleAssignees, agreementAssignee)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Determine whether a rule party constraint applies to the agreement parties.\n\t * Rule party is treated as a constraint: if specified, it must match at least one agreement party.\n\t * @param rulePartyIds The party ids specified on the rule (if any).\n\t * @param agreementPartyIds The party ids extracted from the agreement.\n\t * @returns True if the rule party constraint is satisfied.\n\t * @internal\n\t */\n\tprivate isPartyApplicable(\n\t\trulePartyIds: string[] | undefined,\n\t\tagreementPartyIds: string[] | undefined\n\t): boolean {\n\t\t// No party specified on rule means it applies to any agreement party.\n\t\tif (Is.empty(rulePartyIds)) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Rule specifies party/parties, but agreement doesn't provide any.\n\t\tif (Is.empty(agreementPartyIds)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tfor (const rulePartyId of rulePartyIds) {\n\t\t\tif (agreementPartyIds.includes(rulePartyId)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/**\n\t * Determine whether a rule's action(s) match the requested action.\n\t * If no action is specified in the rule, it applies to all actions (action-agnostic).\n\t * If an action is specified in the rule and a specific action is requested, they must match.\n\t * If an action is specified in the rule but no specific action is requested, the rule applies (general evaluation).\n\t * @param ruleActions The actions defined in the rule (can be string, object, or array).\n\t * @param requestedAction The action being requested (optional).\n\t * @returns True if the rule's action(s) apply.\n\t * @internal\n\t */\n\tprivate isActionApplicable(\n\t\truleActions: IOdrlRule[\"action\"],\n\t\trequestedAction?: ActionType | string\n\t): boolean {\n\t\t// If the rule has no action specified, it applies to all actions\n\t\tif (Is.empty(ruleActions)) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// If the rule has actions but no specific action is requested,\n\t\t// the rule applies (we're evaluating permissions in general)\n\t\tif (Is.empty(requestedAction)) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Both rule actions and requested action are specified - check for match\n\t\tconst ruleActionArray = ArrayHelper.fromObjectOrArray(ruleActions) ?? [];\n\n\t\t// Check if the requested action matches any of the rule's actions\n\t\tfor (const ruleAction of ruleActionArray) {\n\t\t\tconst ruleActionId = Is.string(ruleAction) ? ruleAction : OdrlPolicyHelper.getUid(ruleAction);\n\t\t\tconst requestedActionId = Is.string(requestedAction)\n\t\t\t\t? requestedAction\n\t\t\t\t: OdrlPolicyHelper.getUid(requestedAction);\n\n\t\t\tif (Is.stringValue(ruleActionId) && Is.stringValue(requestedActionId)) {\n\t\t\t\tif (ruleActionId === requestedActionId) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/**\n\t * Apply a permission and create decisions based on that information.\n\t * @param agreementAssigner The assigner ID from the agreement.\n\t * @param agreementAssignee The assignee ID from the agreement.\n\t * @param policy The policy containing the permission.\n\t * @param permission The permission to apply.\n\t * @param information Additional facts provided by the PIP.\n\t * @param data The request data/context.\n\t * @returns True if the permission applies.\n\t * @internal\n\t */\n\tprivate async evaluatePermission(\n\t\tagreementAssigner: string[] | undefined,\n\t\tagreementAssignee: string[] | undefined,\n\t\tpolicy: IDataspaceProtocolPolicy,\n\t\tpermission: IOdrlPermission,\n\t\tinformation?: { [id: string]: IJsonLdNodeObject },\n\t\tdata?: unknown,\n\t\taction?: ActionType | string\n\t): Promise<boolean> {\n\t\tif (!this.isRuleApplicableToParties(permission, agreementAssigner, agreementAssignee)) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Check if the permission's action(s) match the requested action\n\t\tif (!this.isActionApplicable(permission.action, action)) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// ODRL semantics: a Permission without constraints is unconditional.\n\t\tconst constraints = ArrayHelper.fromObjectOrArray(permission.constraint ?? []);\n\t\tif (constraints.length === 0) {\n\t\t\treturn this.enforcePermissionDuties(policy, permission, information, data);\n\t\t}\n\n\t\t// Resolve the data context for evaluating this permission.\n\t\t// If the target starts with twin:information:<key>, the key references an entry in the information map.\n\t\tconst ruleDataContext = this.resolveRuleDataContext(permission, information, data);\n\n\t\t// All constraints must be satisfied for the permission to apply.\n\t\tconst constraintsSatisfied = constraints.every(c =>\n\t\t\tthis.evaluateConstraint(c, ruleDataContext)\n\t\t);\n\n\t\tif (!constraintsSatisfied) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn this.enforcePermissionDuties(policy, permission, information, ruleDataContext);\n\t}\n\n\t/**\n\t * Enforce duties attached to a permission.\n\t * @param policy The policy being evaluated.\n\t * @param permission The permission being evaluated.\n\t * @param information Additional facts provided by the PIP.\n\t * @param data The request data/context.\n\t * @returns True if all duties are enforced or none are present.\n\t * @internal\n\t */\n\tprivate async enforcePermissionDuties(\n\t\tpolicy: IDataspaceProtocolPolicy,\n\t\tpermission: IOdrlPermission,\n\t\tinformation?: { [id: string]: IJsonLdNodeObject },\n\t\tdata?: unknown\n\t): Promise<boolean> {\n\t\tconst duties = ArrayHelper.fromObjectOrArray(permission.duty ?? []);\n\t\tif (duties.length === 0) {\n\t\t\treturn true;\n\t\t}\n\n\t\tfor (const duty of duties) {\n\t\t\tconst enforced = await this.enforceDuty(policy, duty, information, data);\n\t\t\tif (!enforced) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Enforce a single duty using registered obligation enforcers.\n\t * @param policy The policy being evaluated.\n\t * @param duty The duty to enforce.\n\t * @param information Additional facts provided by the PIP.\n\t * @param data The request data/context.\n\t * @returns True if any enforcer succeeds.\n\t * @internal\n\t */\n\tprivate async enforceDuty(\n\t\tpolicy: IDataspaceProtocolPolicy,\n\t\tduty: IOdrlDuty,\n\t\tinformation?: { [id: string]: IJsonLdNodeObject },\n\t\tdata?: unknown\n\t): Promise<boolean> {\n\t\tconst enforcerNames = PolicyObligationEnforcerFactory.names();\n\n\t\tif (enforcerNames.length === 0) {\n\t\t\tthrow new GeneralError(DefaultPolicyArbiter.CLASS_NAME, \"noObligationEnforcersRegistered\");\n\t\t}\n\n\t\tfor (const enforcerName of enforcerNames) {\n\t\t\tconst enforcer = PolicyObligationEnforcerFactory.get(enforcerName);\n\t\t\tif (await enforcer.enforce(policy, duty, information, data)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/**\n\t * Resolve the data context used when evaluating a permission's constraints.\n\t * If the permission target is `twin:information:<key>`, the key references an entry in the information map.\n\t * @param rule The permission being evaluated.\n\t * @param information Additional facts provided by the PIP.\n\t * @param data The request data/context.\n\t * @returns The data context to use for JSONPath resolution.\n\t * @throws GeneralError When the information target key is missing.\n\t * @internal\n\t */\n\tprivate resolveRuleDataContext(\n\t\trule: IOdrlRule,\n\t\tinformation?: { [id: string]: IJsonLdNodeObject },\n\t\tdata?: unknown\n\t): unknown {\n\t\tconst targetId = this.getTargetId(rule.target);\n\n\t\tif (targetId?.startsWith(DefaultPolicyArbiter._INFORMATION_TARGET_PREFIX)) {\n\t\t\tconst key = targetId.slice(DefaultPolicyArbiter._INFORMATION_TARGET_PREFIX.length);\n\t\t\tif (Is.empty(key) || Is.empty(information?.[key])) {\n\t\t\t\tthrow new GeneralError(DefaultPolicyArbiter.CLASS_NAME, \"informationTargetMissing\", {\n\t\t\t\t\tkey\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn information[key];\n\t\t}\n\n\t\treturn data;\n\t}\n\n\t/**\n\t * Extract the target id from the permission.\n\t * @param target The permission target.\n\t * @returns The information key, or undefined when the target is not an information reference.\n\t * @internal\n\t */\n\tprivate getTargetId(target: IOdrlPermission[\"target\"]): string | undefined {\n\t\tif (Is.undefined(target)) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (Is.array(target) && target.length > 1) {\n\t\t\tthrow new GeneralError(DefaultPolicyArbiter.CLASS_NAME, \"multipleTargetsNotSupported\");\n\t\t}\n\n\t\tconst arr = ArrayHelper.fromObjectOrArray(target ?? []);\n\t\tif (arr.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn Is.string(arr[0]) ? arr[0] : OdrlPolicyHelper.getUid(arr[0]);\n\t}\n\n\t/**\n\t * Evaluate a single ODRL constraint against the available context.\n\t * Supports logical constraint composition through nested refinements.\n\t * @param constraint The constraint to evaluate.\n\t * @param ruleDataContext The request data/context.\n\t * @returns True if the constraint is satisfied.\n\t * @internal\n\t */\n\tprivate evaluateConstraint(\n\t\tconstraint: IOdrlConstraint | IOdrlLogicalConstraint,\n\t\truleDataContext?: unknown\n\t): boolean {\n\t\tconst logicalConstraint = this.getLogicalConstraintOperands(constraint);\n\t\tif (logicalConstraint) {\n\t\t\treturn this.evaluateLogicalConstraint(logicalConstraint, ruleDataContext);\n\t\t}\n\n\t\t// Must be a regular constraint beyond this point\n\t\tconst regularConstraint = constraint as IOdrlConstraint;\n\n\t\t// Evaluate the main constraint condition\n\t\tconst leftValue = this.calculateOperandValue(regularConstraint.leftOperand, ruleDataContext);\n\t\tconst rightValue = this.calculateOperandValue(regularConstraint.rightOperand, ruleDataContext);\n\t\tconst mainSatisfied = this.evaluateOperator(regularConstraint.operator, leftValue, rightValue);\n\n\t\t// If main constraint is not satisfied, the overall constraint fails\n\t\treturn mainSatisfied;\n\t}\n\n\t/**\n\t * Extract logical constraint operands when present.\n\t * @param constraint The constraint to inspect.\n\t * @returns The logical operator and its operands, or undefined when not logical.\n\t * @throws GeneralError if logical constraint operands are not unique.\n\t * @internal\n\t */\n\tprivate getLogicalConstraintOperands(constraint: IOdrlConstraint | IOdrlLogicalConstraint):\n\t\t| {\n\t\t\t\toperator: LogicalConstraintType;\n\t\t\t\tconstraints: (IOdrlConstraint | IOdrlLogicalConstraint)[];\n\t\t }\n\t\t| undefined {\n\t\tconst logicalConstraint = constraint as IOdrlLogicalConstraint;\n\t\tconst operators: LogicalConstraintType[] = Object.values(LogicalConstraintType);\n\t\tfor (const operator of operators) {\n\t\t\tconst value = logicalConstraint[operator];\n\t\t\tif (!Is.undefined(value)) {\n\t\t\t\tconst constraints = this.normalizeLogicalConstraintOperands(value);\n\t\t\t\tthis.validateLogicalConstraintOperandUniqueness(constraints, operator);\n\t\t\t\treturn {\n\t\t\t\t\toperator,\n\t\t\t\t\tconstraints\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Normalize logical constraint operands into a constraint array.\n\t * Handles both IOdrlConstraint and IOdrlLogicalConstraint types.\n\t * @param raw The raw operand value.\n\t * @returns The constraint array.\n\t * @internal\n\t */\n\tprivate normalizeLogicalConstraintOperands(\n\t\traw: unknown\n\t): (IOdrlConstraint | IOdrlLogicalConstraint)[] {\n\t\tlet normalized = raw;\n\t\tif (\n\t\t\tIs.object<IOdrlLogicalConstraintOperand>(normalized) &&\n\t\t\t!Is.undefined(normalized[\"@list\"])\n\t\t) {\n\t\t\tnormalized = normalized[\"@list\"];\n\t\t}\n\n\t\treturn (ArrayHelper.fromObjectOrArray(normalized) ?? [])\n\t\t\t.filter(item => Is.object(item))\n\t\t\t.map(item => item as IOdrlConstraint | IOdrlLogicalConstraint);\n\t}\n\n\t/**\n\t * Validate that all operands in a logical constraint are unique.\n\t * ODRL spec 2.5.2 requires that all operand values MUST be unique Constraint instances.\n\t * Uniqueness is checked by uid property and id property.\n\t * @param constraints The constraint operands to validate.\n\t * @param operator The logical operator type (for error messaging).\n\t * @throws GeneralError if duplicate constraints are found.\n\t * @internal\n\t */\n\tprivate validateLogicalConstraintOperandUniqueness(\n\t\tconstraints: (IOdrlConstraint | IOdrlLogicalConstraint)[],\n\t\toperator: LogicalConstraintType\n\t): void {\n\t\tconst seenIdentifiers = new Set<string>();\n\n\t\tfor (let i = 0; i < constraints.length; i++) {\n\t\t\tconst constraint = constraints[i];\n\t\t\tconst identifier = OdrlPolicyHelper.getUid(constraint);\n\n\t\t\t// If we have an identifier, check for duplicates\n\t\t\tif (Is.stringValue(identifier)) {\n\t\t\t\tif (seenIdentifiers.has(identifier)) {\n\t\t\t\t\tthrow new GeneralError(\n\t\t\t\t\t\tDefaultPolicyArbiter.CLASS_NAME,\n\t\t\t\t\t\t\"logicalConstraintOperandNotUnique\",\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\toperator,\n\t\t\t\t\t\t\tidentifier,\n\t\t\t\t\t\t\tindex: i\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tseenIdentifiers.add(identifier);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Evaluate a logical constraint operator against its operands.\n\t * @param logicalConstraint The operator and operand list.\n\t * @param ruleDataContext The request data/context.\n\t * @returns True if the logical constraint is satisfied.\n\t * @internal\n\t */\n\tprivate evaluateLogicalConstraint(\n\t\tlogicalConstraint: {\n\t\t\toperator: LogicalConstraintType;\n\t\t\tconstraints: (IOdrlConstraint | IOdrlLogicalConstraint)[];\n\t\t},\n\t\truleDataContext?: unknown\n\t): boolean {\n\t\tconst { operator, constraints } = logicalConstraint;\n\t\tif (constraints.length === 0) {\n\t\t\treturn false;\n\t\t}\n\n\t\tswitch (operator) {\n\t\t\tcase LogicalConstraintType.And:\n\t\t\t\treturn constraints.every(item => this.evaluateConstraint(item, ruleDataContext));\n\t\t\tcase LogicalConstraintType.AndSequence: {\n\t\t\t\tfor (const item of constraints) {\n\t\t\t\t\tif (!this.evaluateConstraint(item, ruleDataContext)) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tcase LogicalConstraintType.Or:\n\t\t\t\treturn constraints.some(item => this.evaluateConstraint(item, ruleDataContext));\n\t\t\tcase LogicalConstraintType.Xone: {\n\t\t\t\tlet satisfied = 0;\n\t\t\t\tfor (const item of constraints) {\n\t\t\t\t\tif (this.evaluateConstraint(item, ruleDataContext)) {\n\t\t\t\t\t\tsatisfied += 1;\n\t\t\t\t\t\tif (satisfied > 1) {\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn satisfied === 1;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Calculate an operand value.\n\t * @param operand The operand.\n\t * @param ruleDataContext The request data/context.\n\t * @returns The resolved operand value.\n\t * @internal\n\t */\n\tprivate calculateOperandValue(\n\t\toperand: IOdrlConstraint[\"leftOperand\"] | IOdrlConstraint[\"rightOperand\"] | string,\n\t\truleDataContext?: unknown\n\t): unknown {\n\t\t// Treat JSONPath operands as selectors against the current rule data context.\n\t\t// Will be in the format twin:jsonpath:<jsonPath>\n\t\tlet jsonPath: string | undefined;\n\t\tif (Is.stringValue(operand)) {\n\t\t\tif (operand.startsWith(`${DefaultPolicyArbiter._JSON_PATH_OPERAND_PREFIX}:`)) {\n\t\t\t\tjsonPath = operand.slice(DefaultPolicyArbiter._JSON_PATH_OPERAND_PREFIX.length + 1);\n\t\t\t\tif (jsonPath.length === 0) {\n\t\t\t\t\tthrow new GeneralError(DefaultPolicyArbiter.CLASS_NAME, \"jsonPathOperandMissingTarget\", {\n\t\t\t\t\t\toperand\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (Is.object<{ \"@type\": unknown; \"@value\": unknown }>(operand)) {\n\t\t\t// Is this an object { \"@value\": \"18\", \"@type\": \"xsd:integer\" } ?\n\t\t\tconst value = operand[\"@value\"];\n\t\t\tconst type = operand[\"@type\"];\n\t\t\tif (Is.stringValue(type)) {\n\t\t\t\t// If the type is set we can try and extract the value\n\t\t\t\t// is it twin:jsonpath ?\n\t\t\t\tif (type === DefaultPolicyArbiter._JSON_PATH_OPERAND_PREFIX) {\n\t\t\t\t\tif (Is.stringValue(value)) {\n\t\t\t\t\t\tjsonPath = value;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst xsdValue = this.coerceXsdType(value, type);\n\t\t\t\t\tif (!Is.undefined(xsdValue)) {\n\t\t\t\t\t\treturn xsdValue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// We have a JSON Path to resolve\n\t\tif (Is.stringValue(jsonPath)) {\n\t\t\tconst jsonPaths = JsonPathHelper.query(jsonPath, ruleDataContext);\n\t\t\tif (jsonPaths.length === 0) {\n\t\t\t\t// No matches\n\t\t\t\treturn undefined;\n\t\t\t} else if (jsonPaths.length === 1) {\n\t\t\t\t// Single match - return the value directly\n\t\t\t\treturn jsonPaths[0].value;\n\t\t\t}\n\n\t\t\t// Multiple matches - return array of values\n\t\t\treturn jsonPaths.map(p => p.value);\n\t\t}\n\n\t\t// Not JSON Path or object value so return as is\n\t\treturn operand;\n\t}\n\n\t/**\n\t * Evaluate an ODRL operator against resolved operands.\n\t * @param operator The operator.\n\t * @param left The resolved left operand.\n\t * @param right The resolved right operand.\n\t * @returns True if the comparison is satisfied.\n\t * @internal\n\t */\n\tprivate evaluateOperator(operator: OperatorType, left: unknown, right: unknown): boolean {\n\t\t// Handle array/collection left values (e.g. JSONPath returning multiple matches).\n\t\tconst leftValues = ArrayHelper.fromObjectOrArray(left ?? []);\n\n\t\tswitch (operator) {\n\t\t\tcase OperatorType.Eq:\n\t\t\t\treturn leftValues.some(v => ObjectHelper.equal(v, right, false));\n\t\t\tcase OperatorType.Neq:\n\t\t\t\treturn leftValues.every(v => !ObjectHelper.equal(v, right, false));\n\t\t\tcase OperatorType.Gt:\n\t\t\t\treturn leftValues.some(v => this.compareOrdered(v, right, (a, b) => a > b));\n\t\t\tcase OperatorType.Gteq:\n\t\t\t\treturn leftValues.some(v => this.compareOrdered(v, right, (a, b) => a >= b));\n\t\t\tcase OperatorType.Lt:\n\t\t\t\treturn leftValues.some(v => this.compareOrdered(v, right, (a, b) => a < b));\n\t\t\tcase OperatorType.Lteq:\n\t\t\t\treturn leftValues.some(v => this.compareOrdered(v, right, (a, b) => a <= b));\n\t\t\tcase OperatorType.IsAnyOf: {\n\t\t\t\treturn leftValues.some(v => {\n\t\t\t\t\tconst stringValue =\n\t\t\t\t\t\ttypeof v === \"string\" || typeof v === \"number\" || typeof v === \"boolean\"\n\t\t\t\t\t\t\t? String(v)\n\t\t\t\t\t\t\t: JSON.stringify(v);\n\t\t\t\t\treturn (ArrayHelper.fromObjectOrArray(right) ?? []).includes(stringValue);\n\t\t\t\t});\n\t\t\t}\n\t\t\tcase OperatorType.IsAllOf: {\n\t\t\t\treturn ObjectHelper.equal(leftValues, ArrayHelper.fromObjectOrArray(right) ?? [], false);\n\t\t\t}\n\t\t\tcase OperatorType.IsNoneOf: {\n\t\t\t\treturn leftValues.every(v => !(ArrayHelper.fromObjectOrArray(right) ?? []).includes(v));\n\t\t\t}\n\t\t\tcase OperatorType.LocTimeEq:\n\t\t\t\treturn leftValues.some(v => ObjectHelper.equal(v, right, false));\n\t\t\tcase OperatorType.LocTimeGteq:\n\t\t\t\treturn leftValues.some(v => this.compareOrdered(v, right, (a, b) => a >= b));\n\t\t\tcase OperatorType.IsA:\n\t\t\tcase OperatorType.HasPart:\n\t\t\tcase OperatorType.IsPartOf:\n\t\t\t\t// For now, treat these as simple equality/ordering semantics where meaningful.\n\t\t\t\t// Profiles can introduce richer semantics via additional arbiters.\n\t\t\t\treturn leftValues.some(v => ObjectHelper.equal(v, right, false));\n\t\t\tdefault:\n\t\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Compare values with numeric/date/string coercion.\n\t * @param left The left value.\n\t * @param right The right value.\n\t * @param compare Comparison operator.\n\t * @returns True if ordered comparison passes.\n\t * @internal\n\t */\n\tprivate compareOrdered(\n\t\tleft: unknown,\n\t\tright: unknown,\n\t\tcompare: (a: number, b: number) => boolean\n\t): boolean {\n\t\tconst leftNum = Coerce.number(left);\n\t\tconst rightNum = Coerce.number(right);\n\t\tif (!Is.undefined(leftNum) && !Is.undefined(rightNum)) {\n\t\t\treturn compare(leftNum, rightNum);\n\t\t}\n\t\tconst leftDate = Coerce.dateTime(left);\n\t\tconst rightDate = Coerce.dateTime(right);\n\t\tif (!Is.undefined(leftDate) && !Is.undefined(rightDate)) {\n\t\t\treturn compare(leftDate.getTime(), rightDate.getTime());\n\t\t}\n\n\t\t// Only use string ordering when both operands are actual strings.\n\t\t// Avoid coercing other types into strings, as that can cause\n\t\t// unintended comparisons like 18 >= \"$.minAge\" evaluating to true.\n\t\tif (Is.string(left) && Is.string(right)) {\n\t\t\treturn compare(left.localeCompare(right), 0);\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/**\n\t * Coerce a value to a specific XSD type.\n\t * @param value The value to coerce.\n\t * @param type The XSD type.\n\t * @returns The coerced value, or undefined when coercion is not possible.\n\t * @internal\n\t */\n\tprivate coerceXsdType(value: unknown, type: string): unknown {\n\t\tif (\n\t\t\t[\n\t\t\t\t\"xsd:string\",\n\t\t\t\t\"xsd:normalizedString\",\n\t\t\t\t\"xsd:token\",\n\t\t\t\t\"xsd:anyURI\",\n\t\t\t\t\"xsd:QName\",\n\t\t\t\t\"xsd:NOTATION\"\n\t\t\t].includes(type)\n\t\t) {\n\t\t\t// Handle standard xsd types\n\t\t\treturn Coerce.string(value);\n\t\t} else if (\n\t\t\t[\n\t\t\t\t\"xsd:integer\",\n\t\t\t\t\"xsd:decimal\",\n\t\t\t\t\"xsd:float\",\n\t\t\t\t\"xsd:double\",\n\t\t\t\t\"xsd:long\",\n\t\t\t\t\"xsd:int\",\n\t\t\t\t\"xsd:short\",\n\t\t\t\t\"xsd:byte\"\n\t\t\t].includes(type)\n\t\t) {\n\t\t\t// Handle standard xsd types\n\t\t\treturn Coerce.number(value);\n\t\t} else if (type === \"xsd:boolean\") {\n\t\t\t// Handle standard xsd types\n\t\t\treturn Coerce.boolean(value);\n\t\t} else if ([\"xsd:date\", \"xsd:dateTime\", \"xsd:time\"].includes(type)) {\n\t\t\t// Handle standard xsd types\n\t\t\treturn Coerce.dateTime(value);\n\t\t}\n\t\treturn undefined;\n\t}\n}\n"]}
1
+ {"version":3,"file":"defaultPolicyArbiter.js","sourceRoot":"","sources":["../../../src/policyArbiters/defaultPolicyArbiter.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,WAAW,EACX,MAAM,EACN,gBAAgB,EAChB,YAAY,EACZ,MAAM,EACN,EAAE,EACF,YAAY,EACZ,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;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C7B,CAAC;aAAM,IACN;YACC,aAAa;YACb,aAAa;YACb,WAAW;YACX,YAAY;YACZ,UAAU;YACV,SAAS;YACT,WAAW;YACX,UAAU;SACV,CAAC,QAAQ,CAAC,IAAI,CAAC,EACf,CAAC;YACF,4BAA4B;YAC5B,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC;aAAM,IAAI,IAAI,KAAK,aAAa,EAAE,CAAC;YACnC,4BAA4B;YAC5B,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;aAAM,IAAI,CAAC,UAAU,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACpE,4BAA4B;YAC5B,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,SAAS,CAAC;IAClB,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tArrayHelper,\n\tCoerce,\n\tComponentFactory,\n\tGeneralError,\n\tGuards,\n\tIs,\n\tObjectHelper\n} from \"@twin.org/core\";\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport { JsonPathHelper } from \"@twin.org/data-json-path\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tOdrlPolicyHelper,\n\tPolicyDecision,\n\tPolicyObligationEnforcerFactory,\n\ttype IPolicyAdministrationPointComponent,\n\ttype IPolicyArbiter,\n\ttype IPolicyDecision\n} from \"@twin.org/rights-management-models\";\nimport type {\n\tIDataspaceProtocolAgreement,\n\tIDataspaceProtocolPolicy\n} from \"@twin.org/standards-dataspace-protocol\";\nimport {\n\tOdrlConflictStrategyType,\n\tOdrlLogicalConstraintType,\n\tOdrlOperatorType,\n\ttype OdrlActionType,\n\ttype IOdrlConstraint,\n\ttype IOdrlDuty,\n\ttype IOdrlLogicalConstraint,\n\ttype IOdrlLogicalConstraintOperand,\n\ttype IOdrlPermission,\n\ttype IOdrlProhibition,\n\ttype IOdrlRule\n} from \"@twin.org/standards-w3c-odrl\";\nimport type { IDefaultPolicyArbiterConstructorOptions } from \"../models/IDefaultPolicyArbiterConstructorOptions.js\";\n\n/**\n * Default Policy Arbiter.\n */\nexport class DefaultPolicyArbiter implements IPolicyArbiter {\n\t/**\n\t * The class name of the Default Policy Arbiter.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<DefaultPolicyArbiter>();\n\n\t/**\n\t * Type indicating the operand type is JSONPath.\n\t * @internal\n\t */\n\tprivate static readonly _JSON_PATH_TYPE = \"jsonpath\";\n\n\t/**\n\t * Prefix indicating the operand encodes a JSONPath.\n\t * @internal\n\t */\n\tprivate static readonly _JSON_PATH_OPERAND_PREFIX = `twin:${DefaultPolicyArbiter._JSON_PATH_TYPE}`;\n\n\t/**\n\t * Prefix indicating the permission target references an item in the information map.\n\t * @internal\n\t */\n\tprivate static readonly _INFORMATION_TARGET_PREFIX = \"twin:information:\";\n\n\t/**\n\t * Default maximum inheritance depth.\n\t * @internal\n\t */\n\tprivate static readonly _DEFAULT_MAX_INHERITANCE_DEPTH = 10;\n\n\t/**\n\t * The logging component.\n\t * @internal\n\t */\n\tprivate readonly _logging: ILoggingComponent;\n\n\t/**\n\t * The policy administration point component.\n\t * @internal\n\t */\n\tprivate readonly _policyAdministrationPoint: IPolicyAdministrationPointComponent;\n\n\t/**\n\t * The maximum depth to traverse when resolving inherited policies.\n\t * @internal\n\t */\n\tprivate readonly _maxInheritanceDepth: number;\n\n\t/**\n\t * Create a new instance of DefaultPolicyArbiter.\n\t * @param options The options for the default policy arbiter.\n\t */\n\tconstructor(options?: IDefaultPolicyArbiterConstructorOptions) {\n\t\tthis._logging = ComponentFactory.get<ILoggingComponent>(\n\t\t\toptions?.loggingComponentType ?? \"logging\"\n\t\t);\n\n\t\tthis._policyAdministrationPoint = ComponentFactory.get<IPolicyAdministrationPointComponent>(\n\t\t\toptions?.policyAdministrationPointComponentType ?? \"policy-administration-point\"\n\t\t);\n\n\t\tthis._maxInheritanceDepth =\n\t\t\tCoerce.integer(options?.config?.maxInheritanceDepth) ??\n\t\t\tDefaultPolicyArbiter._DEFAULT_MAX_INHERITANCE_DEPTH;\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn DefaultPolicyArbiter.CLASS_NAME;\n\t}\n\n\t/**\n\t * Makes decisions regarding policy access to data.\n\t * @param agreement The agreement to evaluate.\n\t * @param information Information provided by the requester to determine if a policy can be created.\n\t * @param data The data to make a decision on.\n\t * @param action Optional action to make a decision on, if not provided, the arbiter will evaluate all actions in the agreement.\n\t * @returns The decisions about access to the data.\n\t */\n\tpublic async decide<D = unknown>(\n\t\tagreement: IDataspaceProtocolAgreement,\n\t\tinformation?: { [id: string]: IJsonLdNodeObject },\n\t\tdata?: D,\n\t\taction?: OdrlActionType | string\n\t): Promise<IPolicyDecision[]> {\n\t\tGuards.object<IDataspaceProtocolAgreement>(\n\t\t\tDefaultPolicyArbiter.CLASS_NAME,\n\t\t\tnameof(agreement),\n\t\t\tagreement\n\t\t);\n\n\t\tawait this._logging.log({\n\t\t\tlevel: \"info\",\n\t\t\tsource: DefaultPolicyArbiter.CLASS_NAME,\n\t\t\tts: Date.now(),\n\t\t\tmessage: \"decidingPolicy\",\n\t\t\tdata: {\n\t\t\t\tpolicyId: OdrlPolicyHelper.getUid(agreement) ?? \"\"\n\t\t\t}\n\t\t});\n\n\t\t// Resolve and merge inherited policies.\n\t\tconst mergedPolicy = await this.mergeInheritedPolicies(agreement);\n\n\t\t// Extract agreement parties once for use in rule evaluation\n\t\tconst agreementAssigner = OdrlPolicyHelper.getPartyIds(agreement.assigner);\n\t\tconst agreementAssignee = OdrlPolicyHelper.getPartyIds(agreement.assignee);\n\n\t\t// ODRL-style rule evaluation:\n\t\t// - Permission rules authorize if ANY applicable permission matches (OR across permissions).\n\t\t// - Default to denied when there are no permissions (closed-world for access control).\n\t\t// - Conflict strategy controls how applicable permissions/prohibitions are resolved.\n\t\tconst permissions = ArrayHelper.fromObjectOrArray(mergedPolicy.permission ?? []);\n\t\tlet permissionApplies = false;\n\t\tif (permissions.length > 0) {\n\t\t\tfor (const permission of permissions) {\n\t\t\t\tif (\n\t\t\t\t\tawait this.evaluatePermission(\n\t\t\t\t\t\tagreementAssigner,\n\t\t\t\t\t\tagreementAssignee,\n\t\t\t\t\t\tmergedPolicy,\n\t\t\t\t\t\tpermission,\n\t\t\t\t\t\tinformation,\n\t\t\t\t\t\tdata,\n\t\t\t\t\t\taction\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tpermissionApplies = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst prohibitions = ArrayHelper.fromObjectOrArray<IOdrlProhibition>(\n\t\t\tmergedPolicy.prohibition ?? []\n\t\t);\n\t\tlet prohibitionApplies = false;\n\t\tfor (const prohibition of prohibitions) {\n\t\t\tif (\n\t\t\t\tthis.evaluateProhibition(agreementAssigner, agreementAssignee, prohibition, data, action)\n\t\t\t) {\n\t\t\t\tprohibitionApplies = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tconst conflictStrategy = mergedPolicy.conflict ?? OdrlConflictStrategyType.Invalid;\n\t\tlet decision: PolicyDecision;\n\t\tif (permissionApplies && prohibitionApplies) {\n\t\t\tswitch (conflictStrategy) {\n\t\t\t\tcase OdrlConflictStrategyType.Perm:\n\t\t\t\t\tdecision = PolicyDecision.Granted;\n\t\t\t\t\tbreak;\n\t\t\t\tcase OdrlConflictStrategyType.Prohibit:\n\t\t\t\tcase OdrlConflictStrategyType.Invalid:\n\t\t\t\tdefault:\n\t\t\t\t\tdecision = PolicyDecision.Denied;\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t} else {\n\t\t\tdecision = permissionApplies ? PolicyDecision.Granted : PolicyDecision.Denied;\n\t\t}\n\n\t\treturn [{ target: \"$\", decision }];\n\t}\n\n\t/**\n\t * Evaluate whether a prohibition applies.\n\t * @param agreementAssigner The assigner ID from the agreement.\n\t * @param agreementAssignee The assignee ID from the agreement.\n\t * @param prohibition The prohibition to evaluate.\n\t * @param data The request data/context.\n\t * @param action Optional action to check against the prohibition's applicable actions.\n\t * @returns True if the prohibition applies.\n\t * @internal\n\t */\n\tprivate evaluateProhibition(\n\t\tagreementAssigner: string[] | undefined,\n\t\tagreementAssignee: string[] | undefined,\n\t\tprohibition: IOdrlProhibition,\n\t\tdata?: unknown,\n\t\taction?: OdrlActionType | string\n\t): boolean {\n\t\tif (!this.isRuleApplicableToParties(prohibition, agreementAssigner, agreementAssignee)) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Check if the prohibition's action(s) match the requested action\n\t\tif (!this.isActionApplicable(prohibition.action, action)) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// ODRL semantics: a rule without constraints is unconditional.\n\t\tconst constraints = ArrayHelper.fromObjectOrArray(prohibition.constraint ?? []);\n\t\tif (constraints.length === 0) {\n\t\t\treturn true;\n\t\t}\n\n\t\treturn constraints.every(c => this.evaluateConstraint(c, data));\n\t}\n\n\t/**\n\t * Merge inherited policies into the current policy.\n\t * Inherited policies' permissions, prohibitions, and obligations are combined with the current policy's rules.\n\t * @param policy The policy to evaluate.\n\t * @returns A new policy with merged rules from all ancestors.\n\t * @internal\n\t */\n\tprivate async mergeInheritedPolicies(\n\t\tpolicy: IDataspaceProtocolPolicy\n\t): Promise<IDataspaceProtocolPolicy> {\n\t\tconst visitedPolicyIds: string[] = [];\n\t\tvisitedPolicyIds.push(OdrlPolicyHelper.getUid(policy) ?? \"\");\n\t\tconst inheritedPolicies = await this.resolveInheritedPolicies(policy, visitedPolicyIds, 0);\n\t\tconst conflictStrategies = new Set<string>();\n\t\tif (Is.stringValue(policy.conflict)) {\n\t\t\tconflictStrategies.add(policy.conflict);\n\t\t}\n\n\t\t// Start with copies of the current policy's rules\n\t\tconst mergedPermissions: IOdrlPermission[] = ArrayHelper.fromObjectOrArray(\n\t\t\tpolicy.permission ?? []\n\t\t).map(permission => this.applyPolicyPartiesToRule(policy, permission));\n\n\t\tconst mergedProhibitions: IOdrlProhibition[] = ArrayHelper.fromObjectOrArray(\n\t\t\tpolicy.prohibition ?? []\n\t\t).map(prohibition => this.applyPolicyPartiesToRule(policy, prohibition));\n\n\t\tconst mergedObligations: IOdrlDuty[] = ArrayHelper.fromObjectOrArray(\n\t\t\tpolicy.obligation ?? []\n\t\t).map(obligation => this.applyPolicyPartiesToRule(policy, obligation));\n\n\t\t// Merge rules from each inherited policy\n\t\tfor (const inheritedPolicy of inheritedPolicies) {\n\t\t\tif (Is.stringValue(inheritedPolicy.conflict)) {\n\t\t\t\tconflictStrategies.add(inheritedPolicy.conflict);\n\t\t\t}\n\t\t\tconst inheritedPermissions = ArrayHelper.fromObjectOrArray(inheritedPolicy.permission ?? []);\n\t\t\tif (inheritedPermissions.length > 0) {\n\t\t\t\tmergedPermissions.push(\n\t\t\t\t\t...inheritedPermissions.map(permission =>\n\t\t\t\t\t\tthis.applyPolicyPartiesToRule(inheritedPolicy, permission)\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst inheritedProhibitions = ArrayHelper.fromObjectOrArray(\n\t\t\t\tinheritedPolicy.prohibition ?? []\n\t\t\t);\n\t\t\tif (inheritedProhibitions.length > 0) {\n\t\t\t\tmergedProhibitions.push(\n\t\t\t\t\t...inheritedProhibitions.map(prohibition =>\n\t\t\t\t\t\tthis.applyPolicyPartiesToRule(inheritedPolicy, prohibition)\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst inheritedObligations = ArrayHelper.fromObjectOrArray(inheritedPolicy.obligation ?? []);\n\t\t\tif (inheritedObligations.length > 0) {\n\t\t\t\tmergedObligations.push(\n\t\t\t\t\t...inheritedObligations.map(obligation =>\n\t\t\t\t\t\tthis.applyPolicyPartiesToRule(inheritedPolicy, obligation)\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tlet mergedConflict: IDataspaceProtocolPolicy[\"conflict\"] | undefined;\n\t\tif (conflictStrategies.size === 1) {\n\t\t\tmergedConflict = Array.from(conflictStrategies)[0] as IDataspaceProtocolPolicy[\"conflict\"];\n\t\t} else if (conflictStrategies.size > 1) {\n\t\t\tmergedConflict = OdrlConflictStrategyType.Invalid;\n\t\t}\n\n\t\t// Return a new policy with merged rules\n\t\treturn {\n\t\t\t...policy,\n\t\t\tconflict: mergedConflict,\n\t\t\tpermission: mergedPermissions.length > 0 ? mergedPermissions : undefined,\n\t\t\tprohibition: mergedProhibitions.length > 0 ? mergedProhibitions : undefined,\n\t\t\tobligation: mergedObligations.length > 0 ? mergedObligations : undefined\n\t\t};\n\t}\n\n\t/**\n\t * Resolve inherited policies by their UIDs from the Policy Administration Point.\n\t * Policies can inherit from other policies via the inheritFrom property.\n\t * Detects circular inheritance and throws an exception if detected.\n\t * @param policy The policy that may have inheritFrom references.\n\t * @param visitedPolicyIds Array of policy UIDs already visited in this inheritance chain.\n\t * @returns Array of inherited policies fetched from the PAP.\n\t * @throws GeneralError if a parent policy cannot be found or if circular inheritance is detected.\n\t * @internal\n\t */\n\tprivate async resolveInheritedPolicies(\n\t\tpolicy: IDataspaceProtocolPolicy,\n\t\tvisitedPolicyIds: string[],\n\t\tcurrentDepth: number\n\t): Promise<IDataspaceProtocolPolicy[]> {\n\t\tconst inheritedPolicies: IDataspaceProtocolPolicy[] = [];\n\n\t\t// If policy has no inheritFrom, return empty array\n\t\tif (Is.empty(policy.inheritFrom)) {\n\t\t\treturn inheritedPolicies;\n\t\t}\n\n\t\tconst inheritFromIds = ArrayHelper.fromObjectOrArray<string>(policy.inheritFrom) ?? [];\n\n\t\tfor (const inheritFromId of inheritFromIds) {\n\t\t\tconst nextDepth = currentDepth + 1;\n\t\t\tif (nextDepth > this._maxInheritanceDepth) {\n\t\t\t\tthrow new GeneralError(DefaultPolicyArbiter.CLASS_NAME, \"maxInheritanceDepthExceeded\", {\n\t\t\t\t\tpolicyId: OdrlPolicyHelper.getUid(policy) ?? \"\",\n\t\t\t\t\tinheritFromId,\n\t\t\t\t\tmaxInheritanceDepth: this._maxInheritanceDepth\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Check for circular inheritance\n\t\t\tif (visitedPolicyIds.includes(inheritFromId)) {\n\t\t\t\tthrow new GeneralError(DefaultPolicyArbiter.CLASS_NAME, \"circularInheritanceDetected\", {\n\t\t\t\t\tpolicyId: OdrlPolicyHelper.getUid(policy) ?? \"\",\n\t\t\t\t\tinheritFromId\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Fetch the inherited policy from the PAP\n\t\t\tconst inheritedPolicy = await this._policyAdministrationPoint.get(inheritFromId);\n\t\t\tif (Is.empty(inheritedPolicy)) {\n\t\t\t\tthrow new GeneralError(DefaultPolicyArbiter.CLASS_NAME, \"inheritedPolicyNotFound\", {\n\t\t\t\t\tinheritFromId\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Mark this policy as visited\n\t\t\tvisitedPolicyIds.push(inheritFromId);\n\n\t\t\tinheritedPolicies.push(inheritedPolicy);\n\n\t\t\t// Recursively resolve inherited policies of the parent\n\t\t\tconst grandparentPolicies = await this.resolveInheritedPolicies(\n\t\t\t\tinheritedPolicy,\n\t\t\t\tvisitedPolicyIds,\n\t\t\t\tnextDepth\n\t\t\t);\n\t\t\tinheritedPolicies.push(...grandparentPolicies);\n\t\t}\n\n\t\treturn inheritedPolicies;\n\t}\n\n\t/**\n\t * Apply policy-level assigner/assignee values to rules that don't override them.\n\t * @param policy The policy providing defaults.\n\t * @param rule The rule to apply defaults to.\n\t * @returns The rule with policy-level assigner/assignee applied.\n\t * @internal\n\t */\n\tprivate applyPolicyPartiesToRule<T extends IOdrlRule>(\n\t\tpolicy: IDataspaceProtocolPolicy,\n\t\trule: T\n\t): T {\n\t\tconst assigner = Is.empty(rule.assigner) ? policy.assigner : rule.assigner;\n\t\tconst assignee = Is.empty(rule.assignee) ? policy.assignee : rule.assignee;\n\n\t\tconst assignerIds = OdrlPolicyHelper.getPartyIds(assigner);\n\t\tconst ruleAssignerIds = OdrlPolicyHelper.getPartyIds(rule.assigner);\n\t\tconst assigneeIds = OdrlPolicyHelper.getPartyIds(assignee);\n\t\tconst ruleAssigneeIds = OdrlPolicyHelper.getPartyIds(rule.assignee);\n\n\t\tlet assignerEqual = false;\n\t\tif (Is.empty(assignerIds) && Is.empty(ruleAssignerIds)) {\n\t\t\tassignerEqual = true;\n\t\t} else if (!Is.empty(assignerIds) && !Is.empty(ruleAssignerIds)) {\n\t\t\tassignerEqual =\n\t\t\t\tassignerIds.length === ruleAssignerIds.length &&\n\t\t\t\tassignerIds.every(id => ruleAssignerIds.includes(id));\n\t\t}\n\n\t\tlet assigneeEqual = false;\n\t\tif (Is.empty(assigneeIds) && Is.empty(ruleAssigneeIds)) {\n\t\t\tassigneeEqual = true;\n\t\t} else if (!Is.empty(assigneeIds) && !Is.empty(ruleAssigneeIds)) {\n\t\t\tassigneeEqual =\n\t\t\t\tassigneeIds.length === ruleAssigneeIds.length &&\n\t\t\t\tassigneeIds.every(id => ruleAssigneeIds.includes(id));\n\t\t}\n\n\t\tif (assignerEqual && assigneeEqual) {\n\t\t\treturn rule;\n\t\t}\n\n\t\treturn {\n\t\t\t...rule,\n\t\t\tassigner,\n\t\t\tassignee\n\t\t};\n\t}\n\n\t/**\n\t * Determine whether a rule applies to the agreement parties based on assigner/assignee.\n\t * @param rule The rule to evaluate.\n\t * @param agreementAssigner The assigner ID from the agreement.\n\t * @param agreementAssignee The assignee ID from the agreement.\n\t * @returns True if the rule is applicable to the agreement parties.\n\t * @internal\n\t */\n\tprivate isRuleApplicableToParties(\n\t\trule: IOdrlRule,\n\t\tagreementAssigner: string[] | undefined,\n\t\tagreementAssignee: string[] | undefined\n\t): boolean {\n\t\tconst ruleAssigners = OdrlPolicyHelper.getPartyIds(rule.assigner);\n\t\tconst ruleAssignees = OdrlPolicyHelper.getPartyIds(rule.assignee);\n\n\t\tif (!this.isPartyApplicable(ruleAssigners, agreementAssigner)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (!this.isPartyApplicable(ruleAssignees, agreementAssignee)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Determine whether a rule party constraint applies to the agreement parties.\n\t * Rule party is treated as a constraint: if specified, it must match at least one agreement party.\n\t * @param rulePartyIds The party ids specified on the rule (if any).\n\t * @param agreementPartyIds The party ids extracted from the agreement.\n\t * @returns True if the rule party constraint is satisfied.\n\t * @internal\n\t */\n\tprivate isPartyApplicable(\n\t\trulePartyIds: string[] | undefined,\n\t\tagreementPartyIds: string[] | undefined\n\t): boolean {\n\t\t// No party specified on rule means it applies to any agreement party.\n\t\tif (Is.empty(rulePartyIds)) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Rule specifies party/parties, but agreement doesn't provide any.\n\t\tif (Is.empty(agreementPartyIds)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tfor (const rulePartyId of rulePartyIds) {\n\t\t\tif (agreementPartyIds.includes(rulePartyId)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/**\n\t * Determine whether a rule's action(s) match the requested action.\n\t * If no action is specified in the rule, it applies to all actions (action-agnostic).\n\t * If an action is specified in the rule and a specific action is requested, they must match.\n\t * If an action is specified in the rule but no specific action is requested, the rule applies (general evaluation).\n\t * @param ruleActions The actions defined in the rule (can be string, object, or array).\n\t * @param requestedAction The action being requested (optional).\n\t * @returns True if the rule's action(s) apply.\n\t * @internal\n\t */\n\tprivate isActionApplicable(\n\t\truleActions: IOdrlRule[\"action\"],\n\t\trequestedAction?: OdrlActionType | string\n\t): boolean {\n\t\t// If the rule has no action specified, it applies to all actions\n\t\tif (Is.empty(ruleActions)) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// If the rule has actions but no specific action is requested,\n\t\t// the rule applies (we're evaluating permissions in general)\n\t\tif (Is.empty(requestedAction)) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Both rule actions and requested action are specified - check for match\n\t\tconst ruleActionArray = ArrayHelper.fromObjectOrArray(ruleActions) ?? [];\n\n\t\t// Check if the requested action matches any of the rule's actions\n\t\tfor (const ruleAction of ruleActionArray) {\n\t\t\tconst ruleActionId = Is.string(ruleAction) ? ruleAction : OdrlPolicyHelper.getUid(ruleAction);\n\t\t\tconst requestedActionId = Is.string(requestedAction)\n\t\t\t\t? requestedAction\n\t\t\t\t: OdrlPolicyHelper.getUid(requestedAction);\n\n\t\t\tif (Is.stringValue(ruleActionId) && Is.stringValue(requestedActionId)) {\n\t\t\t\tif (ruleActionId === requestedActionId) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/**\n\t * Apply a permission and create decisions based on that information.\n\t * @param agreementAssigner The assigner ID from the agreement.\n\t * @param agreementAssignee The assignee ID from the agreement.\n\t * @param policy The policy containing the permission.\n\t * @param permission The permission to apply.\n\t * @param information Additional facts provided by the PIP.\n\t * @param data The request data/context.\n\t * @returns True if the permission applies.\n\t * @internal\n\t */\n\tprivate async evaluatePermission(\n\t\tagreementAssigner: string[] | undefined,\n\t\tagreementAssignee: string[] | undefined,\n\t\tpolicy: IDataspaceProtocolPolicy,\n\t\tpermission: IOdrlPermission,\n\t\tinformation?: { [id: string]: IJsonLdNodeObject },\n\t\tdata?: unknown,\n\t\taction?: OdrlActionType | string\n\t): Promise<boolean> {\n\t\tif (!this.isRuleApplicableToParties(permission, agreementAssigner, agreementAssignee)) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Check if the permission's action(s) match the requested action\n\t\tif (!this.isActionApplicable(permission.action, action)) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// ODRL semantics: a Permission without constraints is unconditional.\n\t\tconst constraints = ArrayHelper.fromObjectOrArray(permission.constraint ?? []);\n\t\tif (constraints.length === 0) {\n\t\t\treturn this.enforcePermissionDuties(policy, permission, information, data);\n\t\t}\n\n\t\t// Resolve the data context for evaluating this permission.\n\t\t// If the target starts with twin:information:<key>, the key references an entry in the information map.\n\t\tconst ruleDataContext = this.resolveRuleDataContext(permission, information, data);\n\n\t\t// All constraints must be satisfied for the permission to apply.\n\t\tconst constraintsSatisfied = constraints.every(c =>\n\t\t\tthis.evaluateConstraint(c, ruleDataContext)\n\t\t);\n\n\t\tif (!constraintsSatisfied) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn this.enforcePermissionDuties(policy, permission, information, ruleDataContext);\n\t}\n\n\t/**\n\t * Enforce duties attached to a permission.\n\t * @param policy The policy being evaluated.\n\t * @param permission The permission being evaluated.\n\t * @param information Additional facts provided by the PIP.\n\t * @param data The request data/context.\n\t * @returns True if all duties are enforced or none are present.\n\t * @internal\n\t */\n\tprivate async enforcePermissionDuties(\n\t\tpolicy: IDataspaceProtocolPolicy,\n\t\tpermission: IOdrlPermission,\n\t\tinformation?: { [id: string]: IJsonLdNodeObject },\n\t\tdata?: unknown\n\t): Promise<boolean> {\n\t\tconst duties = ArrayHelper.fromObjectOrArray(permission.duty ?? []);\n\t\tif (duties.length === 0) {\n\t\t\treturn true;\n\t\t}\n\n\t\tfor (const duty of duties) {\n\t\t\tconst enforced = await this.enforceDuty(policy, duty, information, data);\n\t\t\tif (!enforced) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Enforce a single duty using registered obligation enforcers.\n\t * @param policy The policy being evaluated.\n\t * @param duty The duty to enforce.\n\t * @param information Additional facts provided by the PIP.\n\t * @param data The request data/context.\n\t * @returns True if any enforcer succeeds.\n\t * @internal\n\t */\n\tprivate async enforceDuty(\n\t\tpolicy: IDataspaceProtocolPolicy,\n\t\tduty: IOdrlDuty,\n\t\tinformation?: { [id: string]: IJsonLdNodeObject },\n\t\tdata?: unknown\n\t): Promise<boolean> {\n\t\tconst enforcerNames = PolicyObligationEnforcerFactory.names();\n\n\t\tif (enforcerNames.length === 0) {\n\t\t\tthrow new GeneralError(DefaultPolicyArbiter.CLASS_NAME, \"noObligationEnforcersRegistered\");\n\t\t}\n\n\t\tfor (const enforcerName of enforcerNames) {\n\t\t\tconst enforcer = PolicyObligationEnforcerFactory.get(enforcerName);\n\t\t\tif (await enforcer.enforce(policy, duty, information, data)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/**\n\t * Resolve the data context used when evaluating a permission's constraints.\n\t * If the permission target is `twin:information:<key>`, the key references an entry in the information map.\n\t * @param rule The permission being evaluated.\n\t * @param information Additional facts provided by the PIP.\n\t * @param data The request data/context.\n\t * @returns The data context to use for JSONPath resolution.\n\t * @throws GeneralError When the information target key is missing.\n\t * @internal\n\t */\n\tprivate resolveRuleDataContext(\n\t\trule: IOdrlRule,\n\t\tinformation?: { [id: string]: IJsonLdNodeObject },\n\t\tdata?: unknown\n\t): unknown {\n\t\tconst targetId = this.getTargetId(rule.target);\n\n\t\tif (targetId?.startsWith(DefaultPolicyArbiter._INFORMATION_TARGET_PREFIX)) {\n\t\t\tconst key = targetId.slice(DefaultPolicyArbiter._INFORMATION_TARGET_PREFIX.length);\n\t\t\tif (Is.empty(key) || Is.empty(information?.[key])) {\n\t\t\t\tthrow new GeneralError(DefaultPolicyArbiter.CLASS_NAME, \"informationTargetMissing\", {\n\t\t\t\t\tkey\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn information[key];\n\t\t}\n\n\t\treturn data;\n\t}\n\n\t/**\n\t * Extract the target id from the permission.\n\t * @param target The permission target.\n\t * @returns The information key, or undefined when the target is not an information reference.\n\t * @internal\n\t */\n\tprivate getTargetId(target: IOdrlPermission[\"target\"]): string | undefined {\n\t\tif (Is.undefined(target)) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (Is.array(target) && target.length > 1) {\n\t\t\tthrow new GeneralError(DefaultPolicyArbiter.CLASS_NAME, \"multipleTargetsNotSupported\");\n\t\t}\n\n\t\tconst arr = ArrayHelper.fromObjectOrArray(target ?? []);\n\t\tif (arr.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn Is.string(arr[0]) ? arr[0] : OdrlPolicyHelper.getUid(arr[0]);\n\t}\n\n\t/**\n\t * Evaluate a single ODRL constraint against the available context.\n\t * Supports logical constraint composition through nested refinements.\n\t * @param constraint The constraint to evaluate.\n\t * @param ruleDataContext The request data/context.\n\t * @returns True if the constraint is satisfied.\n\t * @internal\n\t */\n\tprivate evaluateConstraint(\n\t\tconstraint: IOdrlConstraint | IOdrlLogicalConstraint,\n\t\truleDataContext?: unknown\n\t): boolean {\n\t\tconst logicalConstraint = this.getLogicalConstraintOperands(constraint);\n\t\tif (logicalConstraint) {\n\t\t\treturn this.evaluateLogicalConstraint(logicalConstraint, ruleDataContext);\n\t\t}\n\n\t\t// Must be a regular constraint beyond this point\n\t\tconst regularConstraint = constraint as IOdrlConstraint;\n\n\t\t// Evaluate the main constraint condition\n\t\tconst leftValue = this.calculateOperandValue(regularConstraint.leftOperand, ruleDataContext);\n\t\tconst rightValue = this.calculateOperandValue(regularConstraint.rightOperand, ruleDataContext);\n\t\tconst mainSatisfied = this.evaluateOperator(regularConstraint.operator, leftValue, rightValue);\n\n\t\t// If main constraint is not satisfied, the overall constraint fails\n\t\treturn mainSatisfied;\n\t}\n\n\t/**\n\t * Extract logical constraint operands when present.\n\t * @param constraint The constraint to inspect.\n\t * @returns The logical operator and its operands, or undefined when not logical.\n\t * @throws GeneralError if logical constraint operands are not unique.\n\t * @internal\n\t */\n\tprivate getLogicalConstraintOperands(constraint: IOdrlConstraint | IOdrlLogicalConstraint):\n\t\t| {\n\t\t\t\toperator: OdrlLogicalConstraintType;\n\t\t\t\tconstraints: (IOdrlConstraint | IOdrlLogicalConstraint)[];\n\t\t }\n\t\t| undefined {\n\t\tconst logicalConstraint = constraint as IOdrlLogicalConstraint;\n\t\tconst operators: OdrlLogicalConstraintType[] = Object.values(OdrlLogicalConstraintType);\n\t\tfor (const operator of operators) {\n\t\t\tconst value = logicalConstraint[operator];\n\t\t\tif (!Is.undefined(value)) {\n\t\t\t\tconst constraints = this.normalizeLogicalConstraintOperands(value);\n\t\t\t\tthis.validateLogicalConstraintOperandUniqueness(constraints, operator);\n\t\t\t\treturn {\n\t\t\t\t\toperator,\n\t\t\t\t\tconstraints\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Normalize logical constraint operands into a constraint array.\n\t * Handles both IOdrlConstraint and IOdrlLogicalConstraint types.\n\t * @param raw The raw operand value.\n\t * @returns The constraint array.\n\t * @internal\n\t */\n\tprivate normalizeLogicalConstraintOperands(\n\t\traw: unknown\n\t): (IOdrlConstraint | IOdrlLogicalConstraint)[] {\n\t\tlet normalized = raw;\n\t\tif (\n\t\t\tIs.object<IOdrlLogicalConstraintOperand>(normalized) &&\n\t\t\t!Is.undefined(normalized[\"@list\"])\n\t\t) {\n\t\t\tnormalized = normalized[\"@list\"];\n\t\t}\n\n\t\treturn (ArrayHelper.fromObjectOrArray(normalized) ?? [])\n\t\t\t.filter(item => Is.object(item))\n\t\t\t.map(item => item as IOdrlConstraint | IOdrlLogicalConstraint);\n\t}\n\n\t/**\n\t * Validate that all operands in a logical constraint are unique.\n\t * ODRL spec 2.5.2 requires that all operand values MUST be unique Constraint instances.\n\t * Uniqueness is checked by uid property and id property.\n\t * @param constraints The constraint operands to validate.\n\t * @param operator The logical operator type (for error messaging).\n\t * @throws GeneralError if duplicate constraints are found.\n\t * @internal\n\t */\n\tprivate validateLogicalConstraintOperandUniqueness(\n\t\tconstraints: (IOdrlConstraint | IOdrlLogicalConstraint)[],\n\t\toperator: OdrlLogicalConstraintType\n\t): void {\n\t\tconst seenIdentifiers = new Set<string>();\n\n\t\tfor (let i = 0; i < constraints.length; i++) {\n\t\t\tconst constraint = constraints[i];\n\t\t\tconst identifier = OdrlPolicyHelper.getUid(constraint);\n\n\t\t\t// If we have an identifier, check for duplicates\n\t\t\tif (Is.stringValue(identifier)) {\n\t\t\t\tif (seenIdentifiers.has(identifier)) {\n\t\t\t\t\tthrow new GeneralError(\n\t\t\t\t\t\tDefaultPolicyArbiter.CLASS_NAME,\n\t\t\t\t\t\t\"logicalConstraintOperandNotUnique\",\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\toperator,\n\t\t\t\t\t\t\tidentifier,\n\t\t\t\t\t\t\tindex: i\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tseenIdentifiers.add(identifier);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Evaluate a logical constraint operator against its operands.\n\t * @param logicalConstraint The operator and operand list.\n\t * @param ruleDataContext The request data/context.\n\t * @returns True if the logical constraint is satisfied.\n\t * @internal\n\t */\n\tprivate evaluateLogicalConstraint(\n\t\tlogicalConstraint: {\n\t\t\toperator: OdrlLogicalConstraintType;\n\t\t\tconstraints: (IOdrlConstraint | IOdrlLogicalConstraint)[];\n\t\t},\n\t\truleDataContext?: unknown\n\t): boolean {\n\t\tconst { operator, constraints } = logicalConstraint;\n\t\tif (constraints.length === 0) {\n\t\t\treturn false;\n\t\t}\n\n\t\tswitch (operator) {\n\t\t\tcase OdrlLogicalConstraintType.And:\n\t\t\t\treturn constraints.every(item => this.evaluateConstraint(item, ruleDataContext));\n\t\t\tcase OdrlLogicalConstraintType.AndSequence: {\n\t\t\t\tfor (const item of constraints) {\n\t\t\t\t\tif (!this.evaluateConstraint(item, ruleDataContext)) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tcase OdrlLogicalConstraintType.Or:\n\t\t\t\treturn constraints.some(item => this.evaluateConstraint(item, ruleDataContext));\n\t\t\tcase OdrlLogicalConstraintType.Xone: {\n\t\t\t\tlet satisfied = 0;\n\t\t\t\tfor (const item of constraints) {\n\t\t\t\t\tif (this.evaluateConstraint(item, ruleDataContext)) {\n\t\t\t\t\t\tsatisfied += 1;\n\t\t\t\t\t\tif (satisfied > 1) {\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn satisfied === 1;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Calculate an operand value.\n\t * @param operand The operand.\n\t * @param ruleDataContext The request data/context.\n\t * @returns The resolved operand value.\n\t * @internal\n\t */\n\tprivate calculateOperandValue(\n\t\toperand: IOdrlConstraint[\"leftOperand\"] | IOdrlConstraint[\"rightOperand\"] | string,\n\t\truleDataContext?: unknown\n\t): unknown {\n\t\t// Treat JSONPath operands as selectors against the current rule data context.\n\t\t// Will be in the format twin:jsonpath:<jsonPath>\n\t\tlet jsonPath: string | undefined;\n\t\tif (Is.stringValue(operand)) {\n\t\t\tif (operand.startsWith(`${DefaultPolicyArbiter._JSON_PATH_OPERAND_PREFIX}:`)) {\n\t\t\t\tjsonPath = operand.slice(DefaultPolicyArbiter._JSON_PATH_OPERAND_PREFIX.length + 1);\n\t\t\t\tif (jsonPath.length === 0) {\n\t\t\t\t\tthrow new GeneralError(DefaultPolicyArbiter.CLASS_NAME, \"jsonPathOperandMissingTarget\", {\n\t\t\t\t\t\toperand\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (Is.object<{ \"@type\": unknown; \"@value\": unknown }>(operand)) {\n\t\t\t// Is this an object { \"@value\": \"18\", \"@type\": \"xsd:integer\" } ?\n\t\t\tconst value = operand[\"@value\"];\n\t\t\tconst type = operand[\"@type\"];\n\t\t\tif (Is.stringValue(type)) {\n\t\t\t\t// If the type is set we can try and extract the value\n\t\t\t\t// is it twin:jsonpath ?\n\t\t\t\tif (type === DefaultPolicyArbiter._JSON_PATH_OPERAND_PREFIX) {\n\t\t\t\t\tif (Is.stringValue(value)) {\n\t\t\t\t\t\tjsonPath = value;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst xsdValue = this.coerceXsdType(value, type);\n\t\t\t\t\tif (!Is.undefined(xsdValue)) {\n\t\t\t\t\t\treturn xsdValue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// We have a JSON Path to resolve\n\t\tif (Is.stringValue(jsonPath)) {\n\t\t\tconst jsonPaths = JsonPathHelper.query(jsonPath, ruleDataContext);\n\t\t\tif (jsonPaths.length === 0) {\n\t\t\t\t// No matches\n\t\t\t\treturn undefined;\n\t\t\t} else if (jsonPaths.length === 1) {\n\t\t\t\t// Single match - return the value directly\n\t\t\t\treturn jsonPaths[0].value;\n\t\t\t}\n\n\t\t\t// Multiple matches - return array of values\n\t\t\treturn jsonPaths.map(p => p.value);\n\t\t}\n\n\t\t// Not JSON Path or object value so return as is\n\t\treturn operand;\n\t}\n\n\t/**\n\t * Evaluate an ODRL operator against resolved operands.\n\t * @param operator The operator.\n\t * @param left The resolved left operand.\n\t * @param right The resolved right operand.\n\t * @returns True if the comparison is satisfied.\n\t * @internal\n\t */\n\tprivate evaluateOperator(operator: OdrlOperatorType, left: unknown, right: unknown): boolean {\n\t\t// Handle array/collection left values (e.g. JSONPath returning multiple matches).\n\t\tconst leftValues = ArrayHelper.fromObjectOrArray(left ?? []);\n\n\t\tswitch (operator) {\n\t\t\tcase OdrlOperatorType.Eq:\n\t\t\t\treturn leftValues.some(v => ObjectHelper.equal(v, right, false));\n\t\t\tcase OdrlOperatorType.Neq:\n\t\t\t\treturn leftValues.every(v => !ObjectHelper.equal(v, right, false));\n\t\t\tcase OdrlOperatorType.Gt:\n\t\t\t\treturn leftValues.some(v => this.compareOrdered(v, right, (a, b) => a > b));\n\t\t\tcase OdrlOperatorType.Gteq:\n\t\t\t\treturn leftValues.some(v => this.compareOrdered(v, right, (a, b) => a >= b));\n\t\t\tcase OdrlOperatorType.Lt:\n\t\t\t\treturn leftValues.some(v => this.compareOrdered(v, right, (a, b) => a < b));\n\t\t\tcase OdrlOperatorType.Lteq:\n\t\t\t\treturn leftValues.some(v => this.compareOrdered(v, right, (a, b) => a <= b));\n\t\t\tcase OdrlOperatorType.IsAnyOf: {\n\t\t\t\treturn leftValues.some(v => {\n\t\t\t\t\tconst stringValue =\n\t\t\t\t\t\ttypeof v === \"string\" || typeof v === \"number\" || typeof v === \"boolean\"\n\t\t\t\t\t\t\t? String(v)\n\t\t\t\t\t\t\t: JSON.stringify(v);\n\t\t\t\t\treturn (ArrayHelper.fromObjectOrArray(right) ?? []).includes(stringValue);\n\t\t\t\t});\n\t\t\t}\n\t\t\tcase OdrlOperatorType.IsAllOf: {\n\t\t\t\treturn ObjectHelper.equal(leftValues, ArrayHelper.fromObjectOrArray(right) ?? [], false);\n\t\t\t}\n\t\t\tcase OdrlOperatorType.IsNoneOf: {\n\t\t\t\treturn leftValues.every(v => !(ArrayHelper.fromObjectOrArray(right) ?? []).includes(v));\n\t\t\t}\n\t\t\tcase OdrlOperatorType.LocTimeEq:\n\t\t\t\treturn leftValues.some(v => ObjectHelper.equal(v, right, false));\n\t\t\tcase OdrlOperatorType.LocTimeGteq:\n\t\t\t\treturn leftValues.some(v => this.compareOrdered(v, right, (a, b) => a >= b));\n\t\t\tcase OdrlOperatorType.IsA:\n\t\t\tcase OdrlOperatorType.HasPart:\n\t\t\tcase OdrlOperatorType.IsPartOf:\n\t\t\t\t// For now, treat these as simple equality/ordering semantics where meaningful.\n\t\t\t\t// Profiles can introduce richer semantics via additional arbiters.\n\t\t\t\treturn leftValues.some(v => ObjectHelper.equal(v, right, false));\n\t\t\tdefault:\n\t\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Compare values with numeric/date/string coercion.\n\t * @param left The left value.\n\t * @param right The right value.\n\t * @param compare Comparison operator.\n\t * @returns True if ordered comparison passes.\n\t * @internal\n\t */\n\tprivate compareOrdered(\n\t\tleft: unknown,\n\t\tright: unknown,\n\t\tcompare: (a: number, b: number) => boolean\n\t): boolean {\n\t\tconst leftNum = Coerce.number(left);\n\t\tconst rightNum = Coerce.number(right);\n\t\tif (!Is.undefined(leftNum) && !Is.undefined(rightNum)) {\n\t\t\treturn compare(leftNum, rightNum);\n\t\t}\n\t\tconst leftDate = Coerce.dateTime(left);\n\t\tconst rightDate = Coerce.dateTime(right);\n\t\tif (!Is.undefined(leftDate) && !Is.undefined(rightDate)) {\n\t\t\treturn compare(leftDate.getTime(), rightDate.getTime());\n\t\t}\n\n\t\t// Only use string ordering when both operands are actual strings.\n\t\t// Avoid coercing other types into strings, as that can cause\n\t\t// unintended comparisons like 18 >= \"$.minAge\" evaluating to true.\n\t\tif (Is.string(left) && Is.string(right)) {\n\t\t\treturn compare(left.localeCompare(right), 0);\n\t\t}\n\n\t\treturn false;\n\t}\n\n\t/**\n\t * Coerce a value to a specific XSD type.\n\t * @param value The value to coerce.\n\t * @param type The XSD type.\n\t * @returns The coerced value, or undefined when coercion is not possible.\n\t * @internal\n\t */\n\tprivate coerceXsdType(value: unknown, type: string): unknown {\n\t\tif (\n\t\t\t[\n\t\t\t\t\"xsd:string\",\n\t\t\t\t\"xsd:normalizedString\",\n\t\t\t\t\"xsd:token\",\n\t\t\t\t\"xsd:anyURI\",\n\t\t\t\t\"xsd:QName\",\n\t\t\t\t\"xsd:NOTATION\"\n\t\t\t].includes(type)\n\t\t) {\n\t\t\t// Handle standard xsd types\n\t\t\treturn Coerce.string(value);\n\t\t} else if (\n\t\t\t[\n\t\t\t\t\"xsd:integer\",\n\t\t\t\t\"xsd:decimal\",\n\t\t\t\t\"xsd:float\",\n\t\t\t\t\"xsd:double\",\n\t\t\t\t\"xsd:long\",\n\t\t\t\t\"xsd:int\",\n\t\t\t\t\"xsd:short\",\n\t\t\t\t\"xsd:byte\"\n\t\t\t].includes(type)\n\t\t) {\n\t\t\t// Handle standard xsd types\n\t\t\treturn Coerce.number(value);\n\t\t} else if (type === \"xsd:boolean\") {\n\t\t\t// Handle standard xsd types\n\t\t\treturn Coerce.boolean(value);\n\t\t} else if ([\"xsd:date\", \"xsd:dateTime\", \"xsd:time\"].includes(type)) {\n\t\t\t// Handle standard xsd types\n\t\t\treturn Coerce.dateTime(value);\n\t\t}\n\t\treturn undefined;\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"passThroughPolicyArbiter.js","sourceRoot":"","sources":["../../../src/policyArbiters/passThroughPolicyArbiter.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAI1D,OAAO,EACN,gBAAgB,EAChB,cAAc,EAGd,MAAM,oCAAoC,CAAC;AAK5C;;GAEG;AACH,MAAM,OAAO,wBAAwB;IACpC;;OAEG;IACI,MAAM,CAAU,UAAU,8BAA8C;IAE/E;;;OAGG;IACc,QAAQ,CAAoB;IAE7C;;;OAGG;IACH,YAAY,OAAqD;QAChE,IAAI,CAAC,QAAQ,GAAG,gBAAgB,CAAC,GAAG,CACnC,OAAO,EAAE,oBAAoB,IAAI,SAAS,CAC1C,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,wBAAwB,CAAC,UAAU,CAAC;IAC5C,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,MAAM,CAClB,SAAsC,EACtC,WAAiD,EACjD,IAAQ,EACR,MAA4B;QAE5B,MAAM,CAAC,MAAM,CACZ,wBAAwB,CAAC,UAAU,eAEnC,SAAS,CACT,CAAC;QAEF,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;YACvB,KAAK,EAAE,MAAM;YACb,MAAM,EAAE,wBAAwB,CAAC,UAAU;YAC3C,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE;YACd,OAAO,EAAE,gBAAgB;YACzB,IAAI,EAAE;gBACL,QAAQ,EAAE,gBAAgB,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE;aAClD;SACD,CAAC,CAAC;QAEH,OAAO;YACN;gBACC,MAAM,EAAE,GAAG;gBACX,QAAQ,EAAE,cAAc,CAAC,OAAO;aAChC;SACD,CAAC;IACH,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ComponentFactory, Guards } from \"@twin.org/core\";\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tOdrlPolicyHelper,\n\tPolicyDecision,\n\ttype IPolicyArbiter,\n\ttype IPolicyDecision\n} from \"@twin.org/rights-management-models\";\nimport type { IDataspaceProtocolAgreement } from \"@twin.org/standards-dataspace-protocol\";\nimport type { ActionType } from \"@twin.org/standards-w3c-odrl\";\nimport type { IPassThroughPolicyArbiterConstructorOptions } from \"../models/IPassThroughPolicyArbiterConstructorOptions.js\";\n\n/**\n * Pass Through Policy Arbiter.\n */\nexport class PassThroughPolicyArbiter implements IPolicyArbiter {\n\t/**\n\t * The class name of the Pass Through Policy Arbiter.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<PassThroughPolicyArbiter>();\n\n\t/**\n\t * The logging component.\n\t * @internal\n\t */\n\tprivate readonly _logging: ILoggingComponent;\n\n\t/**\n\t * Create a new instance of PassThroughPolicyArbiter.\n\t * @param options The options for the pass through policy arbiter.\n\t */\n\tconstructor(options?: IPassThroughPolicyArbiterConstructorOptions) {\n\t\tthis._logging = ComponentFactory.get<ILoggingComponent>(\n\t\t\toptions?.loggingComponentType ?? \"logging\"\n\t\t);\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn PassThroughPolicyArbiter.CLASS_NAME;\n\t}\n\n\t/**\n\t * Makes decisions regarding policy access to data.\n\t * @param agreement The agreement to evaluate.\n\t * @param information Information provided by the requester to determine if a policy can be created.\n\t * @param data The data to make a decision on.\n\t * @param action Optional action to make a decision on, if not provided, the arbiter will evaluate all actions in the agreement.\n\t * @returns The decisions about access to the data.\n\t */\n\tpublic async decide<D = unknown>(\n\t\tagreement: IDataspaceProtocolAgreement,\n\t\tinformation?: { [id: string]: IJsonLdNodeObject },\n\t\tdata?: D,\n\t\taction?: ActionType | string\n\t): Promise<IPolicyDecision[]> {\n\t\tGuards.object<IDataspaceProtocolAgreement>(\n\t\t\tPassThroughPolicyArbiter.CLASS_NAME,\n\t\t\tnameof(agreement),\n\t\t\tagreement\n\t\t);\n\n\t\tawait this._logging.log({\n\t\t\tlevel: \"info\",\n\t\t\tsource: PassThroughPolicyArbiter.CLASS_NAME,\n\t\t\tts: Date.now(),\n\t\t\tmessage: \"decidingPolicy\",\n\t\t\tdata: {\n\t\t\t\tpolicyId: OdrlPolicyHelper.getUid(agreement) ?? \"\"\n\t\t\t}\n\t\t});\n\n\t\treturn [\n\t\t\t{\n\t\t\t\ttarget: \"$\",\n\t\t\t\tdecision: PolicyDecision.Granted\n\t\t\t}\n\t\t];\n\t}\n}\n"]}
1
+ {"version":3,"file":"passThroughPolicyArbiter.js","sourceRoot":"","sources":["../../../src/policyArbiters/passThroughPolicyArbiter.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAI1D,OAAO,EACN,gBAAgB,EAChB,cAAc,EAGd,MAAM,oCAAoC,CAAC;AAK5C;;GAEG;AACH,MAAM,OAAO,wBAAwB;IACpC;;OAEG;IACI,MAAM,CAAU,UAAU,8BAA8C;IAE/E;;;OAGG;IACc,QAAQ,CAAoB;IAE7C;;;OAGG;IACH,YAAY,OAAqD;QAChE,IAAI,CAAC,QAAQ,GAAG,gBAAgB,CAAC,GAAG,CACnC,OAAO,EAAE,oBAAoB,IAAI,SAAS,CAC1C,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,wBAAwB,CAAC,UAAU,CAAC;IAC5C,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,MAAM,CAClB,SAAsC,EACtC,WAAiD,EACjD,IAAQ,EACR,MAAgC;QAEhC,MAAM,CAAC,MAAM,CACZ,wBAAwB,CAAC,UAAU,eAEnC,SAAS,CACT,CAAC;QAEF,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;YACvB,KAAK,EAAE,MAAM;YACb,MAAM,EAAE,wBAAwB,CAAC,UAAU;YAC3C,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE;YACd,OAAO,EAAE,gBAAgB;YACzB,IAAI,EAAE;gBACL,QAAQ,EAAE,gBAAgB,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE;aAClD;SACD,CAAC,CAAC;QAEH,OAAO;YACN;gBACC,MAAM,EAAE,GAAG;gBACX,QAAQ,EAAE,cAAc,CAAC,OAAO;aAChC;SACD,CAAC;IACH,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ComponentFactory, Guards } from \"@twin.org/core\";\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tOdrlPolicyHelper,\n\tPolicyDecision,\n\ttype IPolicyArbiter,\n\ttype IPolicyDecision\n} from \"@twin.org/rights-management-models\";\nimport type { IDataspaceProtocolAgreement } from \"@twin.org/standards-dataspace-protocol\";\nimport type { OdrlActionType } from \"@twin.org/standards-w3c-odrl\";\nimport type { IPassThroughPolicyArbiterConstructorOptions } from \"../models/IPassThroughPolicyArbiterConstructorOptions.js\";\n\n/**\n * Pass Through Policy Arbiter.\n */\nexport class PassThroughPolicyArbiter implements IPolicyArbiter {\n\t/**\n\t * The class name of the Pass Through Policy Arbiter.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<PassThroughPolicyArbiter>();\n\n\t/**\n\t * The logging component.\n\t * @internal\n\t */\n\tprivate readonly _logging: ILoggingComponent;\n\n\t/**\n\t * Create a new instance of PassThroughPolicyArbiter.\n\t * @param options The options for the pass through policy arbiter.\n\t */\n\tconstructor(options?: IPassThroughPolicyArbiterConstructorOptions) {\n\t\tthis._logging = ComponentFactory.get<ILoggingComponent>(\n\t\t\toptions?.loggingComponentType ?? \"logging\"\n\t\t);\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn PassThroughPolicyArbiter.CLASS_NAME;\n\t}\n\n\t/**\n\t * Makes decisions regarding policy access to data.\n\t * @param agreement The agreement to evaluate.\n\t * @param information Information provided by the requester to determine if a policy can be created.\n\t * @param data The data to make a decision on.\n\t * @param action Optional action to make a decision on, if not provided, the arbiter will evaluate all actions in the agreement.\n\t * @returns The decisions about access to the data.\n\t */\n\tpublic async decide<D = unknown>(\n\t\tagreement: IDataspaceProtocolAgreement,\n\t\tinformation?: { [id: string]: IJsonLdNodeObject },\n\t\tdata?: D,\n\t\taction?: OdrlActionType | string\n\t): Promise<IPolicyDecision[]> {\n\t\tGuards.object<IDataspaceProtocolAgreement>(\n\t\t\tPassThroughPolicyArbiter.CLASS_NAME,\n\t\t\tnameof(agreement),\n\t\t\tagreement\n\t\t);\n\n\t\tawait this._logging.log({\n\t\t\tlevel: \"info\",\n\t\t\tsource: PassThroughPolicyArbiter.CLASS_NAME,\n\t\t\tts: Date.now(),\n\t\t\tmessage: \"decidingPolicy\",\n\t\t\tdata: {\n\t\t\t\tpolicyId: OdrlPolicyHelper.getUid(agreement) ?? \"\"\n\t\t\t}\n\t\t});\n\n\t\treturn [\n\t\t\t{\n\t\t\t\ttarget: \"$\",\n\t\t\t\tdecision: PolicyDecision.Granted\n\t\t\t}\n\t\t];\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"defaultPolicyEnforcementProcess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,CAAC,QAAQ,EAAE,cAAc,CAAC,YAAY,CAAC,CAAC;YAC1F,CAAC;QACF,CAAC;aAAM,CAAC;YACP,8FAA8F;YAC9F,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;YAC1E,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;gBAC9B,cAAc,CAAC,gBAAgB,CAAC,YAAY,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;YAChE,CAAC;QACF,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ComponentFactory, GeneralError, Guards, Is, ObjectHelper } from \"@twin.org/core\";\nimport { JsonPathHelper } from \"@twin.org/data-json-path\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tOdrlPolicyHelper,\n\tPolicyDecision,\n\ttype IPolicyDecision,\n\ttype IPolicyEnforcementProcessor\n} from \"@twin.org/rights-management-models\";\nimport type { IDataspaceProtocolAgreement } from \"@twin.org/standards-dataspace-protocol\";\nimport type { ActionType } from \"@twin.org/standards-w3c-odrl\";\nimport type { IDefaultPolicyEnforcementProcessorConstructorOptions } from \"../models/IDefaultPolicyEnforcementProcessorConstructorOptions.js\";\n\n/**\n * Default Policy Enforcement Processor.\n */\nexport class DefaultPolicyEnforcementProcessor implements IPolicyEnforcementProcessor {\n\t/**\n\t * The class name of the Default Policy Enforcement Processor.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<DefaultPolicyEnforcementProcessor>();\n\n\t/**\n\t * The logging component.\n\t * @internal\n\t */\n\tprivate readonly _logging: ILoggingComponent;\n\n\t/**\n\t * Create a new instance of DefaultPolicyEnforcementProcessor.\n\t * @param options The options for the default policy enforcement processor.\n\t */\n\tconstructor(options?: IDefaultPolicyEnforcementProcessorConstructorOptions) {\n\t\tthis._logging = ComponentFactory.get<ILoggingComponent>(\n\t\t\toptions?.loggingComponentType ?? \"logging\"\n\t\t);\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn DefaultPolicyEnforcementProcessor.CLASS_NAME;\n\t}\n\n\t/**\n\t * Process the response from the policy decision point.\n\t * @param agreement The agreement to process.\n\t * @param decisions The decisions made by the policy decision point.\n\t * @param data The data to process.\n\t * @param action Optional action to make a decision on, if not provided, the arbiter will evaluate all actions in the agreement.\n\t * @returns The data after processing.\n\t */\n\tpublic async process<D = unknown, R = D>(\n\t\tagreement: IDataspaceProtocolAgreement,\n\t\tdecisions: IPolicyDecision[],\n\t\tdata?: D,\n\t\taction?: ActionType | string\n\t): Promise<R> {\n\t\tGuards.object<IDataspaceProtocolAgreement>(\n\t\t\tDefaultPolicyEnforcementProcessor.CLASS_NAME,\n\t\t\tnameof(agreement),\n\t\t\tagreement\n\t\t);\n\n\t\tawait this._logging.log({\n\t\t\tlevel: \"info\",\n\t\t\tsource: DefaultPolicyEnforcementProcessor.CLASS_NAME,\n\t\t\tts: Date.now(),\n\t\t\tmessage: \"processingPolicy\",\n\t\t\tdata: {\n\t\t\t\tpolicyId: OdrlPolicyHelper.getUid(agreement) ?? \"\"\n\t\t\t}\n\t\t});\n\n\t\tconst isOriginalEmpty = Is.empty(data);\n\t\tconst outputObject: R = (Is.arrayValue(data) ? [] : {}) as unknown as R;\n\n\t\tif (Is.arrayValue(decisions)) {\n\t\t\t// If this is a single simple decision with no values, handle that quickly.\n\t\t\tif (decisions.length === 1 && decisions[0].target === \"$\") {\n\t\t\t\tif (!Is.stringValue(decisions[0].target)) {\n\t\t\t\t\tthrow new GeneralError(\n\t\t\t\t\t\tDefaultPolicyEnforcementProcessor.CLASS_NAME,\n\t\t\t\t\t\t\"targetNotJsonPath\",\n\t\t\t\t\t\t{ target: decisions[0].target }\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (decisions[0].decision === PolicyDecision.Granted) {\n\t\t\t\t\t// Object granted, if original data is an object return it, otherwise return true.\n\t\t\t\t\treturn isOriginalEmpty ? (true as R) : (data as unknown as R);\n\t\t\t\t} else if (\n\t\t\t\t\tdecisions[0].decision === PolicyDecision.Replace &&\n\t\t\t\t\tIs.object(decisions[0].replaceValue)\n\t\t\t\t) {\n\t\t\t\t\t// Object replaced, return the replace value.\n\t\t\t\t\treturn decisions[0].replaceValue as R;\n\t\t\t\t}\n\n\t\t\t\t// Object denied, or replace with no value\n\t\t\t\t// if original data is an object return empty object, otherwise return false.\n\t\t\t\treturn isOriginalEmpty ? (false as R) : ({} as unknown as R);\n\t\t\t}\n\n\t\t\tfor (const policyDecision of decisions) {\n\t\t\t\tif (!Is.stringValue(policyDecision.target)) {\n\t\t\t\t\tthrow new GeneralError(\n\t\t\t\t\t\tDefaultPolicyEnforcementProcessor.CLASS_NAME,\n\t\t\t\t\t\t\"targetNotJsonPath\",\n\t\t\t\t\t\t{ target: policyDecision.target }\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\tpolicyDecision.decision === PolicyDecision.Replace &&\n\t\t\t\t\tIs.undefined(policyDecision.replaceValue)\n\t\t\t\t) {\n\t\t\t\t\tthrow new GeneralError(\n\t\t\t\t\t\tDefaultPolicyEnforcementProcessor.CLASS_NAME,\n\t\t\t\t\t\t\"replaceValueMissing\",\n\t\t\t\t\t\t{ target: policyDecision.target }\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tthis.processDecision<D, R>(data, outputObject, policyDecision);\n\t\t\t}\n\t\t}\n\n\t\treturn outputObject;\n\t}\n\n\t/**\n\t * Process a single policy decision.\n\t * @param sourceObject The data to process.\n\t * @param outputObject The currently processed object.\n\t * @param policyDecision The policy decision to process.\n\t * @throws GeneralError When replaceValue is missing or invalid.\n\t */\n\tprivate processDecision<D = unknown, R = D>(\n\t\tsourceObject: D | undefined,\n\t\toutputObject: R,\n\t\tpolicyDecision: IPolicyDecision\n\t): void {\n\t\t// If the target is \"$\" assume we are using the entire source object.\n\t\tif (policyDecision.target === \"$\") {\n\t\t\tconst sourceKeys = Object.keys(sourceObject ?? {});\n\t\t\tconst outputKeys = Object.keys(outputObject ?? {});\n\n\t\t\tif (policyDecision.decision === PolicyDecision.Granted) {\n\t\t\t\tfor (const key of sourceKeys) {\n\t\t\t\t\tObjectHelper.propertySet(outputObject, key, ObjectHelper.propertyGet(sourceObject, key));\n\t\t\t\t}\n\t\t\t} else if (policyDecision.decision === PolicyDecision.Replace) {\n\t\t\t\t// Replace everything, first remove all the current keys.\n\t\t\t\tfor (const key of outputKeys) {\n\t\t\t\t\tObjectHelper.propertyDelete(outputObject, key);\n\t\t\t\t}\n\t\t\t\tif (Is.objectValue(policyDecision.replaceValue)) {\n\t\t\t\t\tconst replaceKeys = Object.keys(policyDecision.replaceValue);\n\t\t\t\t\tfor (const key of replaceKeys) {\n\t\t\t\t\t\tObjectHelper.propertySet(\n\t\t\t\t\t\t\toutputObject,\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\tObjectHelper.propertyGet(policyDecision.replaceValue, key)\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Denied everything, so remove all the properties.\n\t\t\t\tfor (const key of sourceKeys) {\n\t\t\t\t\tObjectHelper.propertyDelete(outputObject, key);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (policyDecision.decision === PolicyDecision.Granted) {\n\t\t\t// We have a specific granted target (JSONPath), so copy all matching values into the output.\n\t\t\tconst results = JsonPathHelper.query(policyDecision.target, sourceObject ?? {});\n\t\t\tfor (const result of results) {\n\t\t\t\tJsonPathHelper.setAtLocation(outputObject, result.location, result.value);\n\t\t\t}\n\t\t} else if (policyDecision.decision === PolicyDecision.Replace) {\n\t\t\t// We have a specific replace target (JSONPath), so write replaceValue into all matching locations.\n\t\t\tconst results = JsonPathHelper.query(policyDecision.target, sourceObject ?? {});\n\t\t\tfor (const result of results) {\n\t\t\t\tJsonPathHelper.setAtLocation(outputObject, result.location, policyDecision.replaceValue);\n\t\t\t}\n\t\t} else {\n\t\t\t// We have a specific denied target (JSONPath), so remove all matching values from the output.\n\t\t\tconst results = JsonPathHelper.query(policyDecision.target, outputObject);\n\t\t\tfor (const result of results) {\n\t\t\t\tJsonPathHelper.deleteAtLocation(outputObject, result.location);\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"defaultPolicyEnforcementProcessor.js","sourceRoot":"","sources":["../../../src/policyEnforcementProcessor/defaultPolicyEnforcementProcessor.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC1F,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG1D,OAAO,EACN,gBAAgB,EAChB,cAAc,EAGd,MAAM,oCAAoC,CAAC;AAK5C;;GAEG;AACH,MAAM,OAAO,iCAAiC;IAC7C;;OAEG;IACI,MAAM,CAAU,UAAU,uCAAuD;IAExF;;;OAGG;IACc,QAAQ,CAAoB;IAE7C;;;OAGG;IACH,YAAY,OAA8D;QACzE,IAAI,CAAC,QAAQ,GAAG,gBAAgB,CAAC,GAAG,CACnC,OAAO,EAAE,oBAAoB,IAAI,SAAS,CAC1C,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,iCAAiC,CAAC,UAAU,CAAC;IACrD,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,OAAO,CACnB,SAAsC,EACtC,SAA4B,EAC5B,IAAQ,EACR,MAAgC;QAEhC,MAAM,CAAC,MAAM,CACZ,iCAAiC,CAAC,UAAU,eAE5C,SAAS,CACT,CAAC;QAEF,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;YACvB,KAAK,EA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,CAAC,KAAK,CAAC,CAAC;YAC3E,CAAC;QACF,CAAC;aAAM,IAAI,cAAc,CAAC,QAAQ,KAAK,cAAc,CAAC,OAAO,EAAE,CAAC;YAC/D,mGAAmG;YACnG,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,EAAE,YAAY,IAAI,EAAE,CAAC,CAAC;YAChF,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;gBAC9B,cAAc,CAAC,aAAa,CAAC,YAAY,EAAE,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC,YAAY,CAAC,CAAC;YAC1F,CAAC;QACF,CAAC;aAAM,CAAC;YACP,8FAA8F;YAC9F,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;YAC1E,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;gBAC9B,cAAc,CAAC,gBAAgB,CAAC,YAAY,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;YAChE,CAAC;QACF,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ComponentFactory, GeneralError, Guards, Is, ObjectHelper } from \"@twin.org/core\";\nimport { JsonPathHelper } from \"@twin.org/data-json-path\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tOdrlPolicyHelper,\n\tPolicyDecision,\n\ttype IPolicyDecision,\n\ttype IPolicyEnforcementProcessor\n} from \"@twin.org/rights-management-models\";\nimport type { IDataspaceProtocolAgreement } from \"@twin.org/standards-dataspace-protocol\";\nimport type { OdrlActionType } from \"@twin.org/standards-w3c-odrl\";\nimport type { IDefaultPolicyEnforcementProcessorConstructorOptions } from \"../models/IDefaultPolicyEnforcementProcessorConstructorOptions.js\";\n\n/**\n * Default Policy Enforcement Processor.\n */\nexport class DefaultPolicyEnforcementProcessor implements IPolicyEnforcementProcessor {\n\t/**\n\t * The class name of the Default Policy Enforcement Processor.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<DefaultPolicyEnforcementProcessor>();\n\n\t/**\n\t * The logging component.\n\t * @internal\n\t */\n\tprivate readonly _logging: ILoggingComponent;\n\n\t/**\n\t * Create a new instance of DefaultPolicyEnforcementProcessor.\n\t * @param options The options for the default policy enforcement processor.\n\t */\n\tconstructor(options?: IDefaultPolicyEnforcementProcessorConstructorOptions) {\n\t\tthis._logging = ComponentFactory.get<ILoggingComponent>(\n\t\t\toptions?.loggingComponentType ?? \"logging\"\n\t\t);\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn DefaultPolicyEnforcementProcessor.CLASS_NAME;\n\t}\n\n\t/**\n\t * Process the response from the policy decision point.\n\t * @param agreement The agreement to process.\n\t * @param decisions The decisions made by the policy decision point.\n\t * @param data The data to process.\n\t * @param action Optional action to make a decision on, if not provided, the arbiter will evaluate all actions in the agreement.\n\t * @returns The data after processing.\n\t */\n\tpublic async process<D = unknown, R = D>(\n\t\tagreement: IDataspaceProtocolAgreement,\n\t\tdecisions: IPolicyDecision[],\n\t\tdata?: D,\n\t\taction?: OdrlActionType | string\n\t): Promise<R> {\n\t\tGuards.object<IDataspaceProtocolAgreement>(\n\t\t\tDefaultPolicyEnforcementProcessor.CLASS_NAME,\n\t\t\tnameof(agreement),\n\t\t\tagreement\n\t\t);\n\n\t\tawait this._logging.log({\n\t\t\tlevel: \"info\",\n\t\t\tsource: DefaultPolicyEnforcementProcessor.CLASS_NAME,\n\t\t\tts: Date.now(),\n\t\t\tmessage: \"processingPolicy\",\n\t\t\tdata: {\n\t\t\t\tpolicyId: OdrlPolicyHelper.getUid(agreement) ?? \"\"\n\t\t\t}\n\t\t});\n\n\t\tconst isOriginalEmpty = Is.empty(data);\n\t\tconst outputObject: R = (Is.arrayValue(data) ? [] : {}) as unknown as R;\n\n\t\tif (Is.arrayValue(decisions)) {\n\t\t\t// If this is a single simple decision with no values, handle that quickly.\n\t\t\tif (decisions.length === 1 && decisions[0].target === \"$\") {\n\t\t\t\tif (!Is.stringValue(decisions[0].target)) {\n\t\t\t\t\tthrow new GeneralError(\n\t\t\t\t\t\tDefaultPolicyEnforcementProcessor.CLASS_NAME,\n\t\t\t\t\t\t\"targetNotJsonPath\",\n\t\t\t\t\t\t{ target: decisions[0].target }\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (decisions[0].decision === PolicyDecision.Granted) {\n\t\t\t\t\t// Object granted, if original data is an object return it, otherwise return true.\n\t\t\t\t\treturn isOriginalEmpty ? (true as R) : (data as unknown as R);\n\t\t\t\t} else if (\n\t\t\t\t\tdecisions[0].decision === PolicyDecision.Replace &&\n\t\t\t\t\tIs.object(decisions[0].replaceValue)\n\t\t\t\t) {\n\t\t\t\t\t// Object replaced, return the replace value.\n\t\t\t\t\treturn decisions[0].replaceValue as R;\n\t\t\t\t}\n\n\t\t\t\t// Object denied, or replace with no value\n\t\t\t\t// if original data is an object return empty object, otherwise return false.\n\t\t\t\treturn isOriginalEmpty ? (false as R) : ({} as unknown as R);\n\t\t\t}\n\n\t\t\tfor (const policyDecision of decisions) {\n\t\t\t\tif (!Is.stringValue(policyDecision.target)) {\n\t\t\t\t\tthrow new GeneralError(\n\t\t\t\t\t\tDefaultPolicyEnforcementProcessor.CLASS_NAME,\n\t\t\t\t\t\t\"targetNotJsonPath\",\n\t\t\t\t\t\t{ target: policyDecision.target }\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif (\n\t\t\t\t\tpolicyDecision.decision === PolicyDecision.Replace &&\n\t\t\t\t\tIs.undefined(policyDecision.replaceValue)\n\t\t\t\t) {\n\t\t\t\t\tthrow new GeneralError(\n\t\t\t\t\t\tDefaultPolicyEnforcementProcessor.CLASS_NAME,\n\t\t\t\t\t\t\"replaceValueMissing\",\n\t\t\t\t\t\t{ target: policyDecision.target }\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tthis.processDecision<D, R>(data, outputObject, policyDecision);\n\t\t\t}\n\t\t}\n\n\t\treturn outputObject;\n\t}\n\n\t/**\n\t * Process a single policy decision.\n\t * @param sourceObject The data to process.\n\t * @param outputObject The currently processed object.\n\t * @param policyDecision The policy decision to process.\n\t * @throws GeneralError When replaceValue is missing or invalid.\n\t */\n\tprivate processDecision<D = unknown, R = D>(\n\t\tsourceObject: D | undefined,\n\t\toutputObject: R,\n\t\tpolicyDecision: IPolicyDecision\n\t): void {\n\t\t// If the target is \"$\" assume we are using the entire source object.\n\t\tif (policyDecision.target === \"$\") {\n\t\t\tconst sourceKeys = Object.keys(sourceObject ?? {});\n\t\t\tconst outputKeys = Object.keys(outputObject ?? {});\n\n\t\t\tif (policyDecision.decision === PolicyDecision.Granted) {\n\t\t\t\tfor (const key of sourceKeys) {\n\t\t\t\t\tObjectHelper.propertySet(outputObject, key, ObjectHelper.propertyGet(sourceObject, key));\n\t\t\t\t}\n\t\t\t} else if (policyDecision.decision === PolicyDecision.Replace) {\n\t\t\t\t// Replace everything, first remove all the current keys.\n\t\t\t\tfor (const key of outputKeys) {\n\t\t\t\t\tObjectHelper.propertyDelete(outputObject, key);\n\t\t\t\t}\n\t\t\t\tif (Is.objectValue(policyDecision.replaceValue)) {\n\t\t\t\t\tconst replaceKeys = Object.keys(policyDecision.replaceValue);\n\t\t\t\t\tfor (const key of replaceKeys) {\n\t\t\t\t\t\tObjectHelper.propertySet(\n\t\t\t\t\t\t\toutputObject,\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\tObjectHelper.propertyGet(policyDecision.replaceValue, key)\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Denied everything, so remove all the properties.\n\t\t\t\tfor (const key of sourceKeys) {\n\t\t\t\t\tObjectHelper.propertyDelete(outputObject, key);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (policyDecision.decision === PolicyDecision.Granted) {\n\t\t\t// We have a specific granted target (JSONPath), so copy all matching values into the output.\n\t\t\tconst results = JsonPathHelper.query(policyDecision.target, sourceObject ?? {});\n\t\t\tfor (const result of results) {\n\t\t\t\tJsonPathHelper.setAtLocation(outputObject, result.location, result.value);\n\t\t\t}\n\t\t} else if (policyDecision.decision === PolicyDecision.Replace) {\n\t\t\t// We have a specific replace target (JSONPath), so write replaceValue into all matching locations.\n\t\t\tconst results = JsonPathHelper.query(policyDecision.target, sourceObject ?? {});\n\t\t\tfor (const result of results) {\n\t\t\t\tJsonPathHelper.setAtLocation(outputObject, result.location, policyDecision.replaceValue);\n\t\t\t}\n\t\t} else {\n\t\t\t// We have a specific denied target (JSONPath), so remove all matching values from the output.\n\t\t\tconst results = JsonPathHelper.query(policyDecision.target, outputObject);\n\t\t\tfor (const result of results) {\n\t\t\t\tJsonPathHelper.deleteAtLocation(outputObject, result.location);\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"passThroughPolicyEnforcementProcessor.js","sourceRoot":"","sources":["../../../src/policyEnforcementProcessor/passThroughPolicyEnforcementProcessor.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAG1D,OAAO,EACN,gBAAgB,EAGhB,MAAM,oCAAoC,CAAC;AAK5C;;GAEG;AACH,MAAM,OAAO,qCAAqC;IACjD;;OAEG;IACI,MAAM,CAAU,UAAU,2CAA2D;IAE5F;;;OAGG;IACc,QAAQ,CAAoB;IAE7C;;;OAGG;IACH,YAAY,OAAkE;QAC7E,IAAI,CAAC,QAAQ,GAAG,gBAAgB,CAAC,GAAG,CACnC,OAAO,EAAE,oBAAoB,IAAI,SAAS,CAC1C,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,qCAAqC,CAAC,UAAU,CAAC;IACzD,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,OAAO,CACnB,SAAsC,EACtC,SAA4B,EAC5B,IAAQ,EACR,MAA4B;QAE5B,MAAM,CAAC,MAAM,CACZ,qCAAqC,CAAC,UAAU,eAEhD,SAAS,CACT,CAAC;QAEF,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;YACvB,KAAK,EAAE,MAAM;YACb,MAAM,EAAE,qCAAqC,CAAC,UAAU;YACxD,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE;YACd,OAAO,EAAE,kBAAkB;YAC3B,IAAI,EAAE;gBACL,QAAQ,EAAE,gBAAgB,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE;aAClD;SACD,CAAC,CAAC;QAEH,OAAO,IAAoB,CAAC;IAC7B,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ComponentFactory, Guards } from \"@twin.org/core\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tOdrlPolicyHelper,\n\ttype IPolicyDecision,\n\ttype IPolicyEnforcementProcessor\n} from \"@twin.org/rights-management-models\";\nimport type { IDataspaceProtocolAgreement } from \"@twin.org/standards-dataspace-protocol\";\nimport type { ActionType } from \"@twin.org/standards-w3c-odrl\";\nimport type { IPassThroughPolicyEnforcementProcessorConstructorOptions } from \"../models/IPassThroughPolicyEnforcementProcessorConstructorOptions.js\";\n\n/**\n * Pass Through Policy Enforcement Processor.\n */\nexport class PassThroughPolicyEnforcementProcessor implements IPolicyEnforcementProcessor {\n\t/**\n\t * The class name of the Pass Through Policy Enforcement Processor.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<PassThroughPolicyEnforcementProcessor>();\n\n\t/**\n\t * The logging component.\n\t * @internal\n\t */\n\tprivate readonly _logging: ILoggingComponent;\n\n\t/**\n\t * Create a new instance of PassThroughPolicyEnforcementProcessor.\n\t * @param options The options for the pass through policy enforcement processor.\n\t */\n\tconstructor(options?: IPassThroughPolicyEnforcementProcessorConstructorOptions) {\n\t\tthis._logging = ComponentFactory.get<ILoggingComponent>(\n\t\t\toptions?.loggingComponentType ?? \"logging\"\n\t\t);\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn PassThroughPolicyEnforcementProcessor.CLASS_NAME;\n\t}\n\n\t/**\n\t * Process the response from the policy decision point.\n\t * @param agreement The agreement to process.\n\t * @param decisions The decisions made by the policy decision point.\n\t * @param data The data to process.\n\t * @param action Optional action to make a decision on, if not provided, the arbiter will evaluate all actions in the agreement.\n\t * @returns The data after processing.\n\t */\n\tpublic async process<D = unknown, R = D>(\n\t\tagreement: IDataspaceProtocolAgreement,\n\t\tdecisions: IPolicyDecision[],\n\t\tdata?: D,\n\t\taction?: ActionType | string\n\t): Promise<R> {\n\t\tGuards.object<IDataspaceProtocolAgreement>(\n\t\t\tPassThroughPolicyEnforcementProcessor.CLASS_NAME,\n\t\t\tnameof(agreement),\n\t\t\tagreement\n\t\t);\n\n\t\tawait this._logging.log({\n\t\t\tlevel: \"info\",\n\t\t\tsource: PassThroughPolicyEnforcementProcessor.CLASS_NAME,\n\t\t\tts: Date.now(),\n\t\t\tmessage: \"processingPolicy\",\n\t\t\tdata: {\n\t\t\t\tpolicyId: OdrlPolicyHelper.getUid(agreement) ?? \"\"\n\t\t\t}\n\t\t});\n\n\t\treturn data as unknown as R;\n\t}\n}\n"]}
1
+ {"version":3,"file":"passThroughPolicyEnforcementProcessor.js","sourceRoot":"","sources":["../../../src/policyEnforcementProcessor/passThroughPolicyEnforcementProcessor.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAG1D,OAAO,EACN,gBAAgB,EAGhB,MAAM,oCAAoC,CAAC;AAK5C;;GAEG;AACH,MAAM,OAAO,qCAAqC;IACjD;;OAEG;IACI,MAAM,CAAU,UAAU,2CAA2D;IAE5F;;;OAGG;IACc,QAAQ,CAAoB;IAE7C;;;OAGG;IACH,YAAY,OAAkE;QAC7E,IAAI,CAAC,QAAQ,GAAG,gBAAgB,CAAC,GAAG,CACnC,OAAO,EAAE,oBAAoB,IAAI,SAAS,CAC1C,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,qCAAqC,CAAC,UAAU,CAAC;IACzD,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,OAAO,CACnB,SAAsC,EACtC,SAA4B,EAC5B,IAAQ,EACR,MAAgC;QAEhC,MAAM,CAAC,MAAM,CACZ,qCAAqC,CAAC,UAAU,eAEhD,SAAS,CACT,CAAC;QAEF,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;YACvB,KAAK,EAAE,MAAM;YACb,MAAM,EAAE,qCAAqC,CAAC,UAAU;YACxD,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE;YACd,OAAO,EAAE,kBAAkB;YAC3B,IAAI,EAAE;gBACL,QAAQ,EAAE,gBAAgB,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE;aAClD;SACD,CAAC,CAAC;QAEH,OAAO,IAAoB,CAAC;IAC7B,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ComponentFactory, Guards } from \"@twin.org/core\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tOdrlPolicyHelper,\n\ttype IPolicyDecision,\n\ttype IPolicyEnforcementProcessor\n} from \"@twin.org/rights-management-models\";\nimport type { IDataspaceProtocolAgreement } from \"@twin.org/standards-dataspace-protocol\";\nimport type { OdrlActionType } from \"@twin.org/standards-w3c-odrl\";\nimport type { IPassThroughPolicyEnforcementProcessorConstructorOptions } from \"../models/IPassThroughPolicyEnforcementProcessorConstructorOptions.js\";\n\n/**\n * Pass Through Policy Enforcement Processor.\n */\nexport class PassThroughPolicyEnforcementProcessor implements IPolicyEnforcementProcessor {\n\t/**\n\t * The class name of the Pass Through Policy Enforcement Processor.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<PassThroughPolicyEnforcementProcessor>();\n\n\t/**\n\t * The logging component.\n\t * @internal\n\t */\n\tprivate readonly _logging: ILoggingComponent;\n\n\t/**\n\t * Create a new instance of PassThroughPolicyEnforcementProcessor.\n\t * @param options The options for the pass through policy enforcement processor.\n\t */\n\tconstructor(options?: IPassThroughPolicyEnforcementProcessorConstructorOptions) {\n\t\tthis._logging = ComponentFactory.get<ILoggingComponent>(\n\t\t\toptions?.loggingComponentType ?? \"logging\"\n\t\t);\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn PassThroughPolicyEnforcementProcessor.CLASS_NAME;\n\t}\n\n\t/**\n\t * Process the response from the policy decision point.\n\t * @param agreement The agreement to process.\n\t * @param decisions The decisions made by the policy decision point.\n\t * @param data The data to process.\n\t * @param action Optional action to make a decision on, if not provided, the arbiter will evaluate all actions in the agreement.\n\t * @returns The data after processing.\n\t */\n\tpublic async process<D = unknown, R = D>(\n\t\tagreement: IDataspaceProtocolAgreement,\n\t\tdecisions: IPolicyDecision[],\n\t\tdata?: D,\n\t\taction?: OdrlActionType | string\n\t): Promise<R> {\n\t\tGuards.object<IDataspaceProtocolAgreement>(\n\t\t\tPassThroughPolicyEnforcementProcessor.CLASS_NAME,\n\t\t\tnameof(agreement),\n\t\t\tagreement\n\t\t);\n\n\t\tawait this._logging.log({\n\t\t\tlevel: \"info\",\n\t\t\tsource: PassThroughPolicyEnforcementProcessor.CLASS_NAME,\n\t\t\tts: Date.now(),\n\t\t\tmessage: \"processingPolicy\",\n\t\t\tdata: {\n\t\t\t\tpolicyId: OdrlPolicyHelper.getUid(agreement) ?? \"\"\n\t\t\t}\n\t\t});\n\n\t\treturn data as unknown as R;\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"loggingPolicyExecutionAction.js","sourceRoot":"","sources":["../../../src/policyExecutionActions/loggingPolicyExecutionAction.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAG9D,OAAO,EAGN,gBAAgB,EAChB,mBAAmB,EACnB,MAAM,oCAAoC,CAAC;AAK5C;;GAEG;AACH,MAAM,OAAO,4BAA4B;IACxC;;OAEG;IACI,MAAM,CAAU,UAAU,kCAAkD;IAEnF;;;OAGG;IACc,QAAQ,CAAoB;IAE7C;;;OAGG;IACc,OAAO,CAAwB;IAEhD;;OAEG;IACc,YAAY,CAAU;IAEvC;;OAEG;IACc,cAAc,CAAU;IAEzC;;OAEG;IACc,iBAAiB,CAAU;IAE5C;;;OAGG;IACH,YAAY,OAAyD;QACpE,IAAI,CAAC,QAAQ,GAAG,gBAAgB,CAAC,GAAG,CACnC,OAAO,EAAE,oBAAoB,IAAI,SAAS,CAC1C,CAAC;QAEF,IAAI,CAAC,OAAO,GAAG,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI;YACzC,mBAAmB,CAAC,MAAM;YAC1B,mBAAmB,CAAC,KAAK;SACzB,CAAC;QACF,IAAI,CAAC,YAAY,GAAG,OAAO,EAAE,MAAM,EAAE,WAAW,IAAI,KAAK,CAAC;QAC1D,IAAI,CAAC,cAAc,GAAG,OAAO,EAAE,MAAM,EAAE,aAAa,IAAI,KAAK,CAAC;QAC9D,IAAI,CAAC,iBAAiB,GAAG,OAAO,EAAE,MAAM,EAAE,gBAAgB,IAAI,KAAK,CAAC;IACrE,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,4BAA4B,CAAC,UAAU,CAAC;IAChD,CAAC;IAED;;;OAGG;IACI,eAAe;QACrB,OAAO,IA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,CAAC;gBACP,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;oBACvB,KAAK,EAAE,MAAM;oBACb,MAAM,EAAE,4BAA4B,CAAC,UAAU;oBAC/C,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE;oBACd,OAAO,EAAE,2BAA2B;oBACpC,IAAI,EAAE;wBACL,QAAQ,EAAE,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;wBAC/C,IAAI,EAAE,OAAO;wBACb,MAAM,EAAE,SAAS;wBACjB,SAAS,EAAE,YAAY;wBACvB,MAAM;wBACN,KAAK;qBACL;iBACD,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ComponentFactory, Guards, Is } from \"@twin.org/core\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\ttype IPolicyDecision,\n\ttype IPolicyExecutionAction,\n\tOdrlPolicyHelper,\n\tPolicyDecisionStage\n} from \"@twin.org/rights-management-models\";\nimport type { IDataspaceProtocolPolicy } from \"@twin.org/standards-dataspace-protocol\";\nimport type { ActionType } from \"@twin.org/standards-w3c-odrl\";\nimport type { ILoggingPolicyExecutionActionConstructorOptions } from \"../models/ILoggingPolicyExecutionActionConstructorOptions.js\";\n\n/**\n * Logging Policy Execution Action to send decisions to logging.\n */\nexport class LoggingPolicyExecutionAction implements IPolicyExecutionAction {\n\t/**\n\t * The class name of the Logging Policy Execution Action.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<LoggingPolicyExecutionAction>();\n\n\t/**\n\t * The logging component.\n\t * @internal\n\t */\n\tprivate readonly _logging: ILoggingComponent;\n\n\t/**\n\t * The policy decision stages to log, if undefined defaults to all.\n\t * @internal\n\t */\n\tprivate readonly _stages: PolicyDecisionStage[];\n\n\t/**\n\t * Whether to include the data in the log.\n\t */\n\tprivate readonly _includeData: boolean;\n\n\t/**\n\t * Whether to include the policy in the log.\n\t */\n\tprivate readonly _includePolicy: boolean;\n\n\t/**\n\t * Whether to include the decisions in the log.\n\t */\n\tprivate readonly _includeDecisions: boolean;\n\n\t/**\n\t * Create a new instance of LoggingPolicyExecutionAction.\n\t * @param options The options for the logging policy execution action.\n\t */\n\tconstructor(options?: ILoggingPolicyExecutionActionConstructorOptions) {\n\t\tthis._logging = ComponentFactory.get<ILoggingComponent>(\n\t\t\toptions?.loggingComponentType ?? \"logging\"\n\t\t);\n\n\t\tthis._stages = options?.config?.stages ?? [\n\t\t\tPolicyDecisionStage.Before,\n\t\t\tPolicyDecisionStage.After\n\t\t];\n\t\tthis._includeData = options?.config?.includeData ?? false;\n\t\tthis._includePolicy = options?.config?.includePolicy ?? false;\n\t\tthis._includeDecisions = options?.config?.includeDecisions ?? false;\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn LoggingPolicyExecutionAction.CLASS_NAME;\n\t}\n\n\t/**\n\t * Which stages should the action be executed at.\n\t * @returns List of stages.\n\t */\n\tpublic supportedStages(): PolicyDecisionStage[] {\n\t\treturn this._stages;\n\t}\n\n\t/**\n\t * Execute function type for policy actions.\n\t * @param policy The policy that applied to the data.\n\t * @param decisions The decisions made by the PDP.\n\t * @param data The data to process.\n\t * @param action Optional action to make a decision on, if not provided, the arbiter will evaluate all actions in the agreement.\n\t * @param stage The stage of the policy decision.\n\t * @returns A promise that resolves when the action is complete.\n\t */\n\tpublic async execute<D = unknown>(\n\t\tpolicy: IDataspaceProtocolPolicy,\n\t\tdecisions: IPolicyDecision[],\n\t\tdata: D | undefined,\n\t\taction: ActionType | string,\n\t\tstage: PolicyDecisionStage\n\t): Promise<void> {\n\t\tGuards.arrayOneOf(\n\t\t\tLoggingPolicyExecutionAction.CLASS_NAME,\n\t\t\tnameof(stage),\n\t\t\tstage,\n\t\t\tObject.values(PolicyDecisionStage)\n\t\t);\n\n\t\tif (this._stages.includes(stage)) {\n\t\t\t// Even if we don't have the options to include data or include policy we\n\t\t\t// still create dummy entries, as the logging string still has them embedded\n\t\t\tlet logData;\n\t\t\tif (!Is.empty(data)) {\n\t\t\t\tlogData = this._includeData ? data : \"{...}\";\n\t\t\t}\n\t\t\tconst logPolicy = this._includePolicy ? policy : \"{}\";\n\t\t\tconst logDecisions = this._includeDecisions ? decisions : \"[...]\";\n\n\t\t\tif (stage === PolicyDecisionStage.Before) {\n\t\t\t\tawait this._logging.log({\n\t\t\t\t\tlevel: \"info\",\n\t\t\t\t\tsource: LoggingPolicyExecutionAction.CLASS_NAME,\n\t\t\t\t\tts: Date.now(),\n\t\t\t\t\tmessage: \"policyActionExecutedBefore\",\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tpolicyId: OdrlPolicyHelper.getUid(policy) ?? \"\",\n\t\t\t\t\t\tdata: logData,\n\t\t\t\t\t\tpolicy: logPolicy,\n\t\t\t\t\t\tdecisions: logDecisions,\n\t\t\t\t\t\taction,\n\t\t\t\t\t\tstage\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tawait this._logging.log({\n\t\t\t\t\tlevel: \"info\",\n\t\t\t\t\tsource: LoggingPolicyExecutionAction.CLASS_NAME,\n\t\t\t\t\tts: Date.now(),\n\t\t\t\t\tmessage: \"policyActionExecutedAfter\",\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tpolicyId: OdrlPolicyHelper.getUid(policy) ?? \"\",\n\t\t\t\t\t\tdata: logData,\n\t\t\t\t\t\tpolicy: logPolicy,\n\t\t\t\t\t\tdecisions: logDecisions,\n\t\t\t\t\t\taction,\n\t\t\t\t\t\tstage\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"loggingPolicyExecutionAction.js","sourceRoot":"","sources":["../../../src/policyExecutionActions/loggingPolicyExecutionAction.ts"],"names":[],"mappings":"AAA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AAE,2BAA2B;oBACpC,IAAI,EAAE;wBACL,QAAQ,EAAE,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;wBAC/C,IAAI,EAAE,OAAO;wBACb,MAAM,EAAE,SAAS;wBACjB,SAAS,EAAE,YAAY;wBACvB,MAAM;wBACN,KAAK;qBACL;iBACD,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ComponentFactory, Guards, Is } from \"@twin.org/core\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\ttype IPolicyDecision,\n\ttype IPolicyExecutionAction,\n\tOdrlPolicyHelper,\n\tPolicyDecisionStage\n} from \"@twin.org/rights-management-models\";\nimport type { IDataspaceProtocolPolicy } from \"@twin.org/standards-dataspace-protocol\";\nimport type { OdrlActionType } from \"@twin.org/standards-w3c-odrl\";\nimport type { ILoggingPolicyExecutionActionConstructorOptions } from \"../models/ILoggingPolicyExecutionActionConstructorOptions.js\";\n\n/**\n * Logging Policy Execution Action to send decisions to logging.\n */\nexport class LoggingPolicyExecutionAction implements IPolicyExecutionAction {\n\t/**\n\t * The class name of the Logging Policy Execution Action.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<LoggingPolicyExecutionAction>();\n\n\t/**\n\t * The logging component.\n\t * @internal\n\t */\n\tprivate readonly _logging: ILoggingComponent;\n\n\t/**\n\t * The policy decision stages to log, if undefined defaults to all.\n\t * @internal\n\t */\n\tprivate readonly _stages: PolicyDecisionStage[];\n\n\t/**\n\t * Whether to include the data in the log.\n\t */\n\tprivate readonly _includeData: boolean;\n\n\t/**\n\t * Whether to include the policy in the log.\n\t */\n\tprivate readonly _includePolicy: boolean;\n\n\t/**\n\t * Whether to include the decisions in the log.\n\t */\n\tprivate readonly _includeDecisions: boolean;\n\n\t/**\n\t * Create a new instance of LoggingPolicyExecutionAction.\n\t * @param options The options for the logging policy execution action.\n\t */\n\tconstructor(options?: ILoggingPolicyExecutionActionConstructorOptions) {\n\t\tthis._logging = ComponentFactory.get<ILoggingComponent>(\n\t\t\toptions?.loggingComponentType ?? \"logging\"\n\t\t);\n\n\t\tthis._stages = options?.config?.stages ?? [\n\t\t\tPolicyDecisionStage.Before,\n\t\t\tPolicyDecisionStage.After\n\t\t];\n\t\tthis._includeData = options?.config?.includeData ?? false;\n\t\tthis._includePolicy = options?.config?.includePolicy ?? false;\n\t\tthis._includeDecisions = options?.config?.includeDecisions ?? false;\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn LoggingPolicyExecutionAction.CLASS_NAME;\n\t}\n\n\t/**\n\t * Which stages should the action be executed at.\n\t * @returns List of stages.\n\t */\n\tpublic supportedStages(): PolicyDecisionStage[] {\n\t\treturn this._stages;\n\t}\n\n\t/**\n\t * Execute function type for policy actions.\n\t * @param policy The policy that applied to the data.\n\t * @param decisions The decisions made by the PDP.\n\t * @param data The data to process.\n\t * @param action Optional action to make a decision on, if not provided, the arbiter will evaluate all actions in the agreement.\n\t * @param stage The stage of the policy decision.\n\t * @returns A promise that resolves when the action is complete.\n\t */\n\tpublic async execute<D = unknown>(\n\t\tpolicy: IDataspaceProtocolPolicy,\n\t\tdecisions: IPolicyDecision[],\n\t\tdata: D | undefined,\n\t\taction: OdrlActionType | string,\n\t\tstage: PolicyDecisionStage\n\t): Promise<void> {\n\t\tGuards.arrayOneOf(\n\t\t\tLoggingPolicyExecutionAction.CLASS_NAME,\n\t\t\tnameof(stage),\n\t\t\tstage,\n\t\t\tObject.values(PolicyDecisionStage)\n\t\t);\n\n\t\tif (this._stages.includes(stage)) {\n\t\t\t// Even if we don't have the options to include data or include policy we\n\t\t\t// still create dummy entries, as the logging string still has them embedded\n\t\t\tlet logData;\n\t\t\tif (!Is.empty(data)) {\n\t\t\t\tlogData = this._includeData ? data : \"{...}\";\n\t\t\t}\n\t\t\tconst logPolicy = this._includePolicy ? policy : \"{}\";\n\t\t\tconst logDecisions = this._includeDecisions ? decisions : \"[...]\";\n\n\t\t\tif (stage === PolicyDecisionStage.Before) {\n\t\t\t\tawait this._logging.log({\n\t\t\t\t\tlevel: \"info\",\n\t\t\t\t\tsource: LoggingPolicyExecutionAction.CLASS_NAME,\n\t\t\t\t\tts: Date.now(),\n\t\t\t\t\tmessage: \"policyActionExecutedBefore\",\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tpolicyId: OdrlPolicyHelper.getUid(policy) ?? \"\",\n\t\t\t\t\t\tdata: logData,\n\t\t\t\t\t\tpolicy: logPolicy,\n\t\t\t\t\t\tdecisions: logDecisions,\n\t\t\t\t\t\taction,\n\t\t\t\t\t\tstage\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tawait this._logging.log({\n\t\t\t\t\tlevel: \"info\",\n\t\t\t\t\tsource: LoggingPolicyExecutionAction.CLASS_NAME,\n\t\t\t\t\tts: Date.now(),\n\t\t\t\t\tmessage: \"policyActionExecutedAfter\",\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tpolicyId: OdrlPolicyHelper.getUid(policy) ?? \"\",\n\t\t\t\t\t\tdata: logData,\n\t\t\t\t\t\tpolicy: logPolicy,\n\t\t\t\t\t\tdecisions: logDecisions,\n\t\t\t\t\t\taction,\n\t\t\t\t\t\tstage\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n}\n"]}