@twin.org/rights-management-plugins 0.0.3-next.4 → 0.0.3-next.41

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 (131) hide show
  1. package/README.md +11 -3
  2. package/dist/es/index.js +18 -10
  3. package/dist/es/index.js.map +1 -1
  4. package/dist/es/models/IAutomationPolicyExecutionActionConfig.js +4 -0
  5. package/dist/es/models/IAutomationPolicyExecutionActionConfig.js.map +1 -0
  6. package/dist/es/models/IAutomationPolicyExecutionActionConstructorOptions.js +2 -0
  7. package/dist/es/models/IAutomationPolicyExecutionActionConstructorOptions.js.map +1 -0
  8. package/dist/es/models/{IExamplePolicyArbiterConstructorOptions.js → IDefaultPolicyArbiterConfig.js} +1 -1
  9. package/dist/es/models/IDefaultPolicyArbiterConfig.js.map +1 -0
  10. package/dist/es/models/{IExamplePolicyRequesterConstructorOptions.js → IDefaultPolicyArbiterConstructorOptions.js} +1 -1
  11. package/dist/es/models/IDefaultPolicyArbiterConstructorOptions.js.map +1 -0
  12. package/dist/es/models/{IExamplePolicyEnforcementProcessorConstructorOptions.js → IDefaultPolicyEnforcementProcessorConstructorOptions.js} +1 -1
  13. package/dist/es/models/IDefaultPolicyEnforcementProcessorConstructorOptions.js.map +1 -0
  14. package/dist/es/models/ILoggingPolicyExecutionActionConfig.js.map +1 -1
  15. package/dist/es/models/{IExampleDataAccessHandlerConstructorOptions.js → IPassThroughPolicyArbiterConstructorOptions.js} +1 -1
  16. package/dist/es/models/IPassThroughPolicyArbiterConstructorOptions.js.map +1 -0
  17. package/dist/es/models/IPassThroughPolicyEnforcementProcessorConstructorOptions.js +4 -0
  18. package/dist/es/models/IPassThroughPolicyEnforcementProcessorConstructorOptions.js.map +1 -0
  19. package/dist/es/models/IPassThroughPolicyNegotiatorConstructorOptions.js +4 -0
  20. package/dist/es/models/IPassThroughPolicyNegotiatorConstructorOptions.js.map +1 -0
  21. package/dist/es/models/IPassThroughPolicyObligationEnforcerConstructorOptions.js +4 -0
  22. package/dist/es/models/IPassThroughPolicyObligationEnforcerConstructorOptions.js.map +1 -0
  23. package/dist/es/models/{IExamplePolicyNegotiatorConstructorOptions.js → IPassThroughPolicyRequesterConstructorOptions.js} +1 -1
  24. package/dist/es/models/IPassThroughPolicyRequesterConstructorOptions.js.map +1 -0
  25. package/dist/es/models/IStaticPolicyInformationSource.js.map +1 -1
  26. package/dist/es/policyArbiters/defaultPolicyArbiter.js +1657 -0
  27. package/dist/es/policyArbiters/defaultPolicyArbiter.js.map +1 -0
  28. package/dist/es/policyArbiters/passThroughPolicyArbiter.js +59 -0
  29. package/dist/es/policyArbiters/passThroughPolicyArbiter.js.map +1 -0
  30. package/dist/es/policyEnforcementProcessor/defaultPolicyEnforcementProcessor.js +146 -0
  31. package/dist/es/policyEnforcementProcessor/defaultPolicyEnforcementProcessor.js.map +1 -0
  32. package/dist/es/policyEnforcementProcessor/passThroughPolicyEnforcementProcessor.js +54 -0
  33. package/dist/es/policyEnforcementProcessor/passThroughPolicyEnforcementProcessor.js.map +1 -0
  34. package/dist/es/policyExecutionActions/automationPolicyExecutionAction.js +76 -0
  35. package/dist/es/policyExecutionActions/automationPolicyExecutionAction.js.map +1 -0
  36. package/dist/es/policyExecutionActions/loggingPolicyExecutionAction.js +16 -15
  37. package/dist/es/policyExecutionActions/loggingPolicyExecutionAction.js.map +1 -1
  38. package/dist/es/policyInformationSources/identityPolicyInformationSource.js +43 -31
  39. package/dist/es/policyInformationSources/identityPolicyInformationSource.js.map +1 -1
  40. package/dist/es/policyInformationSources/staticPolicyInformationSource.js +17 -15
  41. package/dist/es/policyInformationSources/staticPolicyInformationSource.js.map +1 -1
  42. package/dist/es/policyNegotiators/passThroughPolicyNegotiator.js +88 -0
  43. package/dist/es/policyNegotiators/passThroughPolicyNegotiator.js.map +1 -0
  44. package/dist/es/policyObligationEnforcers/passThroughPolicyObligationEnforcer.js +56 -0
  45. package/dist/es/policyObligationEnforcers/passThroughPolicyObligationEnforcer.js.map +1 -0
  46. package/dist/es/policyRequesters/passThroughPolicyRequester.js +103 -0
  47. package/dist/es/policyRequesters/passThroughPolicyRequester.js.map +1 -0
  48. package/dist/types/index.d.ts +18 -10
  49. package/dist/types/models/IAutomationPolicyExecutionActionConfig.d.ts +9 -0
  50. package/dist/types/models/IAutomationPolicyExecutionActionConstructorOptions.d.ts +15 -0
  51. package/dist/types/models/IDefaultPolicyArbiterConfig.d.ts +10 -0
  52. package/dist/types/models/IDefaultPolicyArbiterConstructorOptions.d.ts +20 -0
  53. package/dist/types/models/{IExamplePolicyEnforcementProcessorConstructorOptions.d.ts → IDefaultPolicyEnforcementProcessorConstructorOptions.d.ts} +2 -2
  54. package/dist/types/models/ILoggingPolicyExecutionActionConfig.d.ts +2 -2
  55. package/dist/types/models/{IExamplePolicyArbiterConstructorOptions.d.ts → IPassThroughPolicyArbiterConstructorOptions.d.ts} +2 -2
  56. package/dist/types/models/IPassThroughPolicyEnforcementProcessorConstructorOptions.d.ts +10 -0
  57. package/dist/types/models/{IExamplePolicyNegotiatorConstructorOptions.d.ts → IPassThroughPolicyNegotiatorConstructorOptions.d.ts} +2 -2
  58. package/dist/types/models/IPassThroughPolicyObligationEnforcerConstructorOptions.d.ts +10 -0
  59. package/dist/types/models/{IExamplePolicyRequesterConstructorOptions.d.ts → IPassThroughPolicyRequesterConstructorOptions.d.ts} +2 -2
  60. package/dist/types/models/IStaticPolicyInformationSource.d.ts +10 -4
  61. package/dist/types/policyArbiters/defaultPolicyArbiter.d.ts +41 -0
  62. package/dist/types/policyArbiters/passThroughPolicyArbiter.d.ts +35 -0
  63. package/dist/types/policyEnforcementProcessor/defaultPolicyEnforcementProcessor.d.ts +40 -0
  64. package/dist/types/policyEnforcementProcessor/passThroughPolicyEnforcementProcessor.d.ts +32 -0
  65. package/dist/types/policyExecutionActions/automationPolicyExecutionAction.d.ts +49 -0
  66. package/dist/types/policyExecutionActions/loggingPolicyExecutionAction.d.ts +8 -8
  67. package/dist/types/policyInformationSources/identityPolicyInformationSource.d.ts +8 -6
  68. package/dist/types/policyInformationSources/staticPolicyInformationSource.d.ts +7 -5
  69. package/dist/types/policyNegotiators/passThroughPolicyNegotiator.d.ts +52 -0
  70. package/dist/types/policyObligationEnforcers/passThroughPolicyObligationEnforcer.d.ts +35 -0
  71. package/dist/types/policyRequesters/{examplePolicyRequester.d.ts → passThroughPolicyRequester.d.ts} +15 -20
  72. package/docs/changelog.md +835 -3
  73. package/docs/examples.md +295 -1
  74. package/docs/reference/classes/AutomationPolicyExecutionAction.md +143 -0
  75. package/docs/reference/classes/DefaultPolicyArbiter.md +111 -0
  76. package/docs/reference/classes/DefaultPolicyEnforcementProcessor.md +107 -0
  77. package/docs/reference/classes/IdentityPolicyInformationSource.md +14 -14
  78. package/docs/reference/classes/LoggingPolicyExecutionAction.md +20 -20
  79. package/docs/reference/classes/PassThroughPolicyArbiter.md +101 -0
  80. package/docs/reference/classes/PassThroughPolicyEnforcementProcessor.md +107 -0
  81. package/docs/reference/classes/{ExamplePolicyNegotiator.md → PassThroughPolicyNegotiator.md} +24 -22
  82. package/docs/reference/classes/PassThroughPolicyObligationEnforcer.md +107 -0
  83. package/docs/reference/classes/{ExamplePolicyRequester.md → PassThroughPolicyRequester.md} +20 -38
  84. package/docs/reference/classes/StaticPolicyInformationSource.md +15 -15
  85. package/docs/reference/index.md +18 -10
  86. package/docs/reference/interfaces/IAutomationPolicyExecutionActionConfig.md +11 -0
  87. package/docs/reference/interfaces/IAutomationPolicyExecutionActionConstructorOptions.md +25 -0
  88. package/docs/reference/interfaces/IDefaultPolicyArbiterConfig.md +17 -0
  89. package/docs/reference/interfaces/IDefaultPolicyArbiterConstructorOptions.md +39 -0
  90. package/docs/reference/interfaces/IDefaultPolicyEnforcementProcessorConstructorOptions.md +17 -0
  91. package/docs/reference/interfaces/IIdentityPolicyInformationSourceConstructorOptions.md +4 -4
  92. package/docs/reference/interfaces/ILoggingPolicyExecutionActionConfig.md +9 -9
  93. package/docs/reference/interfaces/ILoggingPolicyExecutionActionConstructorOptions.md +4 -4
  94. package/docs/reference/interfaces/IPassThroughPolicyArbiterConstructorOptions.md +17 -0
  95. package/docs/reference/interfaces/IPassThroughPolicyEnforcementProcessorConstructorOptions.md +17 -0
  96. package/docs/reference/interfaces/IPassThroughPolicyNegotiatorConstructorOptions.md +17 -0
  97. package/docs/reference/interfaces/IPassThroughPolicyObligationEnforcerConstructorOptions.md +17 -0
  98. package/docs/reference/interfaces/IPassThroughPolicyRequesterConstructorOptions.md +17 -0
  99. package/docs/reference/interfaces/IStaticPolicyInformationSource.md +25 -6
  100. package/docs/reference/interfaces/IStaticPolicyInformationSourceConfig.md +2 -2
  101. package/docs/reference/interfaces/IStaticPolicyInformationSourceConstructorOptions.md +4 -4
  102. package/locales/en.json +58 -6
  103. package/package.json +7 -5
  104. package/dist/es/dataAccessHandlers/examplePolicyRequester.js +0 -82
  105. package/dist/es/dataAccessHandlers/examplePolicyRequester.js.map +0 -1
  106. package/dist/es/models/IExampleDataAccessHandlerConstructorOptions.js.map +0 -1
  107. package/dist/es/models/IExamplePolicyArbiterConstructorOptions.js.map +0 -1
  108. package/dist/es/models/IExamplePolicyEnforcementProcessorConstructorOptions.js.map +0 -1
  109. package/dist/es/models/IExamplePolicyNegotiatorConstructorOptions.js.map +0 -1
  110. package/dist/es/models/IExamplePolicyRequesterConstructorOptions.js.map +0 -1
  111. package/dist/es/policyArbiters/examplePolicyArbiter.js +0 -50
  112. package/dist/es/policyArbiters/examplePolicyArbiter.js.map +0 -1
  113. package/dist/es/policyEnforcementProcessor/examplePolicyEnforcementProcessor.js +0 -42
  114. package/dist/es/policyEnforcementProcessor/examplePolicyEnforcementProcessor.js.map +0 -1
  115. package/dist/es/policyNegotiators/examplePolicyNegotiator.js +0 -61
  116. package/dist/es/policyNegotiators/examplePolicyNegotiator.js.map +0 -1
  117. package/dist/es/policyRequesters/examplePolicyRequester.js +0 -69
  118. package/dist/es/policyRequesters/examplePolicyRequester.js.map +0 -1
  119. package/dist/types/dataAccessHandlers/examplePolicyRequester.d.ts +0 -68
  120. package/dist/types/models/IExampleDataAccessHandlerConstructorOptions.d.ts +0 -10
  121. package/dist/types/policyArbiters/examplePolicyArbiter.d.ts +0 -36
  122. package/dist/types/policyEnforcementProcessor/examplePolicyEnforcementProcessor.d.ts +0 -29
  123. package/dist/types/policyNegotiators/examplePolicyNegotiator.d.ts +0 -45
  124. package/docs/reference/classes/ExampleDataAccessHandler.md +0 -243
  125. package/docs/reference/classes/ExamplePolicyArbiter.md +0 -121
  126. package/docs/reference/classes/ExamplePolicyEnforcementProcessor.md +0 -101
  127. package/docs/reference/interfaces/IExampleDataAccessHandlerConstructorOptions.md +0 -17
  128. package/docs/reference/interfaces/IExamplePolicyArbiterConstructorOptions.md +0 -17
  129. package/docs/reference/interfaces/IExamplePolicyEnforcementProcessorConstructorOptions.md +0 -17
  130. package/docs/reference/interfaces/IExamplePolicyNegotiatorConstructorOptions.md +0 -17
  131. package/docs/reference/interfaces/IExamplePolicyRequesterConstructorOptions.md +0 -17
@@ -0,0 +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,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"]}
@@ -0,0 +1,76 @@
1
+ import { ComponentFactory, Guards, Is } from "@twin.org/core";
2
+ import { PolicyDecisionStage } from "@twin.org/rights-management-models";
3
+ import { OdrlActionType } from "@twin.org/standards-w3c-odrl";
4
+ /**
5
+ * Automation Policy Execution Action to execute automation policies.
6
+ */
7
+ export class AutomationPolicyExecutionAction {
8
+ /**
9
+ * The class name of the Automation Policy Execution Action.
10
+ */
11
+ static CLASS_NAME = "AutomationPolicyExecutionAction";
12
+ /**
13
+ * The before automation trigger name.
14
+ */
15
+ static BEFORE_TRIGGER_NAME = "rights-management:pxp:before";
16
+ /**
17
+ * The after automation trigger name.
18
+ */
19
+ static AFTER_TRIGGER_NAME = "rights-management:pxp:after";
20
+ /**
21
+ * The automation component.
22
+ * @internal
23
+ */
24
+ _automation;
25
+ /**
26
+ * The policy decision stages to trigger the automation actions, if undefined defaults to "inform".
27
+ */
28
+ _triggerActions;
29
+ /**
30
+ * Create a new instance of AutomationPolicyExecutionAction.
31
+ * @param options The options for the automation policy execution action.
32
+ */
33
+ constructor(options) {
34
+ this._automation = ComponentFactory.get(options?.automationComponentType ?? "automation");
35
+ this._triggerActions = Is.arrayValue(options?.config?.triggerActions)
36
+ ? options?.config?.triggerActions
37
+ : [OdrlActionType.Inform];
38
+ }
39
+ /**
40
+ * Returns the class name of the component.
41
+ * @returns The class name of the component.
42
+ */
43
+ className() {
44
+ return AutomationPolicyExecutionAction.CLASS_NAME;
45
+ }
46
+ /**
47
+ * Which stages should the action be executed at.
48
+ * @returns List of stages.
49
+ */
50
+ supportedStages() {
51
+ return [PolicyDecisionStage.Before, PolicyDecisionStage.After];
52
+ }
53
+ /**
54
+ * Execute function type for policy actions.
55
+ * @param policy The policy that applied to the data.
56
+ * @param decisions The decisions made by the PDP.
57
+ * @param data The data to process.
58
+ * @param action Optional action to make a decision on, if not provided, the arbiter will evaluate all actions in the agreement.
59
+ * @param stage The stage of the policy decision.
60
+ * @returns A promise that resolves when the action is complete.
61
+ */
62
+ async execute(policy, decisions, data, action, stage) {
63
+ Guards.arrayOneOf(AutomationPolicyExecutionAction.CLASS_NAME, "stage", stage, Object.values(PolicyDecisionStage));
64
+ if (Is.stringValue(action) && this._triggerActions.includes(action)) {
65
+ await this._automation.trigger(stage === PolicyDecisionStage.Before
66
+ ? AutomationPolicyExecutionAction.BEFORE_TRIGGER_NAME
67
+ : AutomationPolicyExecutionAction.AFTER_TRIGGER_NAME, {
68
+ policy,
69
+ decisions,
70
+ data,
71
+ action
72
+ });
73
+ }
74
+ }
75
+ }
76
+ //# sourceMappingURL=automationPolicyExecutionAction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"automationPolicyExecutionAction.js","sourceRoot":"","sources":["../../../src/policyExecutionActions/automationPolicyExecutionAction.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAE9D,OAAO,EAIN,mBAAmB,EACnB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG9D;;GAEG;AACH,MAAM,OAAO,+BAA+B;IAC3C;;OAEG;IACI,MAAM,CAAU,UAAU,qCAAqD;IAEtF;;OAEG;IACI,MAAM,CAAU,mBAAmB,GAAW,8BAA8B,CAAC;IAEpF;;OAEG;IACI,MAAM,CAAU,kBAAkB,GAAW,6BAA6B,CAAC;IAElF;;;OAGG;IACc,WAAW,CAAuB;IAEnD;;OAEG;IACc,eAAe,CAAW;IAE3C;;;OAGG;IACH,YAAY,OAA4D;QACvE,IAAI,CAAC,WAAW,GAAG,gBAAgB,CAAC,GAAG,CACtC,OAAO,EAAE,uBAAuB,IAAI,YAAY,CAChD,CAAC;QACF,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,CAAC;YACpE,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc;YACjC,CAAC,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,+BAA+B,CAAC,UAAU,CAAC;IACnD,CAAC;IAED;;;OAGG;IACI,eAAe;QACrB,OAAO,CAAC,mBAAmB,CAAC,MAAM,EAAE,mBAAmB,CAAC,KAAK,CAAC,CAAC;IAChE,CAAC;IAED;;;;;;;;OAQG;IACI,KAAK,CAAC,OAAO,CACnB,MAA+B,EAC/B,SAA4B,EAC5B,IAAmB,EACnB,MAA2C,EAC3C,KAA0B;QAE1B,MAAM,CAAC,UAAU,CAChB,+BAA+B,CAAC,UAAU,WAE1C,KAAK,EACL,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAClC,CAAC;QAEF,IAAI,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACrE,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAC7B,KAAK,KAAK,mBAAmB,CAAC,MAAM;gBACnC,CAAC,CAAC,+BAA+B,CAAC,mBAAmB;gBACrD,CAAC,CAAC,+BAA+B,CAAC,kBAAkB,EACrD;gBACC,MAAM;gBACN,SAAS;gBACT,IAAI;gBACJ,MAAM;aACN,CACD,CAAC;QACH,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IAutomationComponent } from \"@twin.org/automation-models\";\nimport { ComponentFactory, Guards, Is } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\ttype IPolicyDecision,\n\ttype IPolicyExecutionAction,\n\ttype IRightsManagementPolicy,\n\tPolicyDecisionStage\n} from \"@twin.org/rights-management-models\";\nimport { OdrlActionType } from \"@twin.org/standards-w3c-odrl\";\nimport type { IAutomationPolicyExecutionActionConstructorOptions } from \"../models/IAutomationPolicyExecutionActionConstructorOptions.js\";\n\n/**\n * Automation Policy Execution Action to execute automation policies.\n */\nexport class AutomationPolicyExecutionAction implements IPolicyExecutionAction {\n\t/**\n\t * The class name of the Automation Policy Execution Action.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<AutomationPolicyExecutionAction>();\n\n\t/**\n\t * The before automation trigger name.\n\t */\n\tpublic static readonly BEFORE_TRIGGER_NAME: string = \"rights-management:pxp:before\";\n\n\t/**\n\t * The after automation trigger name.\n\t */\n\tpublic static readonly AFTER_TRIGGER_NAME: string = \"rights-management:pxp:after\";\n\n\t/**\n\t * The automation component.\n\t * @internal\n\t */\n\tprivate readonly _automation: IAutomationComponent;\n\n\t/**\n\t * The policy decision stages to trigger the automation actions, if undefined defaults to \"inform\".\n\t */\n\tprivate readonly _triggerActions: string[];\n\n\t/**\n\t * Create a new instance of AutomationPolicyExecutionAction.\n\t * @param options The options for the automation policy execution action.\n\t */\n\tconstructor(options?: IAutomationPolicyExecutionActionConstructorOptions) {\n\t\tthis._automation = ComponentFactory.get<IAutomationComponent>(\n\t\t\toptions?.automationComponentType ?? \"automation\"\n\t\t);\n\t\tthis._triggerActions = Is.arrayValue(options?.config?.triggerActions)\n\t\t\t? options?.config?.triggerActions\n\t\t\t: [OdrlActionType.Inform];\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 AutomationPolicyExecutionAction.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 [PolicyDecisionStage.Before, PolicyDecisionStage.After];\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: IRightsManagementPolicy,\n\t\tdecisions: IPolicyDecision[],\n\t\tdata: D | undefined,\n\t\taction: OdrlActionType | string | undefined,\n\t\tstage: PolicyDecisionStage\n\t): Promise<void> {\n\t\tGuards.arrayOneOf(\n\t\t\tAutomationPolicyExecutionAction.CLASS_NAME,\n\t\t\tnameof(stage),\n\t\t\tstage,\n\t\t\tObject.values(PolicyDecisionStage)\n\t\t);\n\n\t\tif (Is.stringValue(action) && this._triggerActions.includes(action)) {\n\t\t\tawait this._automation.trigger(\n\t\t\t\tstage === PolicyDecisionStage.Before\n\t\t\t\t\t? AutomationPolicyExecutionAction.BEFORE_TRIGGER_NAME\n\t\t\t\t\t: AutomationPolicyExecutionAction.AFTER_TRIGGER_NAME,\n\t\t\t\t{\n\t\t\t\t\tpolicy,\n\t\t\t\t\tdecisions,\n\t\t\t\t\tdata,\n\t\t\t\t\taction\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t}\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  // Copyright 2025 IOTA Stiftung.
2
2
  // SPDX-License-Identifier: Apache-2.0.
3
3
  import { ComponentFactory, Guards, Is } from "@twin.org/core";
4
- import { LocatorHelper, PolicyDecisionStage } from "@twin.org/rights-management-models";
4
+ import { OdrlPolicyHelper, PolicyDecisionStage } from "@twin.org/rights-management-models";
5
5
  /**
6
6
  * Logging Policy Execution Action to send decisions to logging.
7
7
  */
@@ -25,9 +25,9 @@ export class LoggingPolicyExecutionAction {
25
25
  */
26
26
  _includeData;
27
27
  /**
28
- * Whether to include the policies in the log.
28
+ * Whether to include the policy in the log.
29
29
  */
30
- _includePolicies;
30
+ _includePolicy;
31
31
  /**
32
32
  * Whether to include the decisions in the log.
33
33
  */
@@ -43,7 +43,7 @@ export class LoggingPolicyExecutionAction {
43
43
  PolicyDecisionStage.After
44
44
  ];
45
45
  this._includeData = options?.config?.includeData ?? false;
46
- this._includePolicies = options?.config?.includePolicies ?? false;
46
+ this._includePolicy = options?.config?.includePolicy ?? false;
47
47
  this._includeDecisions = options?.config?.includeDecisions ?? false;
48
48
  }
49
49
  /**
@@ -62,24 +62,23 @@ export class LoggingPolicyExecutionAction {
62
62
  }
63
63
  /**
64
64
  * Execute function type for policy actions.
65
- * @param stage The stage of the policy decision.
66
- * @param locator The locator to find relevant policies.
67
- * @param policies The policies that apply to the data.
65
+ * @param policy The policy that applied to the data.
68
66
  * @param decisions The decisions made by the PDP.
69
67
  * @param data The data to process.
68
+ * @param action Optional action to make a decision on, if not provided, the arbiter will evaluate all actions in the agreement.
69
+ * @param stage The stage of the policy decision.
70
70
  * @returns A promise that resolves when the action is complete.
71
71
  */
72
- async execute(stage, locator, policies, decisions, data) {
72
+ async execute(policy, decisions, data, action, stage) {
73
73
  Guards.arrayOneOf(LoggingPolicyExecutionAction.CLASS_NAME, "stage", stage, Object.values(PolicyDecisionStage));
74
- Guards.object(LoggingPolicyExecutionAction.CLASS_NAME, "locator", locator);
75
74
  if (this._stages.includes(stage)) {
76
- // Even if we don't have the options to include data or include policies we
75
+ // Even if we don't have the options to include data or include policy we
77
76
  // still create dummy entries, as the logging string still has them embedded
78
77
  let logData;
79
78
  if (!Is.empty(data)) {
80
79
  logData = this._includeData ? data : "{...}";
81
80
  }
82
- const logPolicies = this._includePolicies ? policies : "[...]";
81
+ const logPolicy = this._includePolicy ? policy : "{}";
83
82
  const logDecisions = this._includeDecisions ? decisions : "[...]";
84
83
  if (stage === PolicyDecisionStage.Before) {
85
84
  await this._logging.log({
@@ -88,10 +87,11 @@ export class LoggingPolicyExecutionAction {
88
87
  ts: Date.now(),
89
88
  message: "policyActionExecutedBefore",
90
89
  data: {
91
- locator: LocatorHelper.toString(locator),
90
+ policyId: OdrlPolicyHelper.getUid(policy) ?? "",
92
91
  data: logData,
93
- policies: logPolicies,
92
+ policy: logPolicy,
94
93
  decisions: logDecisions,
94
+ action,
95
95
  stage
96
96
  }
97
97
  });
@@ -103,10 +103,11 @@ export class LoggingPolicyExecutionAction {
103
103
  ts: Date.now(),
104
104
  message: "policyActionExecutedAfter",
105
105
  data: {
106
- locator: LocatorHelper.toString(locator),
106
+ policyId: OdrlPolicyHelper.getUid(policy) ?? "",
107
107
  data: logData,
108
- policies: logPolicies,
108
+ policy: logPolicy,
109
109
  decisions: logDecisions,
110
+ action,
110
111
  stage
111
112
  }
112
113
  });
@@ -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,EAIN,aAAa,EACb,mBAAmB,EACnB,MAAM,oCAAoC,CAAC;AAI5C;;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,gBAAgB,CAAU;IAE3C;;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,gBAAgB,GAAG,OAAO,EAAE,MAAM,EAAE,eAAe,IAAI,KAAK,CAAC;QAClE,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,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAED;;;;;;;;OAQG;IACI,KAAK,CAAC,OAAO,CACnB,KAA0B,EAC1B,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AAG,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,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC;wBACxC,IAAI,EAAE,OAAO;wBACb,QAAQ,EAAE,WAAW;wBACrB,SAAS,EAAE,YAAY;wBACvB,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\ttype IPolicyLocator,\n\tLocatorHelper,\n\tPolicyDecisionStage\n} from \"@twin.org/rights-management-models\";\nimport type { IOdrlPolicy } 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 policies in the log.\n\t */\n\tprivate readonly _includePolicies: 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._includePolicies = options?.config?.includePolicies ?? 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 stage The stage of the policy decision.\n\t * @param locator The locator to find relevant policies.\n\t * @param policies The policies that apply to the data.\n\t * @param decisions The decisions made by the PDP.\n\t * @param data The data to process.\n\t * @returns A promise that resolves when the action is complete.\n\t */\n\tpublic async execute<D = unknown>(\n\t\tstage: PolicyDecisionStage,\n\t\tlocator: IPolicyLocator,\n\t\tpolicies?: IOdrlPolicy[],\n\t\tdecisions?: IPolicyDecision[],\n\t\tdata?: D\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\t\tGuards.object<IPolicyLocator>(\n\t\t\tLoggingPolicyExecutionAction.CLASS_NAME,\n\t\t\tnameof(locator),\n\t\t\tlocator\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 policies 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 logPolicies = this._includePolicies ? policies : \"[...]\";\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\tlocator: LocatorHelper.toString(locator),\n\t\t\t\t\t\tdata: logData,\n\t\t\t\t\t\tpolicies: logPolicies,\n\t\t\t\t\t\tdecisions: logDecisions,\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\tlocator: LocatorHelper.toString(locator),\n\t\t\t\t\t\tdata: logData,\n\t\t\t\t\t\tpolicies: logPolicies,\n\t\t\t\t\t\tdecisions: logDecisions,\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":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAA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AE;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\ttype IRightsManagementPolicy,\n\tOdrlPolicyHelper,\n\tPolicyDecisionStage\n} from \"@twin.org/rights-management-models\";\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: IRightsManagementPolicy,\n\t\tdecisions: IPolicyDecision[],\n\t\tdata: D | undefined,\n\t\taction: OdrlActionType | string | undefined,\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,7 +1,8 @@
1
1
  // Copyright 2025 IOTA Stiftung.
2
2
  // SPDX-License-Identifier: Apache-2.0.
3
- import { BaseError, ComponentFactory, Guards } from "@twin.org/core";
4
- import { LocatorHelper, PolicyInformationAccessMode } from "@twin.org/rights-management-models";
3
+ import { BaseError, ComponentFactory, Guards, Is } from "@twin.org/core";
4
+ import { JsonLdHelper } from "@twin.org/data-json-ld";
5
+ import { OdrlPolicyHelper, PolicyInformationAccessMode } from "@twin.org/rights-management-models";
5
6
  /**
6
7
  * Policy information source which retrieves the identity information.
7
8
  */
@@ -37,41 +38,52 @@ export class IdentityPolicyInformationSource {
37
38
  }
38
39
  /**
39
40
  * Retrieve information from the sources.
40
- * @param locator The locator to find relevant policies.
41
+ * @param policy The policy to retrieve information for if available.
41
42
  * @param accessMode The access mode to use for the retrieval.
42
- * @param policies The policies that apply to the data.
43
43
  * @param data The data to process.
44
+ * @param action The action that was evaluated.
44
45
  * @returns The objects containing relevant information or undefined if nothing relevant is found.
45
46
  */
46
- async retrieve(locator, accessMode, policies, data) {
47
- Guards.objectValue(IdentityPolicyInformationSource.CLASS_NAME, "locator", locator);
47
+ async retrieve(policy, accessMode, data, action) {
48
48
  Guards.arrayOneOf(IdentityPolicyInformationSource.CLASS_NAME, "accessMode", accessMode, Object.values(PolicyInformationAccessMode));
49
- Guards.stringValue(IdentityPolicyInformationSource.CLASS_NAME, "locator.assignee", locator.assignee);
50
- const information = [];
51
- try {
52
- await this._logging?.log({
53
- level: "info",
54
- source: IdentityPolicyInformationSource.CLASS_NAME,
55
- ts: Date.now(),
56
- message: "identityRetrieving",
57
- data: {
58
- locator: LocatorHelper.toString(locator)
49
+ const information = {};
50
+ if (Is.object(policy)) {
51
+ const ids = [];
52
+ if (Is.stringValue(policy.assignee)) {
53
+ ids.push(policy.assignee);
54
+ }
55
+ if (Is.stringValue(policy.assigner)) {
56
+ ids.push(policy.assigner);
57
+ }
58
+ for (const id of ids) {
59
+ try {
60
+ await this._logging?.log({
61
+ level: "info",
62
+ source: IdentityPolicyInformationSource.CLASS_NAME,
63
+ ts: Date.now(),
64
+ message: "identityRetrieving",
65
+ data: {
66
+ policyId: OdrlPolicyHelper.getUid(policy) ?? "",
67
+ id
68
+ }
69
+ });
70
+ const idDoc = await this._identityResolver.identityResolve(id);
71
+ information[id] = JsonLdHelper.toNodeObject(idDoc);
59
72
  }
60
- });
61
- const idDoc = await this._identityResolver.identityResolve(locator.assignee);
62
- information.push(idDoc);
63
- }
64
- catch (err) {
65
- await this._logging?.log({
66
- level: "error",
67
- source: IdentityPolicyInformationSource.CLASS_NAME,
68
- ts: Date.now(),
69
- message: "identityRetrievalFailed",
70
- data: {
71
- locator: LocatorHelper.toString(locator)
72
- },
73
- error: BaseError.fromError(err)
74
- });
73
+ catch (err) {
74
+ await this._logging?.log({
75
+ level: "error",
76
+ source: IdentityPolicyInformationSource.CLASS_NAME,
77
+ ts: Date.now(),
78
+ message: "identityRetrievalFailed",
79
+ data: {
80
+ policyId: OdrlPolicyHelper.getUid(policy) ?? "",
81
+ id
82
+ },
83
+ error: BaseError.fromError(err)
84
+ });
85
+ }
86
+ }
75
87
  }
76
88
  return information;
77
89
  }
@@ -1 +1 @@
1
- {"version":3,"file":"identityPolicyInformationSource.js","sourceRoot":"","sources":["../../../src/policyInformationSources/identityPolicyInformationSource.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAKrE,OAAO,EAGN,aAAa,EACb,2BAA2B,EAC3B,MAAM,oCAAoC,CAAC;AAI5C;;GAEG;AACH,MAAM,OAAO,+BAA+B;IAC3C;;OAEG;IACI,MAAM,CAAU,UAAU,qCAAqD;IAEtF;;;OAGG;IACc,QAAQ,CAAqB;IAE9C;;;OAGG;IACc,iBAAiB,CAA6B;IAE/D;;;OAGG;IACH,YAAY,OAA4D;QACvE,IAAI,CAAC,QAAQ,GAAG,gBAAgB,CAAC,WAAW,CAC3C,OAAO,EAAE,oBAAoB,IAAI,SAAS,CAC1C,CAAC;QACF,IAAI,CAAC,iBAAiB,GAAG,gBAAgB,CAAC,GAAG,CAC5C,OAAO,EAAE,6BAA6B,IAAI,mBAAmB,CAC7D,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,+BAA+B,CAAC,UAAU,CAAC;IACnD,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,QAAQ,CACpB,OAAuB,EACvB,UAAuC,EACvC,QAAuB,EACvB,IAAQ;QAER,MAAM,CAAC,WAAW,CACjB,+BAA+B,CAAC,U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ory, Guards } from \"@twin.org/core\";\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport type { IIdentityResolverComponent } from \"@twin.org/identity-models\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\ttype IPolicyInformationSource,\n\ttype IPolicyLocator,\n\tLocatorHelper,\n\tPolicyInformationAccessMode\n} from \"@twin.org/rights-management-models\";\nimport type { IOdrlPolicy } from \"@twin.org/standards-w3c-odrl\";\nimport type { IIdentityPolicyInformationSourceConstructorOptions } from \"../models/IIdentityPolicyInformationSourceConstructorOptions.js\";\n\n/**\n * Policy information source which retrieves the identity information.\n */\nexport class IdentityPolicyInformationSource implements IPolicyInformationSource {\n\t/**\n\t * The class name of the Identity Policy Information Source.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<IdentityPolicyInformationSource>();\n\n\t/**\n\t * The logging component.\n\t * @internal\n\t */\n\tprivate readonly _logging?: ILoggingComponent;\n\n\t/**\n\t * The identity resolver component.\n\t * @internal\n\t */\n\tprivate readonly _identityResolver: IIdentityResolverComponent;\n\n\t/**\n\t * Create a new instance of IdentityPolicyInformationSource.\n\t * @param options The options for the logging policy source.\n\t */\n\tconstructor(options?: IIdentityPolicyInformationSourceConstructorOptions) {\n\t\tthis._logging = ComponentFactory.getIfExists<ILoggingComponent>(\n\t\t\toptions?.loggingComponentType ?? \"logging\"\n\t\t);\n\t\tthis._identityResolver = ComponentFactory.get(\n\t\t\toptions?.identityResolverComponentType ?? \"identity-resolver\"\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 IdentityPolicyInformationSource.CLASS_NAME;\n\t}\n\n\t/**\n\t * Retrieve information from the sources.\n\t * @param locator The locator to find relevant policies.\n\t * @param accessMode The access mode to use for the retrieval.\n\t * @param policies The policies that apply to the data.\n\t * @param data The data to process.\n\t * @returns The objects containing relevant information or undefined if nothing relevant is found.\n\t */\n\tpublic async retrieve<D = unknown>(\n\t\tlocator: IPolicyLocator,\n\t\taccessMode: PolicyInformationAccessMode,\n\t\tpolicies: IOdrlPolicy[],\n\t\tdata?: D\n\t): Promise<IJsonLdNodeObject[] | undefined> {\n\t\tGuards.objectValue<IPolicyLocator>(\n\t\t\tIdentityPolicyInformationSource.CLASS_NAME,\n\t\t\tnameof(locator),\n\t\t\tlocator\n\t\t);\n\t\tGuards.arrayOneOf(\n\t\t\tIdentityPolicyInformationSource.CLASS_NAME,\n\t\t\tnameof(accessMode),\n\t\t\taccessMode,\n\t\t\tObject.values(PolicyInformationAccessMode)\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tIdentityPolicyInformationSource.CLASS_NAME,\n\t\t\tnameof(locator.assignee),\n\t\t\tlocator.assignee\n\t\t);\n\n\t\tconst information: IJsonLdNodeObject[] = [];\n\n\t\ttry {\n\t\t\tawait this._logging?.log({\n\t\t\t\tlevel: \"info\",\n\t\t\t\tsource: IdentityPolicyInformationSource.CLASS_NAME,\n\t\t\t\tts: Date.now(),\n\t\t\t\tmessage: \"identityRetrieving\",\n\t\t\t\tdata: {\n\t\t\t\t\tlocator: LocatorHelper.toString(locator)\n\t\t\t\t}\n\t\t\t});\n\t\t\tconst idDoc = await this._identityResolver.identityResolve(locator.assignee);\n\t\t\tinformation.push(idDoc as unknown as IJsonLdNodeObject);\n\t\t} catch (err) {\n\t\t\tawait this._logging?.log({\n\t\t\t\tlevel: \"error\",\n\t\t\t\tsource: IdentityPolicyInformationSource.CLASS_NAME,\n\t\t\t\tts: Date.now(),\n\t\t\t\tmessage: \"identityRetrievalFailed\",\n\t\t\t\tdata: {\n\t\t\t\t\tlocator: LocatorHelper.toString(locator)\n\t\t\t\t},\n\t\t\t\terror: BaseError.fromError(err)\n\t\t\t});\n\t\t}\n\n\t\treturn information;\n\t}\n}\n"]}
1
+ {"version":3,"file":"identityPolicyInformationSource.js","sourceRoot":"","sources":["../../../src/policyInformationSources/identityPolicy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// SPDX-License-Identifier: Apache-2.0.\nimport { BaseError, ComponentFactory, Guards, Is } from \"@twin.org/core\";\nimport { type IJsonLdNodeObject, JsonLdHelper } from \"@twin.org/data-json-ld\";\nimport type { IIdentityResolverComponent } from \"@twin.org/identity-models\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\ttype IPolicyInformationSource,\n\ttype IRightsManagementPolicy,\n\tOdrlPolicyHelper,\n\tPolicyInformationAccessMode\n} from \"@twin.org/rights-management-models\";\nimport type { OdrlActionType } from \"@twin.org/standards-w3c-odrl\";\nimport type { IIdentityPolicyInformationSourceConstructorOptions } from \"../models/IIdentityPolicyInformationSourceConstructorOptions.js\";\n\n/**\n * Policy information source which retrieves the identity information.\n */\nexport class IdentityPolicyInformationSource implements IPolicyInformationSource {\n\t/**\n\t * The class name of the Identity Policy Information Source.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<IdentityPolicyInformationSource>();\n\n\t/**\n\t * The logging component.\n\t * @internal\n\t */\n\tprivate readonly _logging?: ILoggingComponent;\n\n\t/**\n\t * The identity resolver component.\n\t * @internal\n\t */\n\tprivate readonly _identityResolver: IIdentityResolverComponent;\n\n\t/**\n\t * Create a new instance of IdentityPolicyInformationSource.\n\t * @param options The options for the logging policy source.\n\t */\n\tconstructor(options?: IIdentityPolicyInformationSourceConstructorOptions) {\n\t\tthis._logging = ComponentFactory.getIfExists<ILoggingComponent>(\n\t\t\toptions?.loggingComponentType ?? \"logging\"\n\t\t);\n\t\tthis._identityResolver = ComponentFactory.get(\n\t\t\toptions?.identityResolverComponentType ?? \"identity-resolver\"\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 IdentityPolicyInformationSource.CLASS_NAME;\n\t}\n\n\t/**\n\t * Retrieve information from the sources.\n\t * @param policy The policy to retrieve information for if available.\n\t * @param accessMode The access mode to use for the retrieval.\n\t * @param data The data to process.\n\t * @param action The action that was evaluated.\n\t * @returns The objects containing relevant information or undefined if nothing relevant is found.\n\t */\n\tpublic async retrieve<D = unknown>(\n\t\tpolicy: IRightsManagementPolicy | undefined,\n\t\taccessMode: PolicyInformationAccessMode,\n\t\tdata?: D,\n\t\taction?: OdrlActionType | string\n\t): Promise<{ [id: string]: IJsonLdNodeObject } | undefined> {\n\t\tGuards.arrayOneOf(\n\t\t\tIdentityPolicyInformationSource.CLASS_NAME,\n\t\t\tnameof(accessMode),\n\t\t\taccessMode,\n\t\t\tObject.values(PolicyInformationAccessMode)\n\t\t);\n\n\t\tconst information: { [id: string]: IJsonLdNodeObject } = {};\n\n\t\tif (Is.object<IRightsManagementPolicy>(policy)) {\n\t\t\tconst ids = [];\n\n\t\t\tif (Is.stringValue(policy.assignee)) {\n\t\t\t\tids.push(policy.assignee);\n\t\t\t}\n\t\t\tif (Is.stringValue(policy.assigner)) {\n\t\t\t\tids.push(policy.assigner);\n\t\t\t}\n\n\t\t\tfor (const id of ids) {\n\t\t\t\ttry {\n\t\t\t\t\tawait this._logging?.log({\n\t\t\t\t\t\tlevel: \"info\",\n\t\t\t\t\t\tsource: IdentityPolicyInformationSource.CLASS_NAME,\n\t\t\t\t\t\tts: Date.now(),\n\t\t\t\t\t\tmessage: \"identityRetrieving\",\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\tpolicyId: OdrlPolicyHelper.getUid(policy) ?? \"\",\n\t\t\t\t\t\t\tid\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\tconst idDoc = await this._identityResolver.identityResolve(id);\n\t\t\t\t\tinformation[id] = JsonLdHelper.toNodeObject(idDoc);\n\t\t\t\t} catch (err) {\n\t\t\t\t\tawait this._logging?.log({\n\t\t\t\t\t\tlevel: \"error\",\n\t\t\t\t\t\tsource: IdentityPolicyInformationSource.CLASS_NAME,\n\t\t\t\t\t\tts: Date.now(),\n\t\t\t\t\t\tmessage: \"identityRetrievalFailed\",\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\tpolicyId: OdrlPolicyHelper.getUid(policy) ?? \"\",\n\t\t\t\t\t\t\tid\n\t\t\t\t\t\t},\n\t\t\t\t\t\terror: BaseError.fromError(err)\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn information;\n\t}\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  // Copyright 2025 IOTA Stiftung.
2
2
  // SPDX-License-Identifier: Apache-2.0.
3
3
  import { ComponentFactory, Guards, Is } from "@twin.org/core";
4
- import { LocatorHelper, PolicyInformationAccessMode } from "@twin.org/rights-management-models";
4
+ import { OdrlPolicyHelper, PolicyInformationAccessMode } from "@twin.org/rights-management-models";
5
5
  /**
6
6
  * Policy information source which retrieves static information.
7
7
  */
@@ -37,24 +37,22 @@ export class StaticPolicyInformationSource {
37
37
  }
38
38
  /**
39
39
  * Retrieve information from the sources.
40
- * @param locator The locator to find relevant policies.
40
+ * @param policy The policy to retrieve information for if available.
41
41
  * @param accessMode The access mode to use for the retrieval.
42
- * @param policies The policies that apply to the data.
43
42
  * @param data The data to process.
43
+ * @param action The action to get any additional information for.
44
44
  * @returns The objects containing relevant information or undefined if nothing relevant is found.
45
45
  */
46
- async retrieve(locator, accessMode, policies, data) {
47
- Guards.objectValue(StaticPolicyInformationSource.CLASS_NAME, "locator", locator);
46
+ async retrieve(policy, accessMode, data, action) {
48
47
  Guards.arrayOneOf(StaticPolicyInformationSource.CLASS_NAME, "accessMode", accessMode, Object.values(PolicyInformationAccessMode));
49
- Guards.stringValue(StaticPolicyInformationSource.CLASS_NAME, "locator.assignee", locator.assignee);
50
- const information = [];
48
+ let information = {};
51
49
  await this._logging?.log({
52
50
  level: "info",
53
51
  source: StaticPolicyInformationSource.CLASS_NAME,
54
52
  ts: Date.now(),
55
53
  message: "staticRetrieving",
56
54
  data: {
57
- locator: LocatorHelper.toString(locator),
55
+ policyId: OdrlPolicyHelper.getUid(policy) ?? "",
58
56
  accessMode
59
57
  }
60
58
  });
@@ -62,9 +60,13 @@ export class StaticPolicyInformationSource {
62
60
  if (info.accessMode === accessMode ||
63
61
  accessMode === PolicyInformationAccessMode.Any ||
64
62
  info.accessMode === PolicyInformationAccessMode.Any) {
65
- if (!Is.arrayValue(info.matchLocators) ||
66
- !Is.empty(LocatorHelper.findMatchingLocator(info.matchLocators, locator))) {
67
- information.push(...info.objects);
63
+ const matchLocators = info.matchLocators;
64
+ if (!Is.arrayValue(matchLocators) ||
65
+ matchLocators.some(locator => OdrlPolicyHelper.matchPolicy(policy, locator))) {
66
+ information = {
67
+ ...information,
68
+ ...info.objects
69
+ };
68
70
  }
69
71
  }
70
72
  }
@@ -74,12 +76,12 @@ export class StaticPolicyInformationSource {
74
76
  ts: Date.now(),
75
77
  message: "staticRetrieved",
76
78
  data: {
77
- locator: LocatorHelper.toString(locator),
79
+ policyId: OdrlPolicyHelper.getUid(policy) ?? "",
78
80
  accessMode,
79
- itemCount: information.length
81
+ itemCount: Object.keys(information).length
80
82
  }
81
83
  });
82
- return information.length > 0 ? information : undefined;
84
+ return Object.keys(information).length > 0 ? information : undefined;
83
85
  }
84
86
  /**
85
87
  * Add static policy information.
@@ -87,7 +89,7 @@ export class StaticPolicyInformationSource {
87
89
  */
88
90
  addInformation(info) {
89
91
  Guards.arrayOneOf(StaticPolicyInformationSource.CLASS_NAME, "info.accessMode", info.accessMode, Object.values(PolicyInformationAccessMode));
90
- Guards.arrayValue(StaticPolicyInformationSource.CLASS_NAME, "info.objects", info.objects);
92
+ Guards.objectValue(StaticPolicyInformationSource.CLASS_NAME, "info.objects", info.objects);
91
93
  this._information.push(info);
92
94
  }
93
95
  }
@@ -1 +1 @@
1
- {"version":3,"file":"staticPolicyInformationSource.js","sourceRoot":"","sources":["../../../src/policyInformationSources/staticPolicyInformationSource.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,EAAE,EAAE,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I,CAAC,CAAC;IAC9B,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ComponentFactory, Guards, Is } 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\tLocatorHelper,\n\tPolicyInformationAccessMode,\n\ttype IPolicyInformationSource,\n\ttype IPolicyLocator\n} from \"@twin.org/rights-management-models\";\nimport type { IOdrlPolicy } from \"@twin.org/standards-w3c-odrl\";\nimport type { IStaticPolicyInformationSource } from \"../models/IStaticPolicyInformationSource.js\";\nimport type { IStaticPolicyInformationSourceConstructorOptions } from \"../models/IStaticPolicyInformationSourceConstructorOptions.js\";\n\n/**\n * Policy information source which retrieves static information.\n */\nexport class StaticPolicyInformationSource implements IPolicyInformationSource {\n\t/**\n\t * The class name of the Static Policy Information Source.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<StaticPolicyInformationSource>();\n\n\t/**\n\t * The logging component.\n\t * @internal\n\t */\n\tprivate readonly _logging?: ILoggingComponent;\n\n\t/**\n\t * The information sources.\n\t * @internal\n\t */\n\tprivate readonly _information: IStaticPolicyInformationSource[];\n\n\t/**\n\t * Create a new instance of StaticPolicyInformationSource.\n\t * @param options The options for the logging policy source.\n\t */\n\tconstructor(options?: IStaticPolicyInformationSourceConstructorOptions) {\n\t\tthis._logging = ComponentFactory.getIfExists<ILoggingComponent>(\n\t\t\toptions?.loggingComponentType ?? \"logging\"\n\t\t);\n\t\tthis._information = options?.config?.information ?? [];\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 StaticPolicyInformationSource.CLASS_NAME;\n\t}\n\n\t/**\n\t * Retrieve information from the sources.\n\t * @param locator The locator to find relevant policies.\n\t * @param accessMode The access mode to use for the retrieval.\n\t * @param policies The policies that apply to the data.\n\t * @param data The data to process.\n\t * @returns The objects containing relevant information or undefined if nothing relevant is found.\n\t */\n\tpublic async retrieve<D = unknown>(\n\t\tlocator: IPolicyLocator,\n\t\taccessMode: PolicyInformationAccessMode,\n\t\tpolicies: IOdrlPolicy[],\n\t\tdata?: D\n\t): Promise<IJsonLdNodeObject[] | undefined> {\n\t\tGuards.objectValue<IPolicyLocator>(\n\t\t\tStaticPolicyInformationSource.CLASS_NAME,\n\t\t\tnameof(locator),\n\t\t\tlocator\n\t\t);\n\t\tGuards.arrayOneOf(\n\t\t\tStaticPolicyInformationSource.CLASS_NAME,\n\t\t\tnameof(accessMode),\n\t\t\taccessMode,\n\t\t\tObject.values(PolicyInformationAccessMode)\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tStaticPolicyInformationSource.CLASS_NAME,\n\t\t\tnameof(locator.assignee),\n\t\t\tlocator.assignee\n\t\t);\n\n\t\tconst information: IJsonLdNodeObject[] = [];\n\n\t\tawait this._logging?.log({\n\t\t\tlevel: \"info\",\n\t\t\tsource: StaticPolicyInformationSource.CLASS_NAME,\n\t\t\tts: Date.now(),\n\t\t\tmessage: \"staticRetrieving\",\n\t\t\tdata: {\n\t\t\t\tlocator: LocatorHelper.toString(locator),\n\t\t\t\taccessMode\n\t\t\t}\n\t\t});\n\n\t\tfor (const info of this._information) {\n\t\t\tif (\n\t\t\t\tinfo.accessMode === accessMode ||\n\t\t\t\taccessMode === PolicyInformationAccessMode.Any ||\n\t\t\t\tinfo.accessMode === PolicyInformationAccessMode.Any\n\t\t\t) {\n\t\t\t\tif (\n\t\t\t\t\t!Is.arrayValue(info.matchLocators) ||\n\t\t\t\t\t!Is.empty(LocatorHelper.findMatchingLocator(info.matchLocators, locator))\n\t\t\t\t) {\n\t\t\t\t\tinformation.push(...info.objects);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tawait this._logging?.log({\n\t\t\tlevel: \"info\",\n\t\t\tsource: StaticPolicyInformationSource.CLASS_NAME,\n\t\t\tts: Date.now(),\n\t\t\tmessage: \"staticRetrieved\",\n\t\t\tdata: {\n\t\t\t\tlocator: LocatorHelper.toString(locator),\n\t\t\t\taccessMode,\n\t\t\t\titemCount: information.length\n\t\t\t}\n\t\t});\n\n\t\treturn information.length > 0 ? information : undefined;\n\t}\n\n\t/**\n\t * Add static policy information.\n\t * @param info The static policy information to add.\n\t */\n\tpublic addInformation(info: IStaticPolicyInformationSource): void {\n\t\tGuards.arrayOneOf<string>(\n\t\t\tStaticPolicyInformationSource.CLASS_NAME,\n\t\t\tnameof(info.accessMode),\n\t\t\tinfo.accessMode,\n\t\t\tObject.values(PolicyInformationAccessMode)\n\t\t);\n\t\tGuards.arrayValue<IJsonLdNodeObject>(\n\t\t\tStaticPolicyInformationSource.CLASS_NAME,\n\t\t\tnameof(info.objects),\n\t\t\tinfo.objects\n\t\t);\n\t\tthis._information.push(info);\n\t}\n}\n"]}
1
+ {"version":3,"file":"staticPolicyInformationSource.js","sourceRoot":"","sources":["../../../src/policyInformationSources/staticPolicyInformationSource.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAI9D,OAAO,EACN,gBAAgB,EAChB,2BAA2B,EAG3B,MAAM,oCAAoC,CAAC;AAK5C;;GAEG;AACH,MAAM,OAAO,6BAA6B;IACzC;;OAEG;IACI,MAAM,CAAU,UAAU,mCAAmD;IAEpF;;;OAGG;IACc,QAAQ,CAAqB;IAE9C;;;OAGG;IACc,YAAY,CAAmC;IAEhE;;;OAGG;IACH,YAAY,OAA0D;QACrE,IAAI,CAAC,QAAQ,GAAG,gBAAgB,CAAC,WAAW,CAC3C,OAAO,EAAE,oBAAoB,IAAI,SAAS,CAC1C,CAAC;QACF,IAAI,CAAC,YAAY,GAAG,OAAO,EAAE,MAAM,EAAE,WAAW,IAAI,EAAE,CAAC;IACxD,CAAC;IAED;;;OAGG;IACI,SA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ACb,MAAM,EAAE,6BAA6B,CAAC,UAAU;YAChD,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE;YACd,OAAO,EAAE,iBAAiB;YAC1B,IAAI,EAAE;gBACL,QAAQ,EAAE,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;gBAC/C,UAAU;gBACV,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM;aAC1C;SACD,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC;IACtE,CAAC;IAED;;;OAGG;IACI,cAAc,CAAC,IAAoC;QACzD,MAAM,CAAC,UAAU,CAChB,6BAA6B,CAAC,UAAU,qBAExC,IAAI,CAAC,UAAU,EACf,MAAM,CAAC,MAAM,CAAC,2BAA2B,CAAC,CAC1C,CAAC;QACF,MAAM,CAAC,WAAW,CACjB,6BAA6B,CAAC,UAAU,kBAExC,IAAI,CAAC,OAAO,CACZ,CAAC;QACF,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ComponentFactory, Guards, Is } 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\tPolicyInformationAccessMode,\n\ttype IPolicyInformationSource,\n\ttype IRightsManagementPolicy\n} from \"@twin.org/rights-management-models\";\nimport type { OdrlActionType } from \"@twin.org/standards-w3c-odrl\";\nimport type { IStaticPolicyInformationSource } from \"../models/IStaticPolicyInformationSource.js\";\nimport type { IStaticPolicyInformationSourceConstructorOptions } from \"../models/IStaticPolicyInformationSourceConstructorOptions.js\";\n\n/**\n * Policy information source which retrieves static information.\n */\nexport class StaticPolicyInformationSource implements IPolicyInformationSource {\n\t/**\n\t * The class name of the Static Policy Information Source.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<StaticPolicyInformationSource>();\n\n\t/**\n\t * The logging component.\n\t * @internal\n\t */\n\tprivate readonly _logging?: ILoggingComponent;\n\n\t/**\n\t * The information sources.\n\t * @internal\n\t */\n\tprivate readonly _information: IStaticPolicyInformationSource[];\n\n\t/**\n\t * Create a new instance of StaticPolicyInformationSource.\n\t * @param options The options for the logging policy source.\n\t */\n\tconstructor(options?: IStaticPolicyInformationSourceConstructorOptions) {\n\t\tthis._logging = ComponentFactory.getIfExists<ILoggingComponent>(\n\t\t\toptions?.loggingComponentType ?? \"logging\"\n\t\t);\n\t\tthis._information = options?.config?.information ?? [];\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 StaticPolicyInformationSource.CLASS_NAME;\n\t}\n\n\t/**\n\t * Retrieve information from the sources.\n\t * @param policy The policy to retrieve information for if available.\n\t * @param accessMode The access mode to use for the retrieval.\n\t * @param data The data to process.\n\t * @param action The action to get any additional information for.\n\t * @returns The objects containing relevant information or undefined if nothing relevant is found.\n\t */\n\tpublic async retrieve<D = unknown>(\n\t\tpolicy: IRightsManagementPolicy | undefined,\n\t\taccessMode: PolicyInformationAccessMode,\n\t\tdata?: D,\n\t\taction?: OdrlActionType | string\n\t): Promise<{ [id: string]: IJsonLdNodeObject } | undefined> {\n\t\tGuards.arrayOneOf(\n\t\t\tStaticPolicyInformationSource.CLASS_NAME,\n\t\t\tnameof(accessMode),\n\t\t\taccessMode,\n\t\t\tObject.values(PolicyInformationAccessMode)\n\t\t);\n\n\t\tlet information: { [id: string]: IJsonLdNodeObject } = {};\n\n\t\tawait this._logging?.log({\n\t\t\tlevel: \"info\",\n\t\t\tsource: StaticPolicyInformationSource.CLASS_NAME,\n\t\t\tts: Date.now(),\n\t\t\tmessage: \"staticRetrieving\",\n\t\t\tdata: {\n\t\t\t\tpolicyId: OdrlPolicyHelper.getUid(policy) ?? \"\",\n\t\t\t\taccessMode\n\t\t\t}\n\t\t});\n\n\t\tfor (const info of this._information) {\n\t\t\tif (\n\t\t\t\tinfo.accessMode === accessMode ||\n\t\t\t\taccessMode === PolicyInformationAccessMode.Any ||\n\t\t\t\tinfo.accessMode === PolicyInformationAccessMode.Any\n\t\t\t) {\n\t\t\t\tconst matchLocators = info.matchLocators;\n\t\t\t\tif (\n\t\t\t\t\t!Is.arrayValue(matchLocators) ||\n\t\t\t\t\tmatchLocators.some(locator => OdrlPolicyHelper.matchPolicy(policy, locator))\n\t\t\t\t) {\n\t\t\t\t\tinformation = {\n\t\t\t\t\t\t...information,\n\t\t\t\t\t\t...info.objects\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tawait this._logging?.log({\n\t\t\tlevel: \"info\",\n\t\t\tsource: StaticPolicyInformationSource.CLASS_NAME,\n\t\t\tts: Date.now(),\n\t\t\tmessage: \"staticRetrieved\",\n\t\t\tdata: {\n\t\t\t\tpolicyId: OdrlPolicyHelper.getUid(policy) ?? \"\",\n\t\t\t\taccessMode,\n\t\t\t\titemCount: Object.keys(information).length\n\t\t\t}\n\t\t});\n\n\t\treturn Object.keys(information).length > 0 ? information : undefined;\n\t}\n\n\t/**\n\t * Add static policy information.\n\t * @param info The static policy information to add.\n\t */\n\tpublic addInformation(info: IStaticPolicyInformationSource): void {\n\t\tGuards.arrayOneOf<string>(\n\t\t\tStaticPolicyInformationSource.CLASS_NAME,\n\t\t\tnameof(info.accessMode),\n\t\t\tinfo.accessMode,\n\t\t\tObject.values(PolicyInformationAccessMode)\n\t\t);\n\t\tGuards.objectValue<{ [id: string]: IJsonLdNodeObject }>(\n\t\t\tStaticPolicyInformationSource.CLASS_NAME,\n\t\t\tnameof(info.objects),\n\t\t\tinfo.objects\n\t\t);\n\t\tthis._information.push(info);\n\t}\n}\n"]}
@@ -0,0 +1,88 @@
1
+ // Copyright 2025 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { ComponentFactory, Guards, ObjectHelper, Urn } from "@twin.org/core";
4
+ import { OdrlPolicyHelper, RightsManagementNamespaces } from "@twin.org/rights-management-models";
5
+ import { OdrlPolicyType } from "@twin.org/standards-w3c-odrl";
6
+ /**
7
+ * Pass Through Policy Negotiator.
8
+ */
9
+ export class PassThroughPolicyNegotiator {
10
+ /**
11
+ * The class name of the Pass Through Policy Negotiator.
12
+ */
13
+ static CLASS_NAME = "PassThroughPolicyNegotiator";
14
+ /**
15
+ * The logging component.
16
+ * @internal
17
+ */
18
+ _logging;
19
+ /**
20
+ * Create a new instance of PassThroughPolicyNegotiator.
21
+ * @param options The options for the pass through policy negotiator.
22
+ */
23
+ constructor(options) {
24
+ this._logging = ComponentFactory.get(options?.loggingComponentType ?? "logging");
25
+ }
26
+ /**
27
+ * Returns the class name of the component.
28
+ * @returns The class name of the component.
29
+ */
30
+ className() {
31
+ return PassThroughPolicyNegotiator.CLASS_NAME;
32
+ }
33
+ /**
34
+ * Determines if the negotiator supports the given offer.
35
+ * @param offer The offer to check.
36
+ * @returns Sets the supports flag if it can be offered, and the interventionRequired flag if manual agreement is needed.
37
+ */
38
+ supportsOffer(offer) {
39
+ return true;
40
+ }
41
+ /**
42
+ * Handle the offer.
43
+ * @param offer The offer to check.
44
+ * @param information Information provided by the requester to determine if a policy can be created.
45
+ * @returns Sets the accepted flag if it can be offered, and the interventionRequired flag if manual agreement is needed.
46
+ */
47
+ async handleOffer(offer, information) {
48
+ Guards.object(PassThroughPolicyNegotiator.CLASS_NAME, "offer", offer);
49
+ await this._logging.log({
50
+ level: "info",
51
+ source: PassThroughPolicyNegotiator.CLASS_NAME,
52
+ ts: Date.now(),
53
+ message: "handlingOffer",
54
+ data: {
55
+ offerId: OdrlPolicyHelper.getUid(offer) ?? ""
56
+ }
57
+ });
58
+ return {
59
+ accepted: true,
60
+ interventionRequired: false
61
+ };
62
+ }
63
+ /**
64
+ * Create an agreement based on the offer.
65
+ * @param offer The offer to create the agreement from.
66
+ * @param assignee The assignee of the agreement.
67
+ * @param information Information provided by the requester to aid in the creation of the agreement.
68
+ * @returns The agreement created from the offer or undefined if an agreement could not be created.
69
+ */
70
+ async createAgreement(offer, assignee, information) {
71
+ Guards.object(PassThroughPolicyNegotiator.CLASS_NAME, "offer", offer);
72
+ await this._logging.log({
73
+ level: "info",
74
+ source: PassThroughPolicyNegotiator.CLASS_NAME,
75
+ ts: Date.now(),
76
+ message: "createAgreement",
77
+ data: {
78
+ offerId: OdrlPolicyHelper.getUid(offer) ?? ""
79
+ }
80
+ });
81
+ const agreement = ObjectHelper.clone(offer);
82
+ agreement["@type"] = OdrlPolicyType.Agreement;
83
+ agreement["@id"] = Urn.generateRandom(RightsManagementNamespaces.Policy).toString(false);
84
+ agreement.assignee = assignee;
85
+ return agreement;
86
+ }
87
+ }
88
+ //# sourceMappingURL=passThroughPolicyNegotiator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"passThroughPolicyNegotiator.js","sourceRoot":"","sources":["../../../src/policyNegotiators/passThroughPolicyNegotiator.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAI7E,OAAO,EACN,gBAAgB,EAChB,0BAA0B,EAE1B,MAAM,oCAAoC,CAAC;AAM5C,OAAO,EAAE,cAAc,EAAmB,MAAM,8BAA8B,CAAC;AAG/E;;GAEG;AACH,MAAM,OAAO,2BAA2B;IACvC;;OAEG;IACI,MAAM,CAAU,UAAU,iCAAiD;IAElF;;;OAGG;IACc,QAAQ,CAAoB;IAE7C;;;OAGG;IACH,YAAY,OAAwD;QACnE,IAAI,CAAC,QAAQ,GAAG,gBAAgB,CAAC,GAAG,CACnC,OAAO,EAAE,o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AAS,CAAC,OAAO,CAAC,GAAG,cAAc,CAAC,SAAS,CAAC;QAC9C,SAAS,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,cAAc,CAAC,0BAA0B,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACzF,SAAS,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAE9B,OAAO,SAAwC,CAAC;IACjD,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ComponentFactory, Guards, ObjectHelper, Urn } 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\tRightsManagementNamespaces,\n\ttype IPolicyNegotiator\n} from \"@twin.org/rights-management-models\";\nimport type {\n\tIDataspaceProtocolAgreement,\n\tIDataspaceProtocolOffer,\n\tIDataspaceProtocolPolicy\n} from \"@twin.org/standards-dataspace-protocol\";\nimport { OdrlPolicyType, type IOdrlParty } from \"@twin.org/standards-w3c-odrl\";\nimport type { IPassThroughPolicyNegotiatorConstructorOptions } from \"../models/IPassThroughPolicyNegotiatorConstructorOptions.js\";\n\n/**\n * Pass Through Policy Negotiator.\n */\nexport class PassThroughPolicyNegotiator implements IPolicyNegotiator {\n\t/**\n\t * The class name of the Pass Through Policy Negotiator.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<PassThroughPolicyNegotiator>();\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 PassThroughPolicyNegotiator.\n\t * @param options The options for the pass through policy negotiator.\n\t */\n\tconstructor(options?: IPassThroughPolicyNegotiatorConstructorOptions) {\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 PassThroughPolicyNegotiator.CLASS_NAME;\n\t}\n\n\t/**\n\t * Determines if the negotiator supports the given offer.\n\t * @param offer The offer to check.\n\t * @returns Sets the supports flag if it can be offered, and the interventionRequired flag if manual agreement is needed.\n\t */\n\tpublic supportsOffer(offer: IDataspaceProtocolOffer): boolean {\n\t\treturn true;\n\t}\n\n\t/**\n\t * Handle the offer.\n\t * @param offer The offer to check.\n\t * @param information Information provided by the requester to determine if a policy can be created.\n\t * @returns Sets the accepted flag if it can be offered, and the interventionRequired flag if manual agreement is needed.\n\t */\n\tpublic async handleOffer(\n\t\toffer: IDataspaceProtocolOffer,\n\t\tinformation?: { [id: string]: IJsonLdNodeObject }\n\t): Promise<{\n\t\taccepted: boolean;\n\t\tinterventionRequired: boolean;\n\t}> {\n\t\tGuards.object<IDataspaceProtocolOffer>(\n\t\t\tPassThroughPolicyNegotiator.CLASS_NAME,\n\t\t\tnameof(offer),\n\t\t\toffer\n\t\t);\n\n\t\tawait this._logging.log({\n\t\t\tlevel: \"info\",\n\t\t\tsource: PassThroughPolicyNegotiator.CLASS_NAME,\n\t\t\tts: Date.now(),\n\t\t\tmessage: \"handlingOffer\",\n\t\t\tdata: {\n\t\t\t\tofferId: OdrlPolicyHelper.getUid(offer) ?? \"\"\n\t\t\t}\n\t\t});\n\n\t\treturn {\n\t\t\taccepted: true,\n\t\t\tinterventionRequired: false\n\t\t};\n\t}\n\n\t/**\n\t * Create an agreement based on the offer.\n\t * @param offer The offer to create the agreement from.\n\t * @param assignee The assignee of the agreement.\n\t * @param information Information provided by the requester to aid in the creation of the agreement.\n\t * @returns The agreement created from the offer or undefined if an agreement could not be created.\n\t */\n\tpublic async createAgreement(\n\t\toffer: IDataspaceProtocolOffer,\n\t\tassignee: string | IOdrlParty,\n\t\tinformation?: { [id: string]: IJsonLdNodeObject }\n\t): Promise<IDataspaceProtocolAgreement | undefined> {\n\t\tGuards.object<IDataspaceProtocolOffer>(\n\t\t\tPassThroughPolicyNegotiator.CLASS_NAME,\n\t\t\tnameof(offer),\n\t\t\toffer\n\t\t);\n\n\t\tawait this._logging.log({\n\t\t\tlevel: \"info\",\n\t\t\tsource: PassThroughPolicyNegotiator.CLASS_NAME,\n\t\t\tts: Date.now(),\n\t\t\tmessage: \"createAgreement\",\n\t\t\tdata: {\n\t\t\t\tofferId: OdrlPolicyHelper.getUid(offer) ?? \"\"\n\t\t\t}\n\t\t});\n\n\t\tconst agreement = ObjectHelper.clone<IDataspaceProtocolPolicy>(offer);\n\n\t\tagreement[\"@type\"] = OdrlPolicyType.Agreement;\n\t\tagreement[\"@id\"] = Urn.generateRandom(RightsManagementNamespaces.Policy).toString(false);\n\t\tagreement.assignee = assignee;\n\n\t\treturn agreement as IDataspaceProtocolAgreement;\n\t}\n}\n"]}