Skip to content

Commit

Permalink
Relationship decomposition (#212)
Browse files Browse the repository at this point in the history
* chore: version bumps

* refactor: formatting

* feat: implement decompose

* feat: add decompose to sdk

* chore: simplify executeFullCreateAndShareRepositoryAttributeFlow

* fix: expect correct status

* test: relationship decomposition

* fix: 204 for deleteRepositoryAttribute

* fix: update openapi

* chore: add new statuus

* test: add way more checks after decompositions

* test: enhance decomposition test

* test: udpate spec and spec tests

---------

Co-authored-by: Sebastian Mahr <[email protected]>
  • Loading branch information
jkoenig134 and sebbi08 authored Jul 11, 2024
1 parent 20e2dfb commit 872f857
Show file tree
Hide file tree
Showing 16 changed files with 299 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .dev/compose.backbone.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
BACKBONE_VERSION=6.1.0
BACKBONE_VERSION=6.2.0
117 changes: 97 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"@js-soft/node-logger": "1.1.1",
"@js-soft/ts-utils": "^2.3.3",
"@nmshd/iql": "^1.0.2",
"@nmshd/runtime": "5.0.0-alpha.5",
"@nmshd/runtime": "5.0.0-alpha.6",
"agentkeepalive": "4.5.0",
"amqplib": "^0.10.4",
"axios": "^1.7.2",
Expand Down Expand Up @@ -124,7 +124,7 @@
"npm-run-all": "^4.1.5",
"openapi-types": "^12.1.3",
"prettier": "^3.3.2",
"ts-jest": "^29.2.0",
"ts-jest": "^29.2.2",
"ts-node": "^10.9.2",
"typescript": "^5.5.3",
"typescript-rest-swagger": "github:nmshd/typescript-rest-swagger#1.4.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/endpoints/AttributesEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class AttributesEndpoint extends Endpoint {
}

public async deleteRepositoryAttribute(attributeId: string): Promise<ConnectorResponse<void>> {
return await this.delete(`/api/v2/Attributes/${attributeId}`);
return await this.delete(`/api/v2/Attributes/${attributeId}`, undefined, 204);
}

public async deleteThirdPartyOwnedRelationshipAttributeAndNotifyPeer(
Expand Down
6 changes: 4 additions & 2 deletions packages/sdk/src/endpoints/Endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export abstract class Endpoint {
return this.makeResult(response);
}

protected async delete<T>(path: string, params?: unknown): Promise<ConnectorResponse<T>> {
protected async delete<T>(path: string, params?: unknown, expectedStatus?: number): Promise<ConnectorResponse<T>> {
const response = await this.httpClient.delete(path, { params });
return this.makeResult(response);
return this.makeResult(response, expectedStatus);
}

protected makeResult<T>(httpResponse: AxiosResponse<any>, expectedStatus?: number): ConnectorResponse<T> {
Expand Down Expand Up @@ -62,6 +62,8 @@ export abstract class Endpoint {
});
}

if (expectedStatus === 204) return ConnectorResponse.success(undefined as T);

return ConnectorResponse.success(httpResponse.data.result);
}

Expand Down
4 changes: 4 additions & 0 deletions packages/sdk/src/endpoints/RelationshipsEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export class RelationshipsEndpoint extends Endpoint {
return await this.put(`/api/v2/Relationships/${relationshipId}/Terminate`);
}

public async decomposeRelationship(relationshipId: string): Promise<ConnectorResponse<void>> {
return await this.delete(`/api/v2/Relationships/${relationshipId}`, undefined, 204);
}

public async requestRelationshipReactivation(relationshipId: string): Promise<ConnectorResponse<ConnectorRelationship>> {
return await this.put(`/api/v2/Relationships/${relationshipId}/Reactivate`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export enum ConnectorRelationshipAuditLogEntryReason {
ReactivationRequested = "ReactivationRequested",
AcceptanceOfReactivation = "AcceptanceOfReactivation",
RejectionOfReactivation = "RejectionOfReactivation",
RevocationOfReactivation = "RevocationOfReactivation"
RevocationOfReactivation = "RevocationOfReactivation",
Decomposition = "Decomposition"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export enum ConnectorRelationshipStatus {
Active = "Active",
Rejected = "Rejected",
Revoked = "Revoked",
Terminated = "Terminated"
Terminated = "Terminated",
DeletionProposed = "DeletionProposed"
}
4 changes: 2 additions & 2 deletions src/modules/coreHttpApi/controllers/AttributesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ export class AttributesController extends BaseController {

@DELETE
@Path("/:id")
public async deleteRepositoryAttribute(@PathParam("id") attributeId: string): Promise<Envelope> {
public async deleteRepositoryAttribute(@PathParam("id") attributeId: string): Promise<void> {
const result = await this.consumptionServices.attributes.deleteRepositoryAttribute({ attributeId });
return this.ok(result);
return this.noContent(result);
}

private stringToBoolean(value: string | undefined): boolean | undefined {
Expand Down
30 changes: 14 additions & 16 deletions src/modules/coreHttpApi/controllers/RelationshipsController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TransportServices } from "@nmshd/runtime";
import { Inject } from "typescript-ioc";
import { Accept, Context, GET, Path, PathParam, POST, PUT, Return, ServiceContext } from "typescript-rest";
import { Accept, Context, DELETE, GET, Path, PathParam, POST, PUT, Return, ServiceContext } from "typescript-rest";
import { Envelope } from "../../../infrastructure";
import { BaseController } from "../common/BaseController";

Expand Down Expand Up @@ -76,49 +76,47 @@ export class RelationshipsController extends BaseController {
@Path(":id/Terminate")
@Accept("application/json")
public async terminateRelationship(@PathParam("id") id: string): Promise<Envelope> {
const result = await this.transportServices.relationships.terminateRelationship({
relationshipId: id
});
const result = await this.transportServices.relationships.terminateRelationship({ relationshipId: id });
return this.ok(result);
}

@DELETE
@Path(":id")
@Accept("application/json")
public async decomposeRelationship(@PathParam("id") id: string): Promise<void> {
const result = await this.transportServices.relationships.decomposeRelationship({ relationshipId: id });
return this.noContent(result);
}

@PUT
@Path(":id/Reactivate")
@Accept("application/json")
public async requestRelationshipReactivation(@PathParam("id") id: string): Promise<Envelope> {
const result = await this.transportServices.relationships.requestRelationshipReactivation({
relationshipId: id
});
const result = await this.transportServices.relationships.requestRelationshipReactivation({ relationshipId: id });
return this.ok(result);
}

@PUT
@Path(":id/Reactivate/Accept")
@Accept("application/json")
public async acceptRelationshipReactivation(@PathParam("id") id: string): Promise<Envelope> {
const result = await this.transportServices.relationships.acceptRelationshipReactivation({
relationshipId: id
});
const result = await this.transportServices.relationships.acceptRelationshipReactivation({ relationshipId: id });
return this.ok(result);
}

@PUT
@Path(":id/Reactivate/Reject")
@Accept("application/json")
public async rejectRelationshipReactivation(@PathParam("id") id: string): Promise<Envelope> {
const result = await this.transportServices.relationships.rejectRelationshipReactivation({
relationshipId: id
});
const result = await this.transportServices.relationships.rejectRelationshipReactivation({ relationshipId: id });
return this.ok(result);
}

@PUT
@Path(":id/Reactivate/Revoke")
@Accept("application/json")
public async revokeRelationshipReactivation(@PathParam("id") id: string): Promise<Envelope> {
const result = await this.transportServices.relationships.revokeRelationshipReactivation({
relationshipId: id
});
const result = await this.transportServices.relationships.revokeRelationshipReactivation({ relationshipId: id });
return this.ok(result);
}
}
Loading

0 comments on commit 872f857

Please sign in to comment.