@twin.org/dataspace-control-plane-service 0.0.3-next.49 → 0.0.3-next.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/dataspaceControlPlaneService.js +67 -1
- package/dist/es/dataspaceControlPlaneService.js.map +1 -1
- package/dist/types/dataspaceControlPlaneService.d.ts +3 -2
- package/docs/changelog.md +19 -0
- package/docs/reference/classes/DataspaceControlPlaneService.md +11 -11
- package/locales/en.json +2 -0
- package/package.json +2 -2
|
@@ -10,6 +10,7 @@ import { ComparisonOperator } from "@twin.org/entity";
|
|
|
10
10
|
import { EntityStorageConnectorFactory } from "@twin.org/entity-storage-models";
|
|
11
11
|
import { OdrlPolicyHelper, PolicyRequesterFactory } from "@twin.org/rights-management-models";
|
|
12
12
|
import { DataspaceProtocolContexts, DataspaceProtocolContractNegotiationTypes, DataspaceProtocolEndpointType, DataspaceProtocolHelper, DataspaceProtocolTransferProcessStateType, DataspaceProtocolTransferProcessTypes } from "@twin.org/standards-dataspace-protocol";
|
|
13
|
+
import { OdrlPolicyType } from "@twin.org/standards-w3c-odrl";
|
|
13
14
|
import { MetricHelper } from "@twin.org/telemetry-models";
|
|
14
15
|
import { TrustHelper } from "@twin.org/trust-models";
|
|
15
16
|
import { DataspaceControlPlanePolicyRequester } from "./dataspaceControlPlanePolicyRequester.js";
|
|
@@ -1295,7 +1296,7 @@ export class DataspaceControlPlaneService {
|
|
|
1295
1296
|
* @param offerId The offer ID from the provider's catalog.
|
|
1296
1297
|
* @param providerEndpoint The provider's contract negotiation endpoint URL.
|
|
1297
1298
|
* @param trustPayload The trust payload for authentication.
|
|
1298
|
-
* @returns
|
|
1299
|
+
* @returns For implicit trust: `{ agreementId }`. For external negotiation: `{ negotiationId }`.
|
|
1299
1300
|
*/
|
|
1300
1301
|
async negotiateAgreement(datasetId, offerId, providerEndpoint, trustPayload) {
|
|
1301
1302
|
Guards.stringValue(DataspaceControlPlaneService.CLASS_NAME, "datasetId", datasetId);
|
|
@@ -1375,6 +1376,9 @@ export class DataspaceControlPlaneService {
|
|
|
1375
1376
|
offerType: getJsonLdType(matchingOffer)
|
|
1376
1377
|
}
|
|
1377
1378
|
});
|
|
1379
|
+
if (trustInfo.identity === organizationId) {
|
|
1380
|
+
return this.negotiateImplicitTrustAgreement(organizationId, datasetId);
|
|
1381
|
+
}
|
|
1378
1382
|
const negotiationId = await this._policyNegotiationPointComponent.sendRequestToProvider(providerEndpoint, DataspaceControlPlaneService._REQUESTER_TYPE, offerId, publicOrigin);
|
|
1379
1383
|
if (!negotiationId) {
|
|
1380
1384
|
throw new GeneralError(DataspaceControlPlaneService.CLASS_NAME, "negotiationInitiationFailed", {
|
|
@@ -2488,5 +2492,67 @@ export class DataspaceControlPlaneService {
|
|
|
2488
2492
|
const contextIds = await ContextIdStore.getContextIds();
|
|
2489
2493
|
return contextIds?.[ContextIdKeys.Tenant];
|
|
2490
2494
|
}
|
|
2495
|
+
/**
|
|
2496
|
+
* Return an existing full-access agreement for the same-organization (implicit trust) case,
|
|
2497
|
+
* or create and store one if none exists. Fires onFinalized on all registered callbacks in
|
|
2498
|
+
* both cases.
|
|
2499
|
+
* @param organizationId The local organization ID (both assigner and assignee).
|
|
2500
|
+
* @param datasetId The dataset being granted access to.
|
|
2501
|
+
* @returns The agreement ID.
|
|
2502
|
+
* @internal
|
|
2503
|
+
*/
|
|
2504
|
+
async negotiateImplicitTrustAgreement(organizationId, datasetId) {
|
|
2505
|
+
const { policies } = await this._policyAdministrationPointComponent.query({
|
|
2506
|
+
type: OdrlPolicyType.Agreement,
|
|
2507
|
+
assigner: organizationId,
|
|
2508
|
+
assignee: organizationId,
|
|
2509
|
+
target: datasetId
|
|
2510
|
+
});
|
|
2511
|
+
let agreementId;
|
|
2512
|
+
if (policies.length > 0) {
|
|
2513
|
+
agreementId = OdrlPolicyHelper.getUid(policies[0]);
|
|
2514
|
+
await this._loggingComponent?.log({
|
|
2515
|
+
level: "info",
|
|
2516
|
+
source: DataspaceControlPlaneService.CLASS_NAME,
|
|
2517
|
+
ts: Date.now(),
|
|
2518
|
+
message: "implicitTrustAgreementReused",
|
|
2519
|
+
data: { agreementId, datasetId, organizationId }
|
|
2520
|
+
});
|
|
2521
|
+
}
|
|
2522
|
+
else {
|
|
2523
|
+
const implicitAgreement = {
|
|
2524
|
+
"@context": "http://www.w3.org/ns/odrl.jsonld",
|
|
2525
|
+
"@type": "Agreement",
|
|
2526
|
+
assigner: organizationId,
|
|
2527
|
+
assignee: organizationId,
|
|
2528
|
+
target: datasetId,
|
|
2529
|
+
permission: [{ action: "use" }]
|
|
2530
|
+
};
|
|
2531
|
+
agreementId = await this._policyAdministrationPointComponent.create(implicitAgreement);
|
|
2532
|
+
await MetricHelper.metricIncrement(this._telemetryComponent, DataspaceControlPlaneMetricIds.NegotiationsInitiated);
|
|
2533
|
+
await this._loggingComponent?.log({
|
|
2534
|
+
level: "info",
|
|
2535
|
+
source: DataspaceControlPlaneService.CLASS_NAME,
|
|
2536
|
+
ts: Date.now(),
|
|
2537
|
+
message: "implicitTrustAgreementCreated",
|
|
2538
|
+
data: { agreementId, datasetId, organizationId }
|
|
2539
|
+
});
|
|
2540
|
+
}
|
|
2541
|
+
for (const [key, cb] of this._negotiationCallbacks.entries()) {
|
|
2542
|
+
try {
|
|
2543
|
+
await cb.onFinalized(undefined, agreementId);
|
|
2544
|
+
}
|
|
2545
|
+
catch (error) {
|
|
2546
|
+
await this._loggingComponent?.log({
|
|
2547
|
+
level: "error",
|
|
2548
|
+
source: DataspaceControlPlaneService.CLASS_NAME,
|
|
2549
|
+
ts: Date.now(),
|
|
2550
|
+
message: "negotiationCallbackError",
|
|
2551
|
+
data: { key, negotiationId: agreementId, method: "onFinalized", error }
|
|
2552
|
+
});
|
|
2553
|
+
}
|
|
2554
|
+
}
|
|
2555
|
+
return { agreementId };
|
|
2556
|
+
}
|
|
2491
2557
|
}
|
|
2492
2558
|
//# sourceMappingURL=dataspaceControlPlaneService.js.map
|