@twin.org/rights-management-models 0.0.3-next.30 → 0.0.3-next.32

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.
@@ -1 +1 @@
1
- {"version":3,"file":"IPolicyNegotiation.js","sourceRoot":"","sources":["../../../../src/models/pnp/IPolicyNegotiation.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IError } from \"@twin.org/core\";\nimport type {\n\tDataspaceProtocolContractNegotiationStateType,\n\tIDataspaceProtocolAgreement,\n\tIDataspaceProtocolOffer\n} from \"@twin.org/standards-dataspace-protocol\";\nimport type { ITrustVerificationInfo } from \"@twin.org/trust-models\";\n\n/**\n * Interface describing a rights management policy negotiation.\n */\nexport interface IPolicyNegotiation {\n\t/**\n\t * The primary id used by the provider.\n\t */\n\tid: string;\n\n\t/**\n\t * This is used by the other side of the negotiation.\n\t */\n\tcorrelationId: string;\n\n\t/**\n\t * The unique identifier for the policy.\n\t */\n\tpolicyId?: string;\n\n\t/**\n\t * The date and time when the negotiation was created.\n\t */\n\tdateCreated: string;\n\n\t/**\n\t * The expiration time for the policy negotiation if it's a manual process.\n\t */\n\texpires?: number;\n\n\t/**\n\t * The status of the negotiation.\n\t */\n\tstate: DataspaceProtocolContractNegotiationStateType;\n\n\t/**\n\t * The callback address to send updates to the requester.\n\t */\n\tcallbackAddress?: string;\n\n\t/**\n\t * The public origin of the server that initiated or received this negotiation.\n\t * Used to construct callback URLs in subsequent async messages.\n\t */\n\tpublicOrigin?: string;\n\n\t/**\n\t * Organization identity to be used when sending trust payloads.\n\t */\n\torganizationIdentity: string;\n\n\t/**\n\t * The offer being requested.\n\t */\n\toffer?: IDataspaceProtocolOffer;\n\n\t/**\n\t * The agreement being established if the negotiation was successful.\n\t */\n\tagreement?: IDataspaceProtocolAgreement;\n\n\t/**\n\t * The information from the trust provider.\n\t */\n\ttrustVerificationInfo?: ITrustVerificationInfo;\n\n\t/**\n\t * A reason code for when the negotiation errors.\n\t */\n\tcode?: string;\n\n\t/**\n\t * A more detailed reason for the negotiation error.\n\t */\n\treason?: {\n\t\t\"@value\": string;\n\t\t\"@language\"?: string;\n\t}[];\n\n\t/**\n\t * A more detailed reason for the negotiation error.\n\t */\n\tdescription?: {\n\t\t\"@value\": string;\n\t\t\"@language\"?: string;\n\t}[];\n\n\t/**\n\t * Any additional error details that don't fit in the reason or description fields.\n\t */\n\terrorDetails?: IError;\n\n\t/**\n\t * The id of the handler, on provider side this is the negotiator, on consumer side this is the requester.\n\t */\n\thandlerId?: string;\n\n\t/**\n\t * Is manual intervention required to complete the negotiation?\n\t */\n\tinterventionRequired?: boolean;\n}\n"]}
1
+ {"version":3,"file":"IPolicyNegotiation.js","sourceRoot":"","sources":["../../../../src/models/pnp/IPolicyNegotiation.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IError } from \"@twin.org/core\";\nimport type {\n\tDataspaceProtocolContractNegotiationStateType,\n\tIDataspaceProtocolAgreement,\n\tIDataspaceProtocolOffer\n} from \"@twin.org/standards-dataspace-protocol\";\nimport type { ITrustVerificationInfo } from \"@twin.org/trust-models\";\n\n/**\n * Interface describing a rights management policy negotiation.\n */\nexport interface IPolicyNegotiation {\n\t/**\n\t * The primary id used by the provider.\n\t */\n\tid: string;\n\n\t/**\n\t * This is used by the other side of the negotiation.\n\t */\n\tcorrelationId: string;\n\n\t/**\n\t * The unique identifier for the policy.\n\t */\n\tpolicyId?: string;\n\n\t/**\n\t * The date and time when the negotiation was created.\n\t */\n\tdateCreated: string;\n\n\t/**\n\t * The expiration time for the policy negotiation if it's a manual process.\n\t */\n\texpires?: number;\n\n\t/**\n\t * The status of the negotiation.\n\t */\n\tstate: DataspaceProtocolContractNegotiationStateType;\n\n\t/**\n\t * The callback address to send updates to the requester.\n\t */\n\tcallbackAddress?: string;\n\n\t/**\n\t * The public origin of the server that initiated or received this negotiation.\n\t * Used to construct callback URLs in subsequent async messages.\n\t */\n\tpublicOrigin?: string;\n\n\t/**\n\t * The tenant id this negotiation belongs to.\n\t */\n\ttenantId?: string;\n\n\t/**\n\t * Organization identity to be used when sending trust payloads.\n\t */\n\torganizationIdentity: string;\n\n\t/**\n\t * The offer being requested.\n\t */\n\toffer?: IDataspaceProtocolOffer;\n\n\t/**\n\t * The agreement being established if the negotiation was successful.\n\t */\n\tagreement?: IDataspaceProtocolAgreement;\n\n\t/**\n\t * The information from the trust provider.\n\t */\n\ttrustVerificationInfo?: ITrustVerificationInfo;\n\n\t/**\n\t * A reason code for when the negotiation errors.\n\t */\n\tcode?: string;\n\n\t/**\n\t * A more detailed reason for the negotiation error.\n\t */\n\treason?: {\n\t\t\"@value\": string;\n\t\t\"@language\"?: string;\n\t}[];\n\n\t/**\n\t * A more detailed reason for the negotiation error.\n\t */\n\tdescription?: {\n\t\t\"@value\": string;\n\t\t\"@language\"?: string;\n\t}[];\n\n\t/**\n\t * Any additional error details that don't fit in the reason or description fields.\n\t */\n\terrorDetails?: IError;\n\n\t/**\n\t * The id of the handler, on provider side this is the negotiator, on consumer side this is the requester.\n\t */\n\thandlerId?: string;\n\n\t/**\n\t * Is manual intervention required to complete the negotiation?\n\t */\n\tinterventionRequired?: boolean;\n}\n"]}
@@ -103,6 +103,19 @@ export class OdrlPolicyHelper {
103
103
  }
104
104
  return ids;
105
105
  }
106
+ /**
107
+ * Get the dataset targets from policy.
108
+ * @param policy The policy to extract the dataset targets from.
109
+ * @returns Top-level targets (deduped).
110
+ */
111
+ static getDatasetTargets(policy) {
112
+ const targetIds = [];
113
+ const policyTargets = ArrayHelper.fromObjectOrArray(policy.target ?? []);
114
+ for (const target of policyTargets) {
115
+ OdrlPolicyHelper.collectTarget(target, targetIds);
116
+ }
117
+ return Array.from(new Set(targetIds));
118
+ }
106
119
  /**
107
120
  * Get targets from policy.
108
121
  * Walks both the policy-level target field and the target field on every
@@ -112,11 +125,7 @@ export class OdrlPolicyHelper {
112
125
  * @returns Targets.
113
126
  */
114
127
  static getTargets(policy) {
115
- const targetIds = [];
116
- const policyTargets = ArrayHelper.fromObjectOrArray(policy.target ?? []);
117
- for (const target of policyTargets) {
118
- OdrlPolicyHelper.collectTarget(target, targetIds);
119
- }
128
+ const targetIds = OdrlPolicyHelper.getDatasetTargets(policy);
120
129
  const rules = OdrlPolicyHelper.collectRules(policy);
121
130
  for (const rule of rules) {
122
131
  const ruleTargets = ArrayHelper.fromObjectOrArray(rule.target ?? []);
@@ -1 +1 @@
1
- {"version":3,"file":"odrlPolicyHelper.js","sourceRoot":"","sources":["../../../src/utils/odrlPolicyHelper.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAiBrF;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAC5B;;OAEG;IACI,MAAM,CAAU,UAAU,sBAAsC;IAEvE;;;;OAIG;IACI,MAAM,CAAC,MAAM,CAAC,MAA0B;QAC9C,OAAO,YAAY,CAAC,eAAe,CAAS,MAAM,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;IAClF,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,OAAO,CAAC,MAA0B;QAC/C,OAAO,YAAY,CAAC,eAAe,CAAS,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC;IAC/E,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,uBAAuB,CAAC,MAAgC;QACrE,IAAI,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,YAAY,CAAC,gBAAgB,CAAC,UAAU,EAAE,uBAAuB,EAAE;gBAC5E,UAAU,EAAE,gBAAgB,CAAC,OAAO,CAAC,MAAM,C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,CAAC,MAAM,CAAC,CAAC;YAC5C,IAAI,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC;gBACzB,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACvB,CAAC;QACF,CAAC;aAAM,IAAI,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC;YACnC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1B,CAAC;IACF,CAAC;IAED;;;;;OAKG;IACK,MAAM,CAAC,aAAa,CAC3B,MAA6C,EAC7C,WAAqB;QAErB,IAAI,EAAE,CAAC,MAAM,CAAc,MAAM,CAAC,EAAE,CAAC;YACpC,MAAM,GAAG,GAAG,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC5C,IAAI,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC;gBACzB,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACvB,CAAC;QACF,CAAC;aAAM,IAAI,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC;YACnC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1B,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ObjectOrArray } from \"@twin.org/core\";\nimport { ArrayHelper, GeneralError, Guards, Is, ObjectHelper } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IDataspaceProtocolPolicy } from \"@twin.org/standards-dataspace-protocol\";\nimport type {\n\tIOdrlAction,\n\tIOdrlAsset,\n\tIOdrlAssetCollection,\n\tIOdrlDuty,\n\tIOdrlParty,\n\tIOdrlPartyCollection,\n\tIOdrlPermission,\n\tIOdrlProhibition,\n\tIOdrlRule,\n\tOdrlActionType\n} from \"@twin.org/standards-w3c-odrl\";\nimport type { IRightsManagementPolicy } from \"../models/IRightsManagementPolicy.js\";\n\n/**\n * Helper methods for Odrl Policies.\n */\nexport class OdrlPolicyHelper {\n\t/**\n\t * The class name of the Policy Administration Point Service.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<OdrlPolicyHelper>();\n\n\t/**\n\t * Get the UID of an ODRL policy or related object if available.\n\t * @param object The ODRL policy or related object to get the UID from.\n\t * @returns The UID of the object if available, otherwise undefined.\n\t */\n\tpublic static getUid(object: object | undefined): string | undefined {\n\t\treturn ObjectHelper.extractProperty<string>(object, [\"@id\", \"id\", \"uid\"], false);\n\t}\n\n\t/**\n\t * Get the type of an ODRL policy or related object if available.\n\t * @param object The ODRL policy or related object to get the type from.\n\t * @returns The type of the object if available, otherwise undefined.\n\t */\n\tpublic static getType(object: object | undefined): string | undefined {\n\t\treturn ObjectHelper.extractProperty<string>(object, [\"@type\", \"type\"], false);\n\t}\n\n\t/**\n\t * Extract assignee identity from policy.\n\t * @param policy The policy to extract the assignee from.\n\t * @returns Assignee id.\n\t * @throws GeneralError if assignee is missing or invalid.\n\t */\n\tpublic static extractAssigneeIdentity(policy: IDataspaceProtocolPolicy): ObjectOrArray<string> {\n\t\tif (Is.empty(policy.assignee)) {\n\t\t\tthrow new GeneralError(OdrlPolicyHelper.CLASS_NAME, \"policyMissingAssignee\", {\n\t\t\t\tpolicyType: OdrlPolicyHelper.getType(policy) ?? \"\",\n\t\t\t\tpolicyId: OdrlPolicyHelper.getUid(policy) ?? \"\"\n\t\t\t});\n\t\t}\n\n\t\tconst assignees = ArrayHelper.fromObjectOrArray(policy.assignee);\n\t\tconst assigneeIds: string[] = [];\n\t\tfor (const assignee of assignees) {\n\t\t\tconst assigneeId = Is.string(assignee) ? assignee : OdrlPolicyHelper.getUid(assignee);\n\t\t\tGuards.stringValue(OdrlPolicyHelper.CLASS_NAME, nameof(assigneeId), assigneeId);\n\t\t\tassigneeIds.push(assigneeId);\n\t\t}\n\n\t\treturn assigneeIds.length <= 1 ? assigneeIds[0] : assigneeIds;\n\t}\n\n\t/**\n\t * Extract assigner identity from policy.\n\t * @param policy The policy to extract the assigner from.\n\t * @returns Assigner id.\n\t * @throws GeneralError if assigner is missing or invalid.\n\t */\n\tpublic static extractAssignerIdentity(policy: IDataspaceProtocolPolicy): ObjectOrArray<string> {\n\t\tif (Is.empty(policy.assigner)) {\n\t\t\tthrow new GeneralError(OdrlPolicyHelper.CLASS_NAME, \"policyMissingAssigner\", {\n\t\t\t\tpolicyType: OdrlPolicyHelper.getType(policy) ?? \"\",\n\t\t\t\tpolicyId: OdrlPolicyHelper.getUid(policy) ?? \"\"\n\t\t\t});\n\t\t}\n\n\t\tconst assigners = ArrayHelper.fromObjectOrArray(policy.assigner);\n\t\tconst assignerIds: string[] = [];\n\n\t\tfor (const assigner of assigners) {\n\t\t\tconst assignerId = Is.string(assigner) ? assigner : OdrlPolicyHelper.getUid(assigner);\n\t\t\tGuards.stringValue(OdrlPolicyHelper.CLASS_NAME, nameof(assignerId), assignerId);\n\t\t\tassignerIds.push(assignerId);\n\t\t}\n\n\t\treturn assignerIds.length <= 1 ? assignerIds[0] : assignerIds;\n\t}\n\n\t/**\n\t * Normalize party value(s) into identifier strings when possible.\n\t * Handles single parties or arrays of parties by returning all discovered identifiers.\n\t * @param party The party to normalize.\n\t * @returns The party identifiers, or undefined when not available.\n\t */\n\tpublic static getPartyIds(\n\t\tparty?:\n\t\t\t| string\n\t\t\t| IOdrlParty\n\t\t\t| IOdrlPartyCollection\n\t\t\t| (string | IOdrlParty | IOdrlPartyCollection)[]\n\t): string[] {\n\t\tconst ids: string[] = [];\n\n\t\tif (Is.empty(party)) {\n\t\t\treturn ids;\n\t\t}\n\n\t\tif (Is.stringValue(party)) {\n\t\t\tids.push(party);\n\t\t\treturn ids;\n\t\t}\n\n\t\tif (Is.arrayValue(party)) {\n\t\t\tfor (const item of party) {\n\t\t\t\tconst childIds = OdrlPolicyHelper.getPartyIds(item);\n\t\t\t\tif (!Is.empty(childIds)) {\n\t\t\t\t\tfor (const childId of childIds) {\n\t\t\t\t\t\tif (!ids.includes(childId)) {\n\t\t\t\t\t\t\tids.push(childId);\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\treturn ids;\n\t\t}\n\n\t\tif (Is.object<IOdrlParty>(party)) {\n\t\t\tconst uid = OdrlPolicyHelper.getUid(party);\n\t\t\tif (Is.stringValue(uid) && !ids.includes(uid)) {\n\t\t\t\tids.push(uid);\n\t\t\t}\n\t\t}\n\n\t\treturn ids;\n\t}\n\n\t/**\n\t * Get targets from policy.\n\t * Walks both the policy-level target field and the target field on every\n\t * permission, prohibition, and obligation rule so that policies that store\n\t * their target exclusively on a rule are correctly indexed for query().\n\t * @param policy The policy to extract the targets from.\n\t * @returns Targets.\n\t */\n\tpublic static getTargets(policy: IRightsManagementPolicy): string[] {\n\t\tconst targetIds: string[] = [];\n\n\t\tconst policyTargets = ArrayHelper.fromObjectOrArray<IOdrlAsset | IOdrlAssetCollection | string>(\n\t\t\tpolicy.target ?? []\n\t\t);\n\t\tfor (const target of policyTargets) {\n\t\t\tOdrlPolicyHelper.collectTarget(target, targetIds);\n\t\t}\n\n\t\tconst rules = OdrlPolicyHelper.collectRules(policy);\n\t\tfor (const rule of rules) {\n\t\t\tconst ruleTargets = ArrayHelper.fromObjectOrArray<IOdrlAsset | IOdrlAssetCollection | string>(\n\t\t\t\trule.target ?? []\n\t\t\t);\n\t\t\tfor (const target of ruleTargets) {\n\t\t\t\tOdrlPolicyHelper.collectTarget(target, targetIds);\n\t\t\t}\n\t\t}\n\n\t\treturn Array.from(new Set(targetIds));\n\t}\n\n\t/**\n\t * Get actions from policy.\n\t * Walks both the policy-level action field and the action field on every\n\t * permission, prohibition, and obligation rule so that policies that store\n\t * their action exclusively on a rule are correctly indexed for query().\n\t * @param policy The policy to extract the actions from.\n\t * @returns Actions.\n\t */\n\tpublic static getActions(policy: IRightsManagementPolicy): string[] {\n\t\tconst actions: string[] = [];\n\n\t\tconst policyActions = ArrayHelper.fromObjectOrArray<OdrlActionType | string | IOdrlAction>(\n\t\t\tpolicy.action ?? []\n\t\t);\n\t\tfor (const action of policyActions) {\n\t\t\tOdrlPolicyHelper.collectAction(action, actions);\n\t\t}\n\n\t\tconst rules = OdrlPolicyHelper.collectRules(policy);\n\t\tfor (const rule of rules) {\n\t\t\tconst ruleActions = ArrayHelper.fromObjectOrArray<OdrlActionType | string | IOdrlAction>(\n\t\t\t\trule.action ?? []\n\t\t\t);\n\t\t\tfor (const action of ruleActions) {\n\t\t\t\tOdrlPolicyHelper.collectAction(action, actions);\n\t\t\t}\n\t\t}\n\n\t\treturn Array.from(new Set(actions));\n\t}\n\n\t/**\n\t * Does the policy match.\n\t * @param policy The policy to try and match.\n\t * @param options The matching options.\n\t * @param options.assignee The assignee to match.\n\t * @param options.assigner The assigner to match.\n\t * @param options.target The target to match.\n\t * @param options.action The action to match.\n\t * @returns True if the policy matches.\n\t */\n\tpublic static matchPolicy(\n\t\tpolicy: IRightsManagementPolicy | undefined,\n\t\toptions: {\n\t\t\tassignee?: string;\n\t\t\tassigner?: string;\n\t\t\ttarget?: string;\n\t\t\taction?: string;\n\t\t}\n\t): boolean {\n\t\tif (Is.empty(policy)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (Is.stringValue(options.assignee)) {\n\t\t\tconst assigneeIds = OdrlPolicyHelper.getPartyIds(policy.assignee);\n\t\t\tif (!assigneeIds.includes(options.assignee)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\tif (Is.stringValue(options.assigner)) {\n\t\t\tconst assignerIds = OdrlPolicyHelper.getPartyIds(policy.assigner);\n\t\t\tif (!assignerIds.includes(options.assigner)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\tif (Is.stringValue(options.target)) {\n\t\t\tconst targets = OdrlPolicyHelper.getTargets(policy);\n\t\t\tif (!targets.includes(options.target)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\tif (Is.stringValue(options.action)) {\n\t\t\tconst actions = OdrlPolicyHelper.getActions(policy);\n\t\t\tif (!actions.includes(options.action)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Collect all rule objects (permission, prohibition, obligation) from a policy.\n\t * @param policy The policy to collect rules from.\n\t * @returns Flattened array of all rules.\n\t * @internal\n\t */\n\tprivate static collectRules(policy: IRightsManagementPolicy): IOdrlRule[] {\n\t\tconst rules: IOdrlRule[] = [];\n\t\trules.push(\n\t\t\t...ArrayHelper.fromObjectOrArray<IOdrlPermission>(policy.permission ?? []),\n\t\t\t...ArrayHelper.fromObjectOrArray<IOdrlProhibition>(policy.prohibition ?? []),\n\t\t\t...ArrayHelper.fromObjectOrArray<IOdrlDuty>(policy.obligation ?? [])\n\t\t);\n\t\treturn rules;\n\t}\n\n\t/**\n\t * Extract a target string from a target value and push it to the accumulator.\n\t * @param target The target value to extract from.\n\t * @param accumulator The array to push the target string into.\n\t * @internal\n\t */\n\tprivate static collectTarget(\n\t\ttarget: IOdrlAsset | IOdrlAssetCollection | string,\n\t\taccumulator: string[]\n\t): void {\n\t\tif (Is.object<IOdrlAsset>(target)) {\n\t\t\tconst uid = OdrlPolicyHelper.getUid(target);\n\t\t\tif (Is.stringValue(uid)) {\n\t\t\t\taccumulator.push(uid);\n\t\t\t}\n\t\t} else if (Is.stringValue(target)) {\n\t\t\taccumulator.push(target);\n\t\t}\n\t}\n\n\t/**\n\t * Extract an action string from an action value and push it to the accumulator.\n\t * @param action The action value to extract from.\n\t * @param accumulator The array to push the action string into.\n\t * @internal\n\t */\n\tprivate static collectAction(\n\t\taction: OdrlActionType | string | IOdrlAction,\n\t\taccumulator: string[]\n\t): void {\n\t\tif (Is.object<IOdrlAction>(action)) {\n\t\t\tconst uid = OdrlPolicyHelper.getUid(action);\n\t\t\tif (Is.stringValue(uid)) {\n\t\t\t\taccumulator.push(uid);\n\t\t\t}\n\t\t} else if (Is.stringValue(action)) {\n\t\t\taccumulator.push(action);\n\t\t}\n\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AC,CAAC;YACvB,CAAC;QACF,CAAC;aAAM,IAAI,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC;YACnC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1B,CAAC;IACF,CAAC;IAED;;;;;OAKG;IACK,MAAM,CAAC,aAAa,CAC3B,MAA6C,EAC7C,WAAqB;QAErB,IAAI,EAAE,CAAC,MAAM,CAAc,MAAM,CAAC,EAAE,CAAC;YACpC,MAAM,GAAG,GAAG,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC5C,IAAI,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC;gBACzB,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACvB,CAAC;QACF,CAAC;aAAM,IAAI,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC;YACnC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1B,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ObjectOrArray } from \"@twin.org/core\";\nimport { ArrayHelper, GeneralError, Guards, Is, ObjectHelper } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IDataspaceProtocolPolicy } from \"@twin.org/standards-dataspace-protocol\";\nimport type {\n\tIOdrlAction,\n\tIOdrlAsset,\n\tIOdrlAssetCollection,\n\tIOdrlDuty,\n\tIOdrlParty,\n\tIOdrlPartyCollection,\n\tIOdrlPermission,\n\tIOdrlProhibition,\n\tIOdrlRule,\n\tOdrlActionType\n} from \"@twin.org/standards-w3c-odrl\";\nimport type { IRightsManagementPolicy } from \"../models/IRightsManagementPolicy.js\";\n\n/**\n * Helper methods for Odrl Policies.\n */\nexport class OdrlPolicyHelper {\n\t/**\n\t * The class name of the Policy Administration Point Service.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<OdrlPolicyHelper>();\n\n\t/**\n\t * Get the UID of an ODRL policy or related object if available.\n\t * @param object The ODRL policy or related object to get the UID from.\n\t * @returns The UID of the object if available, otherwise undefined.\n\t */\n\tpublic static getUid(object: object | undefined): string | undefined {\n\t\treturn ObjectHelper.extractProperty<string>(object, [\"@id\", \"id\", \"uid\"], false);\n\t}\n\n\t/**\n\t * Get the type of an ODRL policy or related object if available.\n\t * @param object The ODRL policy or related object to get the type from.\n\t * @returns The type of the object if available, otherwise undefined.\n\t */\n\tpublic static getType(object: object | undefined): string | undefined {\n\t\treturn ObjectHelper.extractProperty<string>(object, [\"@type\", \"type\"], false);\n\t}\n\n\t/**\n\t * Extract assignee identity from policy.\n\t * @param policy The policy to extract the assignee from.\n\t * @returns Assignee id.\n\t * @throws GeneralError if assignee is missing or invalid.\n\t */\n\tpublic static extractAssigneeIdentity(policy: IDataspaceProtocolPolicy): ObjectOrArray<string> {\n\t\tif (Is.empty(policy.assignee)) {\n\t\t\tthrow new GeneralError(OdrlPolicyHelper.CLASS_NAME, \"policyMissingAssignee\", {\n\t\t\t\tpolicyType: OdrlPolicyHelper.getType(policy) ?? \"\",\n\t\t\t\tpolicyId: OdrlPolicyHelper.getUid(policy) ?? \"\"\n\t\t\t});\n\t\t}\n\n\t\tconst assignees = ArrayHelper.fromObjectOrArray(policy.assignee);\n\t\tconst assigneeIds: string[] = [];\n\t\tfor (const assignee of assignees) {\n\t\t\tconst assigneeId = Is.string(assignee) ? assignee : OdrlPolicyHelper.getUid(assignee);\n\t\t\tGuards.stringValue(OdrlPolicyHelper.CLASS_NAME, nameof(assigneeId), assigneeId);\n\t\t\tassigneeIds.push(assigneeId);\n\t\t}\n\n\t\treturn assigneeIds.length <= 1 ? assigneeIds[0] : assigneeIds;\n\t}\n\n\t/**\n\t * Extract assigner identity from policy.\n\t * @param policy The policy to extract the assigner from.\n\t * @returns Assigner id.\n\t * @throws GeneralError if assigner is missing or invalid.\n\t */\n\tpublic static extractAssignerIdentity(policy: IDataspaceProtocolPolicy): ObjectOrArray<string> {\n\t\tif (Is.empty(policy.assigner)) {\n\t\t\tthrow new GeneralError(OdrlPolicyHelper.CLASS_NAME, \"policyMissingAssigner\", {\n\t\t\t\tpolicyType: OdrlPolicyHelper.getType(policy) ?? \"\",\n\t\t\t\tpolicyId: OdrlPolicyHelper.getUid(policy) ?? \"\"\n\t\t\t});\n\t\t}\n\n\t\tconst assigners = ArrayHelper.fromObjectOrArray(policy.assigner);\n\t\tconst assignerIds: string[] = [];\n\n\t\tfor (const assigner of assigners) {\n\t\t\tconst assignerId = Is.string(assigner) ? assigner : OdrlPolicyHelper.getUid(assigner);\n\t\t\tGuards.stringValue(OdrlPolicyHelper.CLASS_NAME, nameof(assignerId), assignerId);\n\t\t\tassignerIds.push(assignerId);\n\t\t}\n\n\t\treturn assignerIds.length <= 1 ? assignerIds[0] : assignerIds;\n\t}\n\n\t/**\n\t * Normalize party value(s) into identifier strings when possible.\n\t * Handles single parties or arrays of parties by returning all discovered identifiers.\n\t * @param party The party to normalize.\n\t * @returns The party identifiers, or undefined when not available.\n\t */\n\tpublic static getPartyIds(\n\t\tparty?:\n\t\t\t| string\n\t\t\t| IOdrlParty\n\t\t\t| IOdrlPartyCollection\n\t\t\t| (string | IOdrlParty | IOdrlPartyCollection)[]\n\t): string[] {\n\t\tconst ids: string[] = [];\n\n\t\tif (Is.empty(party)) {\n\t\t\treturn ids;\n\t\t}\n\n\t\tif (Is.stringValue(party)) {\n\t\t\tids.push(party);\n\t\t\treturn ids;\n\t\t}\n\n\t\tif (Is.arrayValue(party)) {\n\t\t\tfor (const item of party) {\n\t\t\t\tconst childIds = OdrlPolicyHelper.getPartyIds(item);\n\t\t\t\tif (!Is.empty(childIds)) {\n\t\t\t\t\tfor (const childId of childIds) {\n\t\t\t\t\t\tif (!ids.includes(childId)) {\n\t\t\t\t\t\t\tids.push(childId);\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\treturn ids;\n\t\t}\n\n\t\tif (Is.object<IOdrlParty>(party)) {\n\t\t\tconst uid = OdrlPolicyHelper.getUid(party);\n\t\t\tif (Is.stringValue(uid) && !ids.includes(uid)) {\n\t\t\t\tids.push(uid);\n\t\t\t}\n\t\t}\n\n\t\treturn ids;\n\t}\n\n\t/**\n\t * Get the dataset targets from policy.\n\t * @param policy The policy to extract the dataset targets from.\n\t * @returns Top-level targets (deduped).\n\t */\n\tpublic static getDatasetTargets(policy: IRightsManagementPolicy): string[] {\n\t\tconst targetIds: string[] = [];\n\n\t\tconst policyTargets = ArrayHelper.fromObjectOrArray<IOdrlAsset | IOdrlAssetCollection | string>(\n\t\t\tpolicy.target ?? []\n\t\t);\n\t\tfor (const target of policyTargets) {\n\t\t\tOdrlPolicyHelper.collectTarget(target, targetIds);\n\t\t}\n\n\t\treturn Array.from(new Set(targetIds));\n\t}\n\n\t/**\n\t * Get targets from policy.\n\t * Walks both the policy-level target field and the target field on every\n\t * permission, prohibition, and obligation rule so that policies that store\n\t * their target exclusively on a rule are correctly indexed for query().\n\t * @param policy The policy to extract the targets from.\n\t * @returns Targets.\n\t */\n\tpublic static getTargets(policy: IRightsManagementPolicy): string[] {\n\t\tconst targetIds: string[] = OdrlPolicyHelper.getDatasetTargets(policy);\n\n\t\tconst rules = OdrlPolicyHelper.collectRules(policy);\n\t\tfor (const rule of rules) {\n\t\t\tconst ruleTargets = ArrayHelper.fromObjectOrArray<IOdrlAsset | IOdrlAssetCollection | string>(\n\t\t\t\trule.target ?? []\n\t\t\t);\n\t\t\tfor (const target of ruleTargets) {\n\t\t\t\tOdrlPolicyHelper.collectTarget(target, targetIds);\n\t\t\t}\n\t\t}\n\n\t\treturn Array.from(new Set(targetIds));\n\t}\n\n\t/**\n\t * Get actions from policy.\n\t * Walks both the policy-level action field and the action field on every\n\t * permission, prohibition, and obligation rule so that policies that store\n\t * their action exclusively on a rule are correctly indexed for query().\n\t * @param policy The policy to extract the actions from.\n\t * @returns Actions.\n\t */\n\tpublic static getActions(policy: IRightsManagementPolicy): string[] {\n\t\tconst actions: string[] = [];\n\n\t\tconst policyActions = ArrayHelper.fromObjectOrArray<OdrlActionType | string | IOdrlAction>(\n\t\t\tpolicy.action ?? []\n\t\t);\n\t\tfor (const action of policyActions) {\n\t\t\tOdrlPolicyHelper.collectAction(action, actions);\n\t\t}\n\n\t\tconst rules = OdrlPolicyHelper.collectRules(policy);\n\t\tfor (const rule of rules) {\n\t\t\tconst ruleActions = ArrayHelper.fromObjectOrArray<OdrlActionType | string | IOdrlAction>(\n\t\t\t\trule.action ?? []\n\t\t\t);\n\t\t\tfor (const action of ruleActions) {\n\t\t\t\tOdrlPolicyHelper.collectAction(action, actions);\n\t\t\t}\n\t\t}\n\n\t\treturn Array.from(new Set(actions));\n\t}\n\n\t/**\n\t * Does the policy match.\n\t * @param policy The policy to try and match.\n\t * @param options The matching options.\n\t * @param options.assignee The assignee to match.\n\t * @param options.assigner The assigner to match.\n\t * @param options.target The target to match.\n\t * @param options.action The action to match.\n\t * @returns True if the policy matches.\n\t */\n\tpublic static matchPolicy(\n\t\tpolicy: IRightsManagementPolicy | undefined,\n\t\toptions: {\n\t\t\tassignee?: string;\n\t\t\tassigner?: string;\n\t\t\ttarget?: string;\n\t\t\taction?: string;\n\t\t}\n\t): boolean {\n\t\tif (Is.empty(policy)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (Is.stringValue(options.assignee)) {\n\t\t\tconst assigneeIds = OdrlPolicyHelper.getPartyIds(policy.assignee);\n\t\t\tif (!assigneeIds.includes(options.assignee)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\tif (Is.stringValue(options.assigner)) {\n\t\t\tconst assignerIds = OdrlPolicyHelper.getPartyIds(policy.assigner);\n\t\t\tif (!assignerIds.includes(options.assigner)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\tif (Is.stringValue(options.target)) {\n\t\t\tconst targets = OdrlPolicyHelper.getTargets(policy);\n\t\t\tif (!targets.includes(options.target)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\tif (Is.stringValue(options.action)) {\n\t\t\tconst actions = OdrlPolicyHelper.getActions(policy);\n\t\t\tif (!actions.includes(options.action)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Collect all rule objects (permission, prohibition, obligation) from a policy.\n\t * @param policy The policy to collect rules from.\n\t * @returns Flattened array of all rules.\n\t * @internal\n\t */\n\tprivate static collectRules(policy: IRightsManagementPolicy): IOdrlRule[] {\n\t\tconst rules: IOdrlRule[] = [];\n\t\trules.push(\n\t\t\t...ArrayHelper.fromObjectOrArray<IOdrlPermission>(policy.permission ?? []),\n\t\t\t...ArrayHelper.fromObjectOrArray<IOdrlProhibition>(policy.prohibition ?? []),\n\t\t\t...ArrayHelper.fromObjectOrArray<IOdrlDuty>(policy.obligation ?? [])\n\t\t);\n\t\treturn rules;\n\t}\n\n\t/**\n\t * Extract a target string from a target value and push it to the accumulator.\n\t * @param target The target value to extract from.\n\t * @param accumulator The array to push the target string into.\n\t * @internal\n\t */\n\tprivate static collectTarget(\n\t\ttarget: IOdrlAsset | IOdrlAssetCollection | string,\n\t\taccumulator: string[]\n\t): void {\n\t\tif (Is.object<IOdrlAsset>(target)) {\n\t\t\tconst uid = OdrlPolicyHelper.getUid(target);\n\t\t\tif (Is.stringValue(uid)) {\n\t\t\t\taccumulator.push(uid);\n\t\t\t}\n\t\t} else if (Is.stringValue(target)) {\n\t\t\taccumulator.push(target);\n\t\t}\n\t}\n\n\t/**\n\t * Extract an action string from an action value and push it to the accumulator.\n\t * @param action The action value to extract from.\n\t * @param accumulator The array to push the action string into.\n\t * @internal\n\t */\n\tprivate static collectAction(\n\t\taction: OdrlActionType | string | IOdrlAction,\n\t\taccumulator: string[]\n\t): void {\n\t\tif (Is.object<IOdrlAction>(action)) {\n\t\t\tconst uid = OdrlPolicyHelper.getUid(action);\n\t\t\tif (Is.stringValue(uid)) {\n\t\t\t\taccumulator.push(uid);\n\t\t\t}\n\t\t} else if (Is.stringValue(action)) {\n\t\t\taccumulator.push(action);\n\t\t}\n\t}\n}\n"]}
@@ -38,6 +38,10 @@ export interface IPolicyNegotiation {
38
38
  * Used to construct callback URLs in subsequent async messages.
39
39
  */
40
40
  publicOrigin?: string;
41
+ /**
42
+ * The tenant id this negotiation belongs to.
43
+ */
44
+ tenantId?: string;
41
45
  /**
42
46
  * Organization identity to be used when sending trust payloads.
43
47
  */
@@ -43,6 +43,12 @@ export declare class OdrlPolicyHelper {
43
43
  * @returns The party identifiers, or undefined when not available.
44
44
  */
45
45
  static getPartyIds(party?: string | IOdrlParty | IOdrlPartyCollection | (string | IOdrlParty | IOdrlPartyCollection)[]): string[];
46
+ /**
47
+ * Get the dataset targets from policy.
48
+ * @param policy The policy to extract the dataset targets from.
49
+ * @returns Top-level targets (deduped).
50
+ */
51
+ static getDatasetTargets(policy: IRightsManagementPolicy): string[];
46
52
  /**
47
53
  * Get targets from policy.
48
54
  * Walks both the policy-level target field and the target field on every
package/docs/changelog.md CHANGED
@@ -6,6 +6,20 @@
6
6
 
7
7
  * remove EcosystemPolicy models/DTOs and standardize policy typing on `OdrlPolicyType` for v2.
8
8
 
9
+ ## [0.0.3-next.32](https://github.com/twinfoundation/twin-rights-management/compare/rights-management-models-v0.0.3-next.31...rights-management-models-v0.0.3-next.32) (2026-05-05)
10
+
11
+
12
+ ### Miscellaneous Chores
13
+
14
+ * **rights-management-models:** Synchronize repo versions
15
+
16
+ ## [0.0.3-next.31](https://github.com/twinfoundation/twin-rights-management/compare/rights-management-models-v0.0.3-next.30...rights-management-models-v0.0.3-next.31) (2026-05-01)
17
+
18
+
19
+ ### Features
20
+
21
+ * pnp callback encryption, getDatasetTargets helper, engine-driven callbackPath ([#132](https://github.com/twinfoundation/twin-rights-management/issues/132)) ([e642154](https://github.com/twinfoundation/twin-rights-management/commit/e6421546336bfa73a7c0a9fe102beeaa518249dd))
22
+
9
23
  ## [0.0.3-next.30](https://github.com/twinfoundation/twin-rights-management/compare/rights-management-models-v0.0.3-next.29...rights-management-models-v0.0.3-next.30) (2026-04-29)
10
24
 
11
25
 
@@ -141,6 +141,28 @@ The party identifiers, or undefined when not available.
141
141
 
142
142
  ***
143
143
 
144
+ ### getDatasetTargets() {#getdatasettargets}
145
+
146
+ > `static` **getDatasetTargets**(`policy`): `string`[]
147
+
148
+ Get the dataset targets from policy.
149
+
150
+ #### Parameters
151
+
152
+ ##### policy
153
+
154
+ [`IRightsManagementPolicy`](../type-aliases/IRightsManagementPolicy.md)
155
+
156
+ The policy to extract the dataset targets from.
157
+
158
+ #### Returns
159
+
160
+ `string`[]
161
+
162
+ Top-level targets (deduped).
163
+
164
+ ***
165
+
144
166
  ### getTargets() {#gettargets}
145
167
 
146
168
  > `static` **getTargets**(`policy`): `string`[]
@@ -69,6 +69,14 @@ Used to construct callback URLs in subsequent async messages.
69
69
 
70
70
  ***
71
71
 
72
+ ### tenantId? {#tenantid}
73
+
74
+ > `optional` **tenantId?**: `string`
75
+
76
+ The tenant id this negotiation belongs to.
77
+
78
+ ***
79
+
72
80
  ### organizationIdentity {#organizationidentity}
73
81
 
74
82
  > **organizationIdentity**: `string`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/rights-management-models",
3
- "version": "0.0.3-next.30",
3
+ "version": "0.0.3-next.32",
4
4
  "description": "Data model definitions for rights management policies, negotiations, and service contracts.",
5
5
  "repository": {
6
6
  "type": "git",