-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add IdentityMetadataController * feat: add sdk support * test: add tests for identity metadata * chore: start openapi doc * fix: use noContent for delete * chore: add more tests * chore: expect 204 * chore: 204 for delete idm * feat: update openapi spec * fix: make key optional * fix: add UpsertIdentityMetadataRequest * chore: update description * chore: move to object
- Loading branch information
1 parent
bf4f026
commit 6268326
Showing
12 changed files
with
301 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { ConnectorHttpResponse, ConnectorIdentityMetadata, UpsertIdentityMetadataRequest } from "../types"; | ||
import { Endpoint } from "./Endpoint"; | ||
|
||
export class IdentityMetadataEndpoint extends Endpoint { | ||
public async upsertIdentityMetadata(request: UpsertIdentityMetadataRequest): Promise<ConnectorHttpResponse<ConnectorIdentityMetadata>> { | ||
return await this.put("/api/v2/IdentityMetadata", request); | ||
} | ||
|
||
public async getIdentityMetadata(reference: string, key?: string): Promise<ConnectorHttpResponse<ConnectorIdentityMetadata>> { | ||
return await this.get("/api/v2/IdentityMetadata", { reference: reference, key: key }); | ||
} | ||
|
||
public async deleteIdentityMetadata(reference: string, key?: string): Promise<ConnectorHttpResponse<void>> { | ||
return await this.delete("/api/v2/IdentityMetadata", { reference: reference, key: key }, 204); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/sdk/src/types/identityMetadata/ConnectorIdentityMetadata.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface ConnectorIdentityMetadata { | ||
reference: string; | ||
key?: string; | ||
value: unknown; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./ConnectorIdentityMetadata"; | ||
export * from "./requests/UpsertIdentityMetadataRequest"; |
5 changes: 5 additions & 0 deletions
5
packages/sdk/src/types/identityMetadata/requests/UpsertIdentityMetadataRequest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface UpsertIdentityMetadataRequest { | ||
reference: string; | ||
key?: string; | ||
value: unknown; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/modules/coreHttpApi/controllers/IdentityMetadataController.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ConsumptionServices } from "@nmshd/runtime"; | ||
import { Inject } from "@nmshd/typescript-ioc"; | ||
import { Accept, DELETE, GET, PUT, Path, QueryParam } from "@nmshd/typescript-rest"; | ||
import { Envelope } from "../../../infrastructure"; | ||
import { BaseController } from "../common/BaseController"; | ||
|
||
@Path("/api/v2/IdentityMetadata") | ||
export class IdentityMetadataController extends BaseController { | ||
public constructor(@Inject private readonly consumptionServices: ConsumptionServices) { | ||
super(); | ||
} | ||
|
||
@PUT | ||
@Accept("application/json") | ||
public async upsertIdentityMetadata(request: any): Promise<Envelope> { | ||
const result = await this.consumptionServices.identityMetadata.upsertIdentityMetadata(request); | ||
return this.ok(result); | ||
} | ||
|
||
@GET | ||
public async getIdentityMetadata(@QueryParam("reference") reference: string, @QueryParam("key") key?: string): Promise<Envelope> { | ||
const result = await this.consumptionServices.identityMetadata.getIdentityMetadata({ reference, key }); | ||
return this.ok(result); | ||
} | ||
|
||
@DELETE | ||
public async deleteIdentityMetadata(@QueryParam("reference") reference: string, @QueryParam("key") key?: string): Promise<void> { | ||
const result = await this.consumptionServices.identityMetadata.deleteIdentityMetadata({ reference, key }); | ||
return this.noContent(result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Random, RandomCharacterRange } from "@nmshd/transport"; | ||
import { ConnectorClientWithMetadata, Launcher } from "./lib/Launcher"; | ||
import { ValidationSchema } from "./lib/validation"; | ||
|
||
const launcher = new Launcher(); | ||
let client1: ConnectorClientWithMetadata; | ||
|
||
beforeAll(async () => { | ||
[client1] = await launcher.launch(1); | ||
}, 30000); | ||
|
||
afterAll(() => launcher.stop()); | ||
|
||
describe("IdentityMetadata", () => { | ||
test.each([ | ||
{ | ||
reference: "did:e:localhost:dids:1234567890abcdef123456", | ||
key: undefined, | ||
value: "value" | ||
}, | ||
{ | ||
reference: "did:e:localhost:dids:1234567890abcdef123456", | ||
key: undefined, | ||
value: { a: "json" } | ||
}, | ||
{ | ||
reference: "did:e:localhost:dids:1234567890abcdef123456", | ||
key: "key", | ||
value: "value" | ||
} | ||
])("should upsert an IdentityMetadata with key '$key' and value '$value'", async (data) => { | ||
const result = await client1.identityMetadata.upsertIdentityMetadata(data); | ||
expect(result).toBeSuccessful(ValidationSchema.IdentityMetadata); | ||
|
||
const identityMetadata = result.result; | ||
expect(identityMetadata.reference.toString()).toStrictEqual(data.reference); | ||
expect(identityMetadata.key).toStrictEqual(data.key); | ||
expect(identityMetadata.value).toStrictEqual(data.value); | ||
}); | ||
|
||
test("should get an IdentityMetadata", async () => { | ||
const reference = await generateReference(); | ||
await client1.identityMetadata.upsertIdentityMetadata({ reference: reference, value: "value" }); | ||
|
||
const result = await client1.identityMetadata.getIdentityMetadata(reference); | ||
expect(result).toBeSuccessful(ValidationSchema.IdentityMetadata); | ||
|
||
const identityMetadata = result.result; | ||
expect(identityMetadata.value).toBe("value"); | ||
}); | ||
|
||
test("should delete an IdentityMetadata", async () => { | ||
const reference = await generateReference(); | ||
await client1.identityMetadata.upsertIdentityMetadata({ reference: reference, value: "value" }); | ||
|
||
const result = await client1.identityMetadata.deleteIdentityMetadata(reference); | ||
expect(result).toBeSuccessfulVoidResult(); | ||
|
||
const getResult = await client1.identityMetadata.getIdentityMetadata(reference); | ||
expect(getResult).toBeAnError("IdentityMetadata not found. Make sure the ID exists and the record is not expired.", "error.runtime.recordNotFound"); | ||
}); | ||
}); | ||
|
||
async function generateReference(): Promise<string> { | ||
const identityPart = await Random.string(22, `${RandomCharacterRange.Digit}abcdef`); | ||
return `did:e:localhost:dids:${identityPart}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters