Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Gann committed Dec 12, 2023
1 parent 130c0eb commit 6028bd8
Show file tree
Hide file tree
Showing 17 changed files with 677 additions and 201 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"editor.formatOnPaste": true,
"files.autoSave": "off",
"editor.codeActionsOnSave": {
"source.organizeImports": true
"source.organizeImports": "explicit"
},
"files.eol": "\n",
"todo-tree.filtering.excludeGlobs": ["**/node_modules/**", "**/dist/**", "**/dist-test/**", "**/lib-web/**", "**/*.min.*", "**/*.map"],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@js-soft/node-logger": "1.1.1",
"@js-soft/ts-utils": "^2.3.3",
"@nmshd/iql": "^1.0.0",
"@nmshd/runtime": "3.0.0",
"@nmshd/runtime": "3.1.0",
"agentkeepalive": "4.5.0",
"amqplib": "^0.10.3",
"axios": "^1.6.2",
Expand Down
45 changes: 34 additions & 11 deletions packages/sdk/src/endpoints/AttributesEndpoint.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,63 @@
import {
ConnectorAttribute,
ConnectorAttributes,
ConnectorRequest,
ConnectorResponse,
CreateAndShareRelationshipAttributeRequest,
CreateAttributeRequest,
CreateIdentityAttributeRequest,
CreateRelationshipAttributeRequest,
ExecuteIQLQueryRequest,
ExecuteIdentityAttributeQueryRequest,
ExecuteRelationshipAttributeQueryRequest,
ExecuteThirdPartyRelationshipAttributeQueryRequest,
GetAttributesRequest,
GetValidAttributesRequest,
NotifyPeerAboutIdentityAttributeSuccessionRequest,
ShareAttributeRequest,
ShareIdentityAttributeRequest,
SucceedAttributeRequest,
SucceedAttributeResponse,
SucceedIdentityAttributeRequest,
SucceedRelationshipAttributeRequest
SucceedRelationshipAttributeAndNotifyPeerRequest
} from "../types";
import { CreateAttributeResponse } from "../types/attributes/requests/CreateAttributeResponse";
import { Endpoint } from "./Endpoint";

export class AttributesEndpoint extends Endpoint {
public async createAttribute(request: CreateAttributeRequest): Promise<ConnectorResponse<CreateAttributeResponse>> {
return await this.post("/api/v2/Attributes", request);
}

public async createIdentityAttribute(request: CreateIdentityAttributeRequest): Promise<ConnectorResponse<ConnectorAttribute>> {
return await this.post("/api/v2/Attributes/IdentityAttribute", request);
return await this.post("/api/v2/Attributes/CreateIdentityAttribute", request);
}

public async createAndShareRelationshipAttribute(request: CreateAndShareRelationshipAttributeRequest): Promise<ConnectorResponse<ConnectorRequest>> {
return await this.post("/api/v2/Attributes/CreateAndShareRelationshipAttribute", request);
}

public async succeedAttribute(request: SucceedAttributeRequest): Promise<ConnectorResponse<SucceedAttributeResponse>> {
return await this.post("/api/v2/Attributes/SucceedAttribute", request);
}

public async succeedIdentityAttribute(request: SucceedIdentityAttributeRequest): Promise<ConnectorResponse<SucceedAttributeResponse>> {
return await this.post("/api/v2/Attributes/SucceedIdentityAttribute", request);
}

public async createRelationshipAttribute(request: CreateRelationshipAttributeRequest): Promise<ConnectorResponse<ConnectorAttribute>> {
return await this.post("/api/v2/Attributes/RelationshipAttribute", request);
public async succeedRelationshipAttributeAndNotifyPeer(request: SucceedRelationshipAttributeAndNotifyPeerRequest): Promise<ConnectorResponse<SucceedAttributeResponse>> {
return await this.post("/api/v2/Attributes/SucceedRelationshipAttributeAndNotifyPeer", request);
}

public async succeedIdentityAttribute(request: SucceedIdentityAttributeRequest): Promise<ConnectorResponse<ConnectorAttribute>> {
return await this.post(`/api/v2/Attributes/succeedIdentityAttribute/${request.predecessorId}`, request.successorContent);
public async shareAttribute(request: ShareAttributeRequest): Promise<ConnectorResponse<CreateAttributeResponse>> {
return await this.post("/api/v2/Attributes/ShareAttribute", request);
}

public async succeedRelationshipAttribute(request: SucceedRelationshipAttributeRequest): Promise<ConnectorResponse<ConnectorAttribute>> {
return await this.post(`/api/v2/Attributes/succeedRelationshipAttribute/${request.predecessorId}`, request.successorContent);
public async shareIdentityAttribute(request: ShareIdentityAttributeRequest): Promise<ConnectorResponse<ConnectorRequest>> {
return await this.post("/api/v2/Attributes/ShareIdentityAttribute", request);
}

public async notifyPeerAboutIdentityAttributeSuccession(request: NotifyPeerAboutIdentityAttributeSuccessionRequest): Promise<ConnectorResponse<ConnectorAttribute>> {
return await this.post("/api/v2/Attributes/notifyPeerAboutIdentityAttributeSuccession", request);
public async notifyPeerAboutIdentityAttributeSuccession(request: NotifyPeerAboutIdentityAttributeSuccessionRequest): Promise<ConnectorResponse<SucceedAttributeResponse>> {
return await this.post("/api/v2/Attributes/NotifyPeerAboutIdentityAttributeSuccession", request);
}

public async getAttributes(request: GetAttributesRequest): Promise<ConnectorResponse<ConnectorAttributes>> {
Expand Down
10 changes: 8 additions & 2 deletions packages/sdk/src/types/attributes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ export * from "./IQLQuery";
export * from "./IdentityAttributeQuery";
export * from "./RelationshipAttributeQuery";
export * from "./ThirdPartyAttributeQuery";
export * from "./requests/CreateAndShareRelationshipAttributeRequest";
export * from "./requests/CreateAttributeRequest";
export * from "./requests/CreateIdentityAttributeRequest";
export * from "./requests/CreateRelationshipAttributeRequest";
export * from "./requests/ExecuteIQLQueryRequest";
export * from "./requests/ExecuteIdentityAttributeQueryRequest";
export * from "./requests/ExecuteRelationshipAttributeQueryRequest";
export * from "./requests/ExecuteThirdPartyRelationshipAttributeQueryRequest";
export * from "./requests/GetAttributesRequest";
export * from "./requests/GetValidAttributesRequest";
export * from "./requests/NotifyPeerAboutIdentityAttributeSuccessionRequest";
export * from "./requests/ShareAttributeRequest";
export * from "./requests/ShareAttributeResponse";
export * from "./requests/ShareIdentityAttributeRequest";
export * from "./requests/SucceedAttributeRequest";
export * from "./requests/SucceedAttributeResponse";
export * from "./requests/SucceedIdentityAttributeRequest";
export * from "./requests/SucceedRelationshipAttributeRequest";
export * from "./requests/SucceedRelationshipAttributeAndNotifyPeerRequest";
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ConnectorAttributeValue } from "../ConnectorAttribute";

export interface CreateRelationshipAttributeRequest {
export interface CreateAndShareRelationshipAttributeRequest {
content: {
value: ConnectorAttributeValue;
key: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { CreateAndShareRelationshipAttributeRequest } from "./CreateAndShareRelationshipAttributeRequest";
import { CreateIdentityAttributeRequest } from "./CreateIdentityAttributeRequest";

export type CreateAttributeRequest = CreateIdentityAttributeRequest | CreateAndShareRelationshipAttributeRequest;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { ConnectorRequest } from "../../requests";
import { ConnectorAttribute } from "../ConnectorAttribute";

export type CreateAttributeResponse = ConnectorAttribute | ConnectorRequest;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { NotifyPeerAboutIdentityAttributeSuccessionRequest } from "./NotifyPeerAboutIdentityAttributeSuccessionRequest";
import { ShareIdentityAttributeRequest } from "./ShareIdentityAttributeRequest";

export type ShareAttributeRequest = (ShareIdentityAttributeRequest & { "@type": "Share" }) | (NotifyPeerAboutIdentityAttributeSuccessionRequest & { "@type": "Notify" });
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { ConnectorRequest } from "../../requests";
import { SucceedAttributeResponse } from "./SucceedAttributeResponse";

export type ShareIdentityAttributeResponse = SucceedAttributeResponse | ConnectorRequest;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface ShareIdentityAttributeRequest {
attributeId: string;
peer: string;
requestMetadata?: {
title?: string;
description?: string;
metadata?: Record<string, any>;
expiresAt?: string;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { SucceedIdentityAttributeRequest } from "./SucceedIdentityAttributeRequest";
import { SucceedRelationshipAttributeAndNotifyPeerRequest } from "./SucceedRelationshipAttributeAndNotifyPeerRequest";

export type SucceedAttributeRequest = SucceedRelationshipAttributeAndNotifyPeerRequest | SucceedIdentityAttributeRequest;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ConnectorAttribute } from "../ConnectorAttribute";

export interface SucceedAttributeResponse {
predecessor: ConnectorAttribute;
successor: ConnectorAttribute;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ConnectorAttributeValue } from "../ConnectorAttribute";

export interface SucceedRelationshipAttributeRequest {
export interface SucceedRelationshipAttributeAndNotifyPeerRequest {
predecessorId: string;
successorContent: {
value: ConnectorAttributeValue;
Expand Down
94 changes: 57 additions & 37 deletions src/modules/coreHttpApi/controllers/AttributesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,71 +14,91 @@ export class AttributesController extends BaseController {
}

@POST
@Path("/IdentityAttribute")
@Accept("application/json")
public async createAttribute(request: any): Promise<Return.NewResource<Envelope>> {
// TODO: remove createAndShareRelationshipAttribute
// TODO: restore original payload structure
let result: any;
if (request.value) {
result = await this.consumptionServices.attributes.createIdentityAttribute({ content: request });
} else {
result = await this.consumptionServices.attributes.createAndShareRelationshipAttribute(request);
}
return this.created(result);
}

@POST
@Path("/CreateIdentityAttribute")
@Accept("application/json")
public async createIdentityAttribute(request: any): Promise<Return.NewResource<Envelope>> {
const result = await this.consumptionServices.attributes.createIdentityAttribute({ content: request });
return this.created(result);
}

@POST
@Path("/RelationshipAttribute")
@Path("/CreateAndShareRelationshipAttribute")
@Accept("application/json")
public async createRelationshipAttribute(request: any): Promise<Return.NewResource<Envelope>> {
public async createandShareRelationshipAttribute(request: any): Promise<Return.NewResource<Envelope>> {
const result = await this.consumptionServices.attributes.createAndShareRelationshipAttribute(request);
return this.created(result);
}

// TODO: Alle successions -> POST only
@POST
@Path("/succeedAttribute")
@Accept("application/json")
public async succeedAttribute(id: string, successorContent: any): Promise<Return.NewResource<Envelope>> {
// TODO:
// openapi:
// ------------------
// predecessorId: string;
// successorContent: {
// "@type": "IdentityAttribute";
// value: AttributeValues.Identity.Json;
// tags?: string[];
// validFrom?: ISO8601DateTimeString;
// validTo?: ISO8601DateTimeString;
// } | {
// "@type": "RelationshipAttribute";
// value: AttributeValues.Identity.Json;
// validFrom?: ISO8601DateTimeString;
// validTo?: ISO8601DateTimeString;
// };
//

let result: any
if (successorContent["@type"] === "IdentityAttribute") {
result = await this.consumptionServices.attributes.succeedIdentityAttribute({ predecessorId: id, successorContent: successorContent });
} else if (successorContent["@type"] === "RelationshipAttribute") {
result = await this.consumptionServices.attributes.succeedRelationshipAttributeAndNotifyPeer({ predecessorId: id, successorContent: successorContent });
@Path("/SucceedIdentityAttribute")
@Accept("application/json")
public async succeedIdentityAttribute(request: any): Promise<Return.NewResource<Envelope>> {
const result = await this.consumptionServices.attributes.succeedIdentityAttribute({ predecessorId: request.predecessorId, successorContent: request.successorContent });
return this.created(result);
}

@POST
@Path("/SucceedAttribute")
@Accept("application/json")
public async succeedAttribute(request: any): Promise<Return.NewResource<Envelope>> {
let result: any;
if (request.successorContent["@type"] === "IdentityAttribute") {
result = await this.consumptionServices.attributes.succeedIdentityAttribute({ predecessorId: request.id, successorContent: request.successorContent });
} else if (request.successorContent["@type"] === "RelationshipAttribute") {
result = await this.consumptionServices.attributes.succeedRelationshipAttributeAndNotifyPeer({ predecessorId: request.id, successorContent: request.successorContent });
}
return this.created(result);
}

@POST
@Path("/succeedIdentityAttribute")
@Path("/SucceedRelationshipAttributeAndNotifyPeer")
@Accept("application/json")
public async succeedIdentityAttribute(predecessorId: string, successorContent: any): Promise<Return.NewResource<Envelope>> {
const result = await this.consumptionServices.attributes.succeedIdentityAttribute({ predecessorId: predecessorId, successorContent: successorContent });
public async succeedRelationshipAttributeAndNotifyPeer(request: any): Promise<Return.NewResource<Envelope>> {
const result = await this.consumptionServices.attributes.succeedRelationshipAttributeAndNotifyPeer({
predecessorId: request.predecessorId,
successorContent: request.successorContent
});
return this.created(result);
}

@POST
@Path("/ShareAttribute")
@Accept("application/json")
public async shareAttribute(request: any): Promise<Return.NewResource<Envelope>> {
// TODO: Remove?
let result: any;
if (request.successorContent["@type"] === "Share") {
result = await this.consumptionServices.attributes.shareIdentityAttribute(request);
} else if (request.successorContent["@type"] === "Notify") {
result = await this.consumptionServices.attributes.notifyPeerAboutIdentityAttributeSuccession(request);
}
return this.created(result);
}

@POST
@Path("/succeedRelationshipAttributeAndNotifyPeer")
@Path("/ShareIdentityAttribute")
@Accept("application/json")
public async succeedRelationshipAttributeAndNotifyPeer(predecessorId: string, successorContent: any): Promise<Return.NewResource<Envelope>> {
const result = await this.consumptionServices.attributes.succeedRelationshipAttributeAndNotifyPeer({ predecessorId: predecessorId, successorContent: successorContent });
public async shareIdentityAttribute(request: any): Promise<Return.NewResource<Envelope>> {
const result = await this.consumptionServices.attributes.shareIdentityAttribute(request);
return this.created(result);
}

@POST
@Path("/notifyPeerAboutIdentityAttributeSuccession")
@Path("/NotifyPeerAboutIdentityAttributeSuccession")
@Accept("application/json")
public async notifyPeerAboutIdentityAttributeSuccession(request: any): Promise<Return.NewResource<Envelope>> {
const result = await this.consumptionServices.attributes.notifyPeerAboutIdentityAttributeSuccession(request);
Expand Down
Loading

0 comments on commit 6028bd8

Please sign in to comment.