@twin.org/rights-management-plugins 0.0.3-next.9 → 0.9.0

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 (150) hide show
  1. package/README.md +11 -3
  2. package/dist/es/index.js +20 -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/IIdentityPolicyInformationSourceConstructorOptions.js.map +1 -1
  15. package/dist/es/models/IIdentityProfilePolicyInformationSourceConstructorOptions.js +4 -0
  16. package/dist/es/models/IIdentityProfilePolicyInformationSourceConstructorOptions.js.map +1 -0
  17. package/dist/es/models/ILoggingPolicyExecutionActionConfig.js.map +1 -1
  18. package/dist/es/models/ILoggingPolicyExecutionActionConstructorOptions.js.map +1 -1
  19. package/dist/es/models/{IExampleDataAccessHandlerConstructorOptions.js → IPassThroughPolicyArbiterConstructorOptions.js} +1 -1
  20. package/dist/es/models/IPassThroughPolicyArbiterConstructorOptions.js.map +1 -0
  21. package/dist/es/models/IPassThroughPolicyEnforcementProcessorConstructorOptions.js +4 -0
  22. package/dist/es/models/IPassThroughPolicyEnforcementProcessorConstructorOptions.js.map +1 -0
  23. package/dist/es/models/IPassThroughPolicyNegotiatorConstructorOptions.js +4 -0
  24. package/dist/es/models/IPassThroughPolicyNegotiatorConstructorOptions.js.map +1 -0
  25. package/dist/es/models/IPassThroughPolicyObligationEnforcerConstructorOptions.js +4 -0
  26. package/dist/es/models/IPassThroughPolicyObligationEnforcerConstructorOptions.js.map +1 -0
  27. package/dist/es/models/{IExamplePolicyNegotiatorConstructorOptions.js → IPassThroughPolicyRequesterConstructorOptions.js} +1 -1
  28. package/dist/es/models/IPassThroughPolicyRequesterConstructorOptions.js.map +1 -0
  29. package/dist/es/models/IStaticPolicyInformationSource.js.map +1 -1
  30. package/dist/es/models/IStaticPolicyInformationSourceConstructorOptions.js.map +1 -1
  31. package/dist/es/policyArbiters/defaultPolicyArbiter.js +1790 -0
  32. package/dist/es/policyArbiters/defaultPolicyArbiter.js.map +1 -0
  33. package/dist/es/policyArbiters/passThroughPolicyArbiter.js +59 -0
  34. package/dist/es/policyArbiters/passThroughPolicyArbiter.js.map +1 -0
  35. package/dist/es/policyEnforcementProcessor/defaultPolicyEnforcementProcessor.js +147 -0
  36. package/dist/es/policyEnforcementProcessor/defaultPolicyEnforcementProcessor.js.map +1 -0
  37. package/dist/es/policyEnforcementProcessor/passThroughPolicyEnforcementProcessor.js +54 -0
  38. package/dist/es/policyEnforcementProcessor/passThroughPolicyEnforcementProcessor.js.map +1 -0
  39. package/dist/es/policyExecutionActions/automationPolicyExecutionAction.js +77 -0
  40. package/dist/es/policyExecutionActions/automationPolicyExecutionAction.js.map +1 -0
  41. package/dist/es/policyExecutionActions/loggingPolicyExecutionAction.js +22 -18
  42. package/dist/es/policyExecutionActions/loggingPolicyExecutionAction.js.map +1 -1
  43. package/dist/es/policyInformationSources/identityPolicyInformationSource.js +44 -32
  44. package/dist/es/policyInformationSources/identityPolicyInformationSource.js.map +1 -1
  45. package/dist/es/policyInformationSources/identityProfilePolicyInformationSource.js +112 -0
  46. package/dist/es/policyInformationSources/identityProfilePolicyInformationSource.js.map +1 -0
  47. package/dist/es/policyInformationSources/staticPolicyInformationSource.js +18 -16
  48. package/dist/es/policyInformationSources/staticPolicyInformationSource.js.map +1 -1
  49. package/dist/es/policyNegotiators/passThroughPolicyNegotiator.js +88 -0
  50. package/dist/es/policyNegotiators/passThroughPolicyNegotiator.js.map +1 -0
  51. package/dist/es/policyObligationEnforcers/passThroughPolicyObligationEnforcer.js +56 -0
  52. package/dist/es/policyObligationEnforcers/passThroughPolicyObligationEnforcer.js.map +1 -0
  53. package/dist/es/policyRequesters/passThroughPolicyRequester.js +103 -0
  54. package/dist/es/policyRequesters/passThroughPolicyRequester.js.map +1 -0
  55. package/dist/types/index.d.ts +20 -10
  56. package/dist/types/models/IAutomationPolicyExecutionActionConfig.d.ts +9 -0
  57. package/dist/types/models/IAutomationPolicyExecutionActionConstructorOptions.d.ts +15 -0
  58. package/dist/types/models/IDefaultPolicyArbiterConfig.d.ts +10 -0
  59. package/dist/types/models/IDefaultPolicyArbiterConstructorOptions.d.ts +19 -0
  60. package/dist/types/models/IDefaultPolicyEnforcementProcessorConstructorOptions.d.ts +9 -0
  61. package/dist/types/models/IIdentityPolicyInformationSourceConstructorOptions.d.ts +0 -1
  62. package/dist/types/models/IIdentityProfilePolicyInformationSourceConstructorOptions.d.ts +14 -0
  63. package/dist/types/models/ILoggingPolicyExecutionActionConfig.d.ts +2 -2
  64. package/dist/types/models/ILoggingPolicyExecutionActionConstructorOptions.d.ts +0 -1
  65. package/dist/types/models/IPassThroughPolicyArbiterConstructorOptions.d.ts +9 -0
  66. package/dist/types/models/IPassThroughPolicyEnforcementProcessorConstructorOptions.d.ts +9 -0
  67. package/dist/types/models/IPassThroughPolicyNegotiatorConstructorOptions.d.ts +9 -0
  68. package/dist/types/models/IPassThroughPolicyObligationEnforcerConstructorOptions.d.ts +9 -0
  69. package/dist/types/models/IPassThroughPolicyRequesterConstructorOptions.d.ts +9 -0
  70. package/dist/types/models/IStaticPolicyInformationSource.d.ts +8 -5
  71. package/dist/types/models/IStaticPolicyInformationSourceConstructorOptions.d.ts +0 -1
  72. package/dist/types/policyArbiters/defaultPolicyArbiter.d.ts +38 -0
  73. package/dist/types/policyArbiters/passThroughPolicyArbiter.d.ts +32 -0
  74. package/dist/types/policyEnforcementProcessor/defaultPolicyEnforcementProcessor.d.ts +32 -0
  75. package/dist/types/policyEnforcementProcessor/passThroughPolicyEnforcementProcessor.d.ts +32 -0
  76. package/dist/types/policyExecutionActions/automationPolicyExecutionAction.d.ts +45 -0
  77. package/dist/types/policyExecutionActions/loggingPolicyExecutionAction.d.ts +6 -18
  78. package/dist/types/policyInformationSources/identityPolicyInformationSource.d.ts +5 -6
  79. package/dist/types/policyInformationSources/identityProfilePolicyInformationSource.d.ts +31 -0
  80. package/dist/types/policyInformationSources/staticPolicyInformationSource.d.ts +5 -6
  81. package/dist/types/policyNegotiators/passThroughPolicyNegotiator.d.ts +47 -0
  82. package/dist/types/policyObligationEnforcers/passThroughPolicyObligationEnforcer.d.ts +32 -0
  83. package/dist/types/policyRequesters/passThroughPolicyRequester.d.ts +48 -0
  84. package/docs/changelog.md +1230 -10
  85. package/docs/examples.md +295 -1
  86. package/docs/reference/classes/AutomationPolicyExecutionAction.md +143 -0
  87. package/docs/reference/classes/DefaultPolicyArbiter.md +113 -0
  88. package/docs/reference/classes/DefaultPolicyEnforcementProcessor.md +107 -0
  89. package/docs/reference/classes/IdentityPolicyInformationSource.md +14 -14
  90. package/docs/reference/classes/IdentityProfilePolicyInformationSource.md +103 -0
  91. package/docs/reference/classes/LoggingPolicyExecutionAction.md +20 -20
  92. package/docs/reference/classes/PassThroughPolicyArbiter.md +103 -0
  93. package/docs/reference/classes/PassThroughPolicyEnforcementProcessor.md +107 -0
  94. package/docs/reference/classes/{ExamplePolicyNegotiator.md → PassThroughPolicyNegotiator.md} +27 -21
  95. package/docs/reference/classes/PassThroughPolicyObligationEnforcer.md +109 -0
  96. package/docs/reference/classes/{ExamplePolicyRequester.md → PassThroughPolicyRequester.md} +22 -40
  97. package/docs/reference/classes/StaticPolicyInformationSource.md +15 -15
  98. package/docs/reference/index.md +20 -10
  99. package/docs/reference/interfaces/IAutomationPolicyExecutionActionConfig.md +11 -0
  100. package/docs/reference/interfaces/IAutomationPolicyExecutionActionConstructorOptions.md +25 -0
  101. package/docs/reference/interfaces/IDefaultPolicyArbiterConfig.md +17 -0
  102. package/docs/reference/interfaces/IDefaultPolicyArbiterConstructorOptions.md +33 -0
  103. package/docs/reference/interfaces/IDefaultPolicyEnforcementProcessorConstructorOptions.md +11 -0
  104. package/docs/reference/interfaces/IIdentityPolicyInformationSourceConstructorOptions.md +4 -10
  105. package/docs/reference/interfaces/IIdentityProfilePolicyInformationSourceConstructorOptions.md +25 -0
  106. package/docs/reference/interfaces/ILoggingPolicyExecutionActionConfig.md +9 -9
  107. package/docs/reference/interfaces/ILoggingPolicyExecutionActionConstructorOptions.md +4 -10
  108. package/docs/reference/interfaces/IPassThroughPolicyArbiterConstructorOptions.md +11 -0
  109. package/docs/reference/interfaces/IPassThroughPolicyEnforcementProcessorConstructorOptions.md +11 -0
  110. package/docs/reference/interfaces/IPassThroughPolicyNegotiatorConstructorOptions.md +11 -0
  111. package/docs/reference/interfaces/IPassThroughPolicyObligationEnforcerConstructorOptions.md +11 -0
  112. package/docs/reference/interfaces/IPassThroughPolicyRequesterConstructorOptions.md +11 -0
  113. package/docs/reference/interfaces/IStaticPolicyInformationSource.md +21 -6
  114. package/docs/reference/interfaces/IStaticPolicyInformationSourceConfig.md +2 -2
  115. package/docs/reference/interfaces/IStaticPolicyInformationSourceConstructorOptions.md +4 -10
  116. package/locales/en.json +65 -6
  117. package/package.json +14 -11
  118. package/dist/es/dataAccessHandlers/examplePolicyRequester.js +0 -82
  119. package/dist/es/dataAccessHandlers/examplePolicyRequester.js.map +0 -1
  120. package/dist/es/models/IExampleDataAccessHandlerConstructorOptions.js.map +0 -1
  121. package/dist/es/models/IExamplePolicyArbiterConstructorOptions.js.map +0 -1
  122. package/dist/es/models/IExamplePolicyEnforcementProcessorConstructorOptions.js.map +0 -1
  123. package/dist/es/models/IExamplePolicyNegotiatorConstructorOptions.js.map +0 -1
  124. package/dist/es/models/IExamplePolicyRequesterConstructorOptions.js.map +0 -1
  125. package/dist/es/policyArbiters/examplePolicyArbiter.js +0 -50
  126. package/dist/es/policyArbiters/examplePolicyArbiter.js.map +0 -1
  127. package/dist/es/policyEnforcementProcessor/examplePolicyEnforcementProcessor.js +0 -42
  128. package/dist/es/policyEnforcementProcessor/examplePolicyEnforcementProcessor.js.map +0 -1
  129. package/dist/es/policyNegotiators/examplePolicyNegotiator.js +0 -61
  130. package/dist/es/policyNegotiators/examplePolicyNegotiator.js.map +0 -1
  131. package/dist/es/policyRequesters/examplePolicyRequester.js +0 -69
  132. package/dist/es/policyRequesters/examplePolicyRequester.js.map +0 -1
  133. package/dist/types/dataAccessHandlers/examplePolicyRequester.d.ts +0 -68
  134. package/dist/types/models/IExampleDataAccessHandlerConstructorOptions.d.ts +0 -10
  135. package/dist/types/models/IExamplePolicyArbiterConstructorOptions.d.ts +0 -10
  136. package/dist/types/models/IExamplePolicyEnforcementProcessorConstructorOptions.d.ts +0 -10
  137. package/dist/types/models/IExamplePolicyNegotiatorConstructorOptions.d.ts +0 -10
  138. package/dist/types/models/IExamplePolicyRequesterConstructorOptions.d.ts +0 -10
  139. package/dist/types/policyArbiters/examplePolicyArbiter.d.ts +0 -36
  140. package/dist/types/policyEnforcementProcessor/examplePolicyEnforcementProcessor.d.ts +0 -29
  141. package/dist/types/policyNegotiators/examplePolicyNegotiator.d.ts +0 -45
  142. package/dist/types/policyRequesters/examplePolicyRequester.d.ts +0 -53
  143. package/docs/reference/classes/ExampleDataAccessHandler.md +0 -243
  144. package/docs/reference/classes/ExamplePolicyArbiter.md +0 -121
  145. package/docs/reference/classes/ExamplePolicyEnforcementProcessor.md +0 -101
  146. package/docs/reference/interfaces/IExampleDataAccessHandlerConstructorOptions.md +0 -17
  147. package/docs/reference/interfaces/IExamplePolicyArbiterConstructorOptions.md +0 -17
  148. package/docs/reference/interfaces/IExamplePolicyEnforcementProcessorConstructorOptions.md +0 -17
  149. package/docs/reference/interfaces/IExamplePolicyNegotiatorConstructorOptions.md +0 -17
  150. package/docs/reference/interfaces/IExamplePolicyRequesterConstructorOptions.md +0 -17
@@ -0,0 +1,54 @@
1
+ // Copyright 2025 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { ComponentFactory, Guards } from "@twin.org/core";
4
+ import { OdrlPolicyHelper } from "@twin.org/rights-management-models";
5
+ /**
6
+ * Pass Through Policy Enforcement Processor.
7
+ */
8
+ export class PassThroughPolicyEnforcementProcessor {
9
+ /**
10
+ * The class name of the Pass Through Policy Enforcement Processor.
11
+ */
12
+ static CLASS_NAME = "PassThroughPolicyEnforcementProcessor";
13
+ /**
14
+ * The logging component.
15
+ * @internal
16
+ */
17
+ _logging;
18
+ /**
19
+ * Create a new instance of PassThroughPolicyEnforcementProcessor.
20
+ * @param options The options for the pass through policy enforcement processor.
21
+ */
22
+ constructor(options) {
23
+ this._logging = ComponentFactory.getIfExists(options?.loggingComponentType);
24
+ }
25
+ /**
26
+ * Returns the class name of the component.
27
+ * @returns The class name of the component.
28
+ */
29
+ className() {
30
+ return PassThroughPolicyEnforcementProcessor.CLASS_NAME;
31
+ }
32
+ /**
33
+ * Process the response from the policy decision point.
34
+ * @param agreement The agreement to process.
35
+ * @param decisions The decisions made by the policy decision point.
36
+ * @param data The data to process.
37
+ * @param action Optional action to make a decision on, if not provided, the arbiter will evaluate all actions in the agreement.
38
+ * @returns The data after processing.
39
+ */
40
+ async process(agreement, decisions, data, action) {
41
+ Guards.object(PassThroughPolicyEnforcementProcessor.CLASS_NAME, "agreement", agreement);
42
+ await this._logging?.log({
43
+ level: "info",
44
+ source: PassThroughPolicyEnforcementProcessor.CLASS_NAME,
45
+ ts: Date.now(),
46
+ message: "processingPolicy",
47
+ data: {
48
+ policyId: OdrlPolicyHelper.getUid(agreement) ?? ""
49
+ }
50
+ });
51
+ return data;
52
+ }
53
+ }
54
+ //# sourceMappingURL=passThroughPolicyEnforcementProcessor.js.map
@@ -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,CAAqB;IAE9C;;;OAGG;IACH,YAAY,OAAkE;QAC7E,IAAI,CAAC,QAAQ,GAAG,gBAAgB,CAAC,WAAW,CAAoB,OAAO,EAAE,oBAAoB,CAAC,CAAC;IAChG,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,EAAE,GAAG,CAAC;YACxB,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.getIfExists<ILoggingComponent>(options?.loggingComponentType);\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,77 @@
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
+ * @internal
28
+ */
29
+ _triggerActions;
30
+ /**
31
+ * Create a new instance of AutomationPolicyExecutionAction.
32
+ * @param options The options for the automation policy execution action.
33
+ */
34
+ constructor(options) {
35
+ this._automation = ComponentFactory.get(options?.automationComponentType ?? "automation");
36
+ this._triggerActions = Is.arrayValue(options?.config?.triggerActions)
37
+ ? options?.config?.triggerActions
38
+ : [OdrlActionType.Inform];
39
+ }
40
+ /**
41
+ * Returns the class name of the component.
42
+ * @returns The class name of the component.
43
+ */
44
+ className() {
45
+ return AutomationPolicyExecutionAction.CLASS_NAME;
46
+ }
47
+ /**
48
+ * Which stages should the action be executed at.
49
+ * @returns List of stages.
50
+ */
51
+ supportedStages() {
52
+ return [PolicyDecisionStage.Before, PolicyDecisionStage.After];
53
+ }
54
+ /**
55
+ * Execute function type for policy actions.
56
+ * @param policy The policy that applied to the data.
57
+ * @param decisions The decisions made by the PDP.
58
+ * @param data The data to process.
59
+ * @param action Optional action to make a decision on, if not provided, the arbiter will evaluate all actions in the agreement.
60
+ * @param stage The stage of the policy decision.
61
+ * @returns A promise that resolves when the action is complete.
62
+ */
63
+ async execute(policy, decisions, data, action, stage) {
64
+ Guards.arrayOneOf(AutomationPolicyExecutionAction.CLASS_NAME, "stage", stage, Object.values(PolicyDecisionStage));
65
+ if (Is.stringValue(action) && this._triggerActions.includes(action)) {
66
+ await this._automation.trigger(stage === PolicyDecisionStage.Before
67
+ ? AutomationPolicyExecutionAction.BEFORE_TRIGGER_NAME
68
+ : AutomationPolicyExecutionAction.AFTER_TRIGGER_NAME, {
69
+ policy,
70
+ decisions,
71
+ data,
72
+ action
73
+ });
74
+ }
75
+ }
76
+ }
77
+ //# 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,M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S;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 * @internal\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
  */
@@ -22,14 +22,17 @@ export class LoggingPolicyExecutionAction {
22
22
  _stages;
23
23
  /**
24
24
  * Whether to include the data in the log.
25
+ * @internal
25
26
  */
26
27
  _includeData;
27
28
  /**
28
- * Whether to include the policies in the log.
29
+ * Whether to include the policy in the log.
30
+ * @internal
29
31
  */
30
- _includePolicies;
32
+ _includePolicy;
31
33
  /**
32
34
  * Whether to include the decisions in the log.
35
+ * @internal
33
36
  */
34
37
  _includeDecisions;
35
38
  /**
@@ -37,13 +40,13 @@ export class LoggingPolicyExecutionAction {
37
40
  * @param options The options for the logging policy execution action.
38
41
  */
39
42
  constructor(options) {
40
- this._logging = ComponentFactory.get(options?.loggingComponentType ?? "logging");
43
+ this._logging = ComponentFactory.getIfExists(options?.loggingComponentType);
41
44
  this._stages = options?.config?.stages ?? [
42
45
  PolicyDecisionStage.Before,
43
46
  PolicyDecisionStage.After
44
47
  ];
45
48
  this._includeData = options?.config?.includeData ?? false;
46
- this._includePolicies = options?.config?.includePolicies ?? false;
49
+ this._includePolicy = options?.config?.includePolicy ?? false;
47
50
  this._includeDecisions = options?.config?.includeDecisions ?? false;
48
51
  }
49
52
  /**
@@ -62,51 +65,52 @@ export class LoggingPolicyExecutionAction {
62
65
  }
63
66
  /**
64
67
  * 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.
68
+ * @param policy The policy that applied to the data.
68
69
  * @param decisions The decisions made by the PDP.
69
70
  * @param data The data to process.
71
+ * @param action Optional action to make a decision on, if not provided, the arbiter will evaluate all actions in the agreement.
72
+ * @param stage The stage of the policy decision.
70
73
  * @returns A promise that resolves when the action is complete.
71
74
  */
72
- async execute(stage, locator, policies, decisions, data) {
75
+ async execute(policy, decisions, data, action, stage) {
73
76
  Guards.arrayOneOf(LoggingPolicyExecutionAction.CLASS_NAME, "stage", stage, Object.values(PolicyDecisionStage));
74
- Guards.object(LoggingPolicyExecutionAction.CLASS_NAME, "locator", locator);
75
77
  if (this._stages.includes(stage)) {
76
- // Even if we don't have the options to include data or include policies we
78
+ // Even if we don't have the options to include data or include policy we
77
79
  // still create dummy entries, as the logging string still has them embedded
78
80
  let logData;
79
81
  if (!Is.empty(data)) {
80
82
  logData = this._includeData ? data : "{...}";
81
83
  }
82
- const logPolicies = this._includePolicies ? policies : "[...]";
84
+ const logPolicy = this._includePolicy ? policy : "{}";
83
85
  const logDecisions = this._includeDecisions ? decisions : "[...]";
84
86
  if (stage === PolicyDecisionStage.Before) {
85
- await this._logging.log({
87
+ await this._logging?.log({
86
88
  level: "info",
87
89
  source: LoggingPolicyExecutionAction.CLASS_NAME,
88
90
  ts: Date.now(),
89
91
  message: "policyActionExecutedBefore",
90
92
  data: {
91
- locator: LocatorHelper.toString(locator),
93
+ policyId: OdrlPolicyHelper.getUid(policy) ?? "",
92
94
  data: logData,
93
- policies: logPolicies,
95
+ policy: logPolicy,
94
96
  decisions: logDecisions,
97
+ action,
95
98
  stage
96
99
  }
97
100
  });
98
101
  }
99
102
  else {
100
- await this._logging.log({
103
+ await this._logging?.log({
101
104
  level: "info",
102
105
  source: LoggingPolicyExecutionAction.CLASS_NAME,
103
106
  ts: Date.now(),
104
107
  message: "policyActionExecutedAfter",
105
108
  data: {
106
- locator: LocatorHelper.toString(locator),
109
+ policyId: OdrlPolicyHelper.getUid(policy) ?? "",
107
110
  data: logData,
108
- policies: logPolicies,
111
+ policy: logPolicy,
109
112
  decisions: logDecisions,
113
+ action,
110
114
  stage
111
115
  }
112
116
  });
@@ -1 +1 @@
1
- {"version":3,"file":"loggingPolicyExecutionAction.js","sourceRoot":"","sources":["../../../src/policyExecutionActions/loggingPolicyExecutionAction.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,gBAAgB,E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E,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,CAAC;AAG9D,OAAO,EAIN,gBAAgB,EAChB,mBAAmB,EACnB,MAAM,oCAAoC,CAAC;AAI5C;;GAEG;AACH,MAAM,OAAO,4BAA4B;IACxC;;OAEG;IACI,MAAM,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ACF,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 * @internal\n\t */\n\tprivate readonly _includeData: boolean;\n\n\t/**\n\t * Whether to include the policy in the log.\n\t * @internal\n\t */\n\tprivate readonly _includePolicy: boolean;\n\n\t/**\n\t * Whether to include the decisions in the log.\n\t * @internal\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.getIfExists<ILoggingComponent>(options?.loggingComponentType);\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
  */
@@ -25,7 +26,7 @@ export class IdentityPolicyInformationSource {
25
26
  * @param options The options for the logging policy source.
26
27
  */
27
28
  constructor(options) {
28
- this._logging = ComponentFactory.getIfExists(options?.loggingComponentType ?? "logging");
29
+ this._logging = ComponentFactory.getIfExists(options?.loggingComponentType);
29
30
  this._identityResolver = ComponentFactory.get(options?.identityResolverComponentType ?? "identity-resolver");
30
31
  }
31
32
  /**
@@ -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;IAC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AAC;QAED,OAAO,WAAW,CAAC;IACpB,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseError, ComponentFactory, 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/identityPolicyInformationSource.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAItD,OAAO,EAIN,gBAAgB,EAChB,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,CAAoB,OAAO,EAAE,oBAAoB,CAAC,CAAC;QAC/F,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,MAA2C,EAC3C,UAAuC,EACvC,IAAQ,EACR,MAAgC;QAEhC,MAAM,CAAC,UAAU,CAChB,+BAA+B,CAAC,UAAU,gBAE1C,UAAU,EACV,MAAM,CAAC,MAAM,CAAC,2BAA2B,CAAC,CAC1C,CAAC;QAEF,MAAM,WAAW,GAAiC,EAAE,CAAC;QAErD,IAAI,EAAE,CAAC,MAAM,CAA0B,MAAM,CAAC,EAAE,CAAC;YAChD,MAAM,GAAG,GAAG,EAAE,CAAC;YAEf,IAAI,EAAE,CAAC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gBACJ,CAAC;YACF,CAAC;QACF,CAAC;QAED,OAAO,WAAW,CAAC;IACpB,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseError, ComponentFactory, Guards, Is } from \"@twin.org/core\";\nimport { 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 IRightsManagementInformation,\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>(options?.loggingComponentType);\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<IRightsManagementInformation | 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: IRightsManagementInformation = {};\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"]}
@@ -0,0 +1,112 @@
1
+ // Copyright 2025 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { BaseError, ComponentFactory, Guards, Is, NotFoundError } from "@twin.org/core";
4
+ import { JsonLdHelper } from "@twin.org/data-json-ld";
5
+ import { OdrlPolicyHelper, PolicyInformationAccessMode } from "@twin.org/rights-management-models";
6
+ /**
7
+ * Policy information source which retrieves identity profile information.
8
+ */
9
+ export class IdentityProfilePolicyInformationSource {
10
+ /**
11
+ * The class name of the Identity Profile Policy Information Source.
12
+ */
13
+ static CLASS_NAME = "IdentityProfilePolicyInformationSource";
14
+ /**
15
+ * The logging component.
16
+ * @internal
17
+ */
18
+ _logging;
19
+ /**
20
+ * The identity profile component.
21
+ * @internal
22
+ */
23
+ _identityProfile;
24
+ /**
25
+ * Create a new instance of IdentityProfilePolicyInformationSource.
26
+ * @param options The options for the identity profile policy source.
27
+ */
28
+ constructor(options) {
29
+ this._logging = ComponentFactory.getIfExists(options?.loggingComponentType);
30
+ this._identityProfile = ComponentFactory.get(options?.identityProfileComponentType ?? "identity-profile");
31
+ }
32
+ /**
33
+ * Returns the class name of the component.
34
+ * @returns The class name of the component.
35
+ */
36
+ className() {
37
+ return IdentityProfilePolicyInformationSource.CLASS_NAME;
38
+ }
39
+ /**
40
+ * Retrieve information from the sources.
41
+ * @param policy The policy to retrieve information for if available.
42
+ * @param accessMode The access mode to use for the retrieval.
43
+ * @param data The data to process.
44
+ * @param action The action that was evaluated.
45
+ * @returns The objects containing relevant information or undefined if nothing relevant is found.
46
+ */
47
+ async retrieve(policy, accessMode, data, action) {
48
+ Guards.arrayOneOf(IdentityProfilePolicyInformationSource.CLASS_NAME, "accessMode", accessMode, Object.values(PolicyInformationAccessMode));
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: IdentityProfilePolicyInformationSource.CLASS_NAME,
63
+ ts: Date.now(),
64
+ message: "profileRetrieving",
65
+ data: {
66
+ policyId: OdrlPolicyHelper.getUid(policy) ?? "",
67
+ id
68
+ }
69
+ });
70
+ const profile = information.profile ?? {};
71
+ if (accessMode === PolicyInformationAccessMode.Public) {
72
+ const publicProfile = await this._identityProfile.getPublic(id);
73
+ profile[id] = {
74
+ public: Is.object(publicProfile)
75
+ ? JsonLdHelper.toNodeObject(publicProfile)
76
+ : undefined
77
+ };
78
+ }
79
+ else {
80
+ const result = await this._identityProfile.get(undefined, undefined, id);
81
+ profile[id] = {
82
+ public: Is.object(result.publicProfile)
83
+ ? JsonLdHelper.toNodeObject(result.publicProfile)
84
+ : undefined,
85
+ private: Is.object(result.privateProfile)
86
+ ? JsonLdHelper.toNodeObject(result.privateProfile)
87
+ : undefined
88
+ };
89
+ }
90
+ information.profile = profile;
91
+ }
92
+ catch (err) {
93
+ if (!BaseError.someErrorName(err, NotFoundError.CLASS_NAME)) {
94
+ await this._logging?.log({
95
+ level: "error",
96
+ source: IdentityProfilePolicyInformationSource.CLASS_NAME,
97
+ ts: Date.now(),
98
+ message: "profileRetrievalFailed",
99
+ data: {
100
+ policyId: OdrlPolicyHelper.getUid(policy) ?? "",
101
+ id
102
+ },
103
+ error: BaseError.fromError(err)
104
+ });
105
+ }
106
+ }
107
+ }
108
+ }
109
+ return information;
110
+ }
111
+ }
112
+ //# sourceMappingURL=identityProfilePolicyInformationSource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identityProfilePolicyInformationSource.js","sourceRoot":"","sources":["../../../src/policyInformationSources/identityProfilePolicyInformationSource.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,EAAE,EAAE,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACxF,OAAO,EAA0B,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAI9E,OAAO,EACN,gBAAgB,EAChB,2BAA2B,EAI3B,MAAM,oCAAoC,CAAC;AAI5C;;GAEG;AACH,MAAM,OAAO,sCAAsC;IAClD;;OAEG;IACI,MAAM,CAAU,UAAU,4CAA4D;IAE7F;;;OAGG;IACc,QAAQ,CAAqB;IAE9C;;;OAGG;IACc,gBAAgB,CAA4B;IAE7D;;;OAGG;IACH,YAAY,OAAmE;QAC9E,IAAI,CAAC,QAAQ,GAAG,gBAAgB,CAAC,WAAW,CAAoB,OAAO,EAAE,oBAAoB,CAAC,CAAC;QAC/F,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC,GAAG,CAC3C,OAAO,EAAE,4BAA4B,IAAI,kBAAkB,CAC3D,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,sCAAsC,CAAC,UAAU,CAAC;IAC1D,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,QAAQ,CACpB,MAA2C,EAC3C,UAAuC,EACvC,IAAQ,EACR,MAAgC;QAEhC,MAAM,CAAC,UAAU,CAChB,sCAAsC,CAAC,UAAU,gBAEjD,UAAU,EACV,MAAM,CAAC,MAAM,CAAC,2BAA2B,CAAC,CAC1C,CAAC;QAEF,MAAM,WAAW,GAAiC,EAAE,CAAC;QAErD,IAAI,EAAE,CAAC,MAAM,CAA0B,MAAM,CAAC,EAAE,CAAC;YAChD,MAAM,GAAG,GAAG,E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,CAAC,EAAE,CAAC,GAAG;4BACb,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC;gCACtC,CAAC,CAAC,YAAY,CAAC,YAAY,CAAC,MAAM,CAAC,aAAa,CAAC;gCACjD,CAAC,CAAC,SAAS;4BACZ,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC;gCACxC,CAAC,CAAC,YAAY,CAAC,YAAY,CAAC,MAAM,CAAC,cAAc,CAAC;gCAClD,CAAC,CAAC,SAAS;yBACZ,CAAC;oBACH,CAAC;oBACD,WAAW,CAAC,OAAO,GAAG,OAAO,CAAC;gBAC/B,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACd,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,aAAa,CAAC,UAAU,CAAC,EAAE,CAAC;wBAC7D,MAAM,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC;4BACxB,KAAK,EAAE,OAAO;4BACd,MAAM,EAAE,sCAAsC,CAAC,UAAU;4BACzD,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE;4BACd,OAAO,EAAE,wBAAwB;4BACjC,IAAI,EAAE;gCACL,QAAQ,EAAE,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;gCAC/C,EAAE;6BACF;4BACD,KAAK,EAAE,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC;yBAC/B,CAAC,CAAC;oBACJ,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;QAED,OAAO,WAAW,CAAC;IACpB,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseError, ComponentFactory, Guards, Is, NotFoundError } from \"@twin.org/core\";\nimport { type IJsonLdNodeObject, JsonLdHelper } from \"@twin.org/data-json-ld\";\nimport type { IIdentityProfileComponent } from \"@twin.org/identity-models\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tOdrlPolicyHelper,\n\tPolicyInformationAccessMode,\n\ttype IPolicyInformationSource,\n\ttype IRightsManagementInformation,\n\ttype IRightsManagementPolicy\n} from \"@twin.org/rights-management-models\";\nimport type { OdrlActionType } from \"@twin.org/standards-w3c-odrl\";\nimport type { IIdentityProfilePolicyInformationSourceConstructorOptions } from \"../models/IIdentityProfilePolicyInformationSourceConstructorOptions.js\";\n\n/**\n * Policy information source which retrieves identity profile information.\n */\nexport class IdentityProfilePolicyInformationSource implements IPolicyInformationSource {\n\t/**\n\t * The class name of the Identity Profile Policy Information Source.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<IdentityProfilePolicyInformationSource>();\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 profile component.\n\t * @internal\n\t */\n\tprivate readonly _identityProfile: IIdentityProfileComponent;\n\n\t/**\n\t * Create a new instance of IdentityProfilePolicyInformationSource.\n\t * @param options The options for the identity profile policy source.\n\t */\n\tconstructor(options?: IIdentityProfilePolicyInformationSourceConstructorOptions) {\n\t\tthis._logging = ComponentFactory.getIfExists<ILoggingComponent>(options?.loggingComponentType);\n\t\tthis._identityProfile = ComponentFactory.get(\n\t\t\toptions?.identityProfileComponentType ?? \"identity-profile\"\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 IdentityProfilePolicyInformationSource.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<IRightsManagementInformation | undefined> {\n\t\tGuards.arrayOneOf(\n\t\t\tIdentityProfilePolicyInformationSource.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: IRightsManagementInformation = {};\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: IdentityProfilePolicyInformationSource.CLASS_NAME,\n\t\t\t\t\t\tts: Date.now(),\n\t\t\t\t\t\tmessage: \"profileRetrieving\",\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\n\t\t\t\t\tconst profile = (information.profile as { [id: string]: IJsonLdNodeObject }) ?? {};\n\n\t\t\t\t\tif (accessMode === PolicyInformationAccessMode.Public) {\n\t\t\t\t\t\tconst publicProfile = await this._identityProfile.getPublic(id);\n\t\t\t\t\t\tprofile[id] = {\n\t\t\t\t\t\t\tpublic: Is.object(publicProfile)\n\t\t\t\t\t\t\t\t? JsonLdHelper.toNodeObject(publicProfile)\n\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t};\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst result = await this._identityProfile.get(undefined, undefined, id);\n\t\t\t\t\t\tprofile[id] = {\n\t\t\t\t\t\t\tpublic: Is.object(result.publicProfile)\n\t\t\t\t\t\t\t\t? JsonLdHelper.toNodeObject(result.publicProfile)\n\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t\tprivate: Is.object(result.privateProfile)\n\t\t\t\t\t\t\t\t? JsonLdHelper.toNodeObject(result.privateProfile)\n\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tinformation.profile = profile;\n\t\t\t\t} catch (err) {\n\t\t\t\t\tif (!BaseError.someErrorName(err, NotFoundError.CLASS_NAME)) {\n\t\t\t\t\t\tawait this._logging?.log({\n\t\t\t\t\t\t\tlevel: \"error\",\n\t\t\t\t\t\t\tsource: IdentityProfilePolicyInformationSource.CLASS_NAME,\n\t\t\t\t\t\t\tts: Date.now(),\n\t\t\t\t\t\t\tmessage: \"profileRetrievalFailed\",\n\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\tpolicyId: OdrlPolicyHelper.getUid(policy) ?? \"\",\n\t\t\t\t\t\t\t\tid\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\terror: BaseError.fromError(err)\n\t\t\t\t\t\t});\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"]}