Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/Query attribute versions #132

Merged
merged 31 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a3291e4
docu: new route definitions
sebbi08 Feb 9, 2024
e364de0
Merge branch 'main' into feature/NMSHDR-27-query-attribute-versions
mergify[bot] Feb 12, 2024
f200bbf
chore: fist implementation of some use cases
sebbi08 Feb 14, 2024
2ec8466
feat: add all missing routes for the new usecases
sebbi08 Feb 14, 2024
e8e1ce7
chore: remove added ts files
sebbi08 Feb 14, 2024
f84d24f
chore: improve test speed
sebbi08 Feb 14, 2024
20b640b
chore: improve imports of types
sebbi08 Feb 14, 2024
5b6e228
chore: add missing files
sebbi08 Feb 14, 2024
3835207
chore: add change log
sebbi08 Feb 14, 2024
88b862f
chore: move new routes to Attributes section
sebbi08 Feb 14, 2024
efe0d4f
chore: remove todo
sebbi08 Feb 14, 2024
02eaa70
chore: add mongodb as dev dependency
sebbi08 Feb 14, 2024
a8f2149
chore: refactor to use QueryParam Injection
sebbi08 Feb 15, 2024
5960b4a
Merge branch 'main' into feature/NMSHDR-27-query-attribute-versions
sebbi08 Feb 15, 2024
0235ab3
chore: bump version
sebbi08 Feb 15, 2024
01841b0
fix: test typing
sebbi08 Feb 15, 2024
6195c7b
chore: move client metadata up
sebbi08 Feb 15, 2024
9f62fae
chore: fix tests
sebbi08 Feb 15, 2024
7e2821e
chore: remove global context
sebbi08 Feb 15, 2024
a41b9db
chore: move to jssoft db client and remove warning log from transport…
sebbi08 Feb 15, 2024
b9980eb
chore: improve error for bad config
sebbi08 Feb 15, 2024
fe70e31
chore: remove math.random
sebbi08 Feb 15, 2024
8550a45
Merge branch 'main' into feature/NMSHDR-27-query-attribute-versions
sebbi08 Feb 19, 2024
0869289
Merge branch 'main' into feature/NMSHDR-27-query-attribute-versions
sebbi08 Feb 19, 2024
fdd158a
chore: use default values of use cases
sebbi08 Feb 19, 2024
390783a
chore: improve query extraction
sebbi08 Feb 19, 2024
d069ba9
chore: change log level
sebbi08 Feb 19, 2024
81d122d
chore: move private functions
sebbi08 Feb 19, 2024
b92813a
chore: add console log for ci tests
sebbi08 Feb 20, 2024
f88ee7f
chore: add second event to wait for with succession
sebbi08 Feb 20, 2024
c15df42
chore: fix tests by waiting for succeeded event
sebbi08 Feb 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .dev/Dockerfile.debug
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
FROM node:20.11.0
WORKDIR /usr/app
RUN npm install nodemon -g

# Webserver, Debugger
EXPOSE 80 9229

ENTRYPOINT ["nodemon", "-e", "js,json,yml", "--watch", "./dist", "--watch", "./config", "--inspect=0.0.0.0:9229", "--nolazy", "./dist/index.js"]
ENTRYPOINT ["npx", "nodemon", "-e", "js,json,yml", "--watch", "./dist", "--watch", "./config", "--inspect=0.0.0.0:9229", "--nolazy", "./dist/index.js"]
jkoenig134 marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 3.8.0

-> SDK 4.1.0

- add routes for querying versions of attrbutes
- `GET /api/v2/Attributes/Own/Repository` Get all the repository attributes
- `GET /api/v2/Attributes/Own/Shared/Identity` Get all own shared indentity attributes
- `GET /api/v2/Attributes/Peer/Shared/Identity` Get all peer shared identity attributes
- `GET /api/v2/Attributes/{id}/Versions` Get all versions of one repository attribute
- `GET /api/v2/Attributes/{id}/Versions/Shared` Get all shard versions of one repository attribute

## 3.7.3

- the webhooksV2 module is now named webhooks
Expand Down
9 changes: 5 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
jkoenig134 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nmshd/connector",
"version": "3.7.3",
"version": "3.8.0",
"private": true,
"description": "The Enmeshed Connector",
"homepage": "https://enmeshed.eu/integrate",
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nmshd/connector-sdk",
"version": "4.0.0",
"version": "4.1.0",
"description": "the enmeshed connector sdk",
"keywords": [
"enmeshed",
Expand Down
23 changes: 23 additions & 0 deletions packages/sdk/src/endpoints/AttributesEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import {
ExecuteRelationshipAttributeQueryRequest,
ExecuteThirdPartyRelationshipAttributeQueryRequest,
GetAttributesRequest,
GetOwnRepositoryAttributesRequest,
GetOwnSharedIdentityAttributesRequest,
GetPeerSharedIdentityAttributesRequest,
GetSharedVersionsOfRepositoryAttributeRequest,
GetValidAttributesRequest,
NotifyPeerAboutRepositoryAttributeSuccessionRequest,
NotifyPeerAboutRepositoryAttributeSuccessionResponse,
Expand Down Expand Up @@ -44,6 +48,25 @@ export class AttributesEndpoint extends Endpoint {
return await this.get("/api/v2/Attributes/Valid", request);
}

public async getOwnRepositoryAttributes(request?: GetOwnRepositoryAttributesRequest): Promise<ConnectorResponse<ConnectorAttributes>> {
return await this.get("/api/v2/Attributes/Own/Repository", request);
}
public async getOwnSharedIdentityAttributes(request?: GetOwnSharedIdentityAttributesRequest): Promise<ConnectorResponse<ConnectorAttributes>> {
return await this.get("/api/v2/Attributes/Own/Shared/Identity", request);
}
public async getPeerSharedIdentityAttributes(request?: GetPeerSharedIdentityAttributesRequest): Promise<ConnectorResponse<ConnectorAttributes>> {
return await this.get("/api/v2/Attributes/Peer/Shared/Identity", request);
}
public async getVersionsOfAttribute(attributeId: string): Promise<ConnectorResponse<ConnectorAttributes>> {
return await this.get(`/api/v2/Attributes/${attributeId}/Versions`);
}
public async getSharedVersionsOfRepositoryAttribute(
attributeId: string,
request: GetSharedVersionsOfRepositoryAttributeRequest
): Promise<ConnectorResponse<ConnectorAttributes>> {
return await this.get(`/api/v2/Attributes/${attributeId}/Versions/Shared`, request);
}

public async executeIdentityAttributeQuery(request: ExecuteIdentityAttributeQueryRequest): Promise<ConnectorResponse<ConnectorAttributes>> {
return await this.post("/api/v2/Attributes/ExecuteIdentityAttributeQuery", request, 200);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/sdk/src/types/attributes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export * from "./requests/ExecuteIdentityAttributeQueryRequest";
export * from "./requests/ExecuteRelationshipAttributeQueryRequest";
export * from "./requests/ExecuteThirdPartyRelationshipAttributeQueryRequest";
export * from "./requests/GetAttributesRequest";
export * from "./requests/GetOwnRepositoryAttributesRequest";
export * from "./requests/GetOwnSharedIdentityAttributesRequest";
export * from "./requests/GetPeerSharedIdentityAttributesRequest";
export * from "./requests/GetSharedVersionsOfRepositoryAttributeRequest";
export * from "./requests/GetValidAttributesRequest";
export * from "./requests/NotifyPeerAboutRepositoryAttributeSuccessionRequest";
export * from "./requests/NotifyPeerAboutRepositoryAttributeSuccessionResponse";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface GetOwnRepositoryAttributesRequest {
onlyLatestVersions?: boolean;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export interface GetOwnSharedIdentityAttributesRequest {
peer: string;
onlyValid?: boolean;
"query.createdAt"?: string;
"query.content.@type"?: string | string[];
"query.content.tags"?: string | string[];
"query.content.validFrom"?: string | string[];
"query.content.validTo"?: string | string[];
"query.content.key"?: string | string[];
"query.content.isTechnical"?: string | string[];
"query.content.confidentiality"?: string | string[];
"query.content.value.@type"?: string | string[];
"query.shareInfo"?: string | string[];
"query.shareInfo.requestReference"?: string | string[];
"query.shareInfo.notificationReference"?: string | string[];
"query.shareInfo.sourceAttribute"?: string | string[];
hideTechnical?: boolean;
onlyLatestVersions?: boolean;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export interface GetPeerSharedIdentityAttributesRequest {
peer: string;
onlyValid?: boolean;
"query.createdAt"?: string;
"query.content.@type"?: string | string[];
"query.content.tags"?: string | string[];
"query.content.validFrom"?: string | string[];
"query.content.validTo"?: string | string[];
"query.content.key"?: string | string[];
"query.content.isTechnical"?: string | string[];
"query.content.confidentiality"?: string | string[];
"query.content.value.@type"?: string | string[];
"query.shareInfo"?: string | string[];
"query.shareInfo.requestReference"?: string | string[];
"query.shareInfo.notificationReference"?: string | string[];
hideTechnical?: boolean;
onlyLatestVersions?: boolean;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface GetSharedVersionsOfRepositoryAttributeRequest {
peers?: string[];
onlyLatestVersions?: boolean;
}
6 changes: 3 additions & 3 deletions packages/sdk/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export * from "./ConnectorError";
export * from "./ConnectorResponse";
export * from "./account";
export * from "./attributes";
export * from "./challenges";
export * from "./ConnectorError";
export * from "./ConnectorResponse";
export * from "./files";
export * from "./messages";
export * from "./relationships";
export * from "./relationshipTemplates";
export * from "./relationships";
export * from "./requests";
export * from "./tokens";
103 changes: 102 additions & 1 deletion src/modules/coreHttpApi/controllers/AttributesController.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApplicationError } from "@js-soft/ts-utils";
import { ConsumptionServices, RuntimeErrors, TransportServices } from "@nmshd/runtime";
import { Inject } from "typescript-ioc";
import { Accept, Context, GET, POST, Path, PathParam, Return, ServiceContext } from "typescript-rest";
import { Accept, Context, GET, POST, Path, PathParam, QueryParam, Return, ServiceContext } from "typescript-rest";
import { Envelope } from "../../../infrastructure";
import { BaseController } from "../common/BaseController";

Expand Down Expand Up @@ -74,6 +74,90 @@ export class AttributesController extends BaseController {
return this.ok(result);
}

@GET
@Path("/Own/Repository")
@Accept("application/json")
public async getOwnRepositoryAttributes(@QueryParam("onlyLatestVersions") onlyLatestVersions?: string): Promise<Envelope> {
const result = await this.consumptionServices.attributes.getRepositoryAttributes({
onlyLatestVersions: this.stringToBoolean(onlyLatestVersions)
});
return this.ok(result);
}

@GET
@Path("/Own/Shared/Identity")
@Accept("application/json")
public async getOwnSharedIdentityAttributes(
@Context context: ServiceContext,
@QueryParam("peer") peer: string,
@QueryParam("hideTechnical") hideTechnical?: string,
@QueryParam("onlyLatestVersions") onlyLatestVersions?: string,
@QueryParam("onlyValid") onlyValid?: string
): Promise<Envelope> {
const query: Record<string, any> = this.extractQuery(context.request.query, ["peer", "hideTechnical", "onlyLatestVersions", "onlyValid"]);

const result = await this.consumptionServices.attributes.getOwnSharedAttributes({
peer,
hideTechnical: this.stringToBoolean(hideTechnical),
query,
onlyLatestVersions: this.stringToBoolean(onlyLatestVersions),
onlyValid: this.stringToBoolean(onlyValid)
});
return this.ok(result);
}

@GET
@Path("/Peer/Shared/Identity")
@Accept("application/json")
public async getPeerSharedIdentityAttributes(
@Context context: ServiceContext,
@QueryParam("peer") peer: string,
@QueryParam("hideTechnical") hideTechnical?: string,
@QueryParam("onlyLatestVersions") onlyLatestVersions?: string,
@QueryParam("onlyValid") onlyValid?: string
): Promise<Envelope> {
const query: Record<string, any> = this.extractQuery(context.request.query, ["peer", "hideTechnical", "onlyLatestVersions", "onlyValid"]);

const result = await this.consumptionServices.attributes.getPeerSharedAttributes({
peer,
hideTechnical: this.stringToBoolean(hideTechnical),
query,
onlyLatestVersions: this.stringToBoolean(onlyLatestVersions),
onlyValid: this.stringToBoolean(onlyValid)
});
return this.ok(result);
}

@GET
@Path("/:id/Versions")
@Accept("application/json")
public async getVersionsOfAttribute(@PathParam("id") attributeId: string): Promise<Envelope> {
const result = await this.consumptionServices.attributes.getVersionsOfAttribute({
attributeId
});
return this.ok(result);
}

@GET
@Path("/:id/Versions/Shared")
@Accept("application/json")
public async getSharedVersionsOfRepositoryAttribute(
@PathParam("id") attributeId: string,
@QueryParam("peers") peers?: string | string[],
@QueryParam("onlyLatestVersions") onlyLatestVersions?: string
): Promise<Envelope> {
if (typeof peers === "string") {
peers = [peers];
}

const result = await this.consumptionServices.attributes.getSharedVersionsOfRepositoryAttribute({
attributeId,
onlyLatestVersions: this.stringToBoolean(onlyLatestVersions),
peers
});
return this.ok(result);
}

@GET
@Path("/Valid")
@Accept("application/json")
Expand Down Expand Up @@ -129,4 +213,21 @@ export class AttributesController extends BaseController {
const result = await this.consumptionServices.attributes.getAttribute({ id });
return this.ok(result);
}

private stringToBoolean(value: string | undefined): boolean | undefined {
if (value === undefined) {
return undefined;
}

return value.toLowerCase() === "true";
}

private extractQuery(query: ServiceContext["request"]["query"], nonQueryParams: string[]): Record<string, any> {
return Object.entries(query)
.filter(([key, _]) => !nonQueryParams.includes(key))
.reduce<Record<string, any>>((previous, [key, value]) => {
previous[key] = value as string | string[];
return previous;
}, {});
}
}
Loading
Loading