-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
3,795 additions
and
429 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
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,61 @@ | ||
import { EdcConnectorClientContext } from "../../context"; | ||
import { | ||
expand, | ||
expandArray, | ||
QuerySpec, | ||
JsonLdObject, | ||
JSON_LD_DEFAULT_CONTEXT, | ||
Edr | ||
} from "../../entities"; | ||
import { Inner } from "../../inner"; | ||
|
||
export class EdrController { | ||
#inner: Inner; | ||
#context?: EdcConnectorClientContext; | ||
|
||
constructor(inner: Inner, context?: EdcConnectorClientContext) { | ||
this.#inner = inner; | ||
this.#context = context; | ||
} | ||
|
||
async request(query: QuerySpec = {}, context?: EdcConnectorClientContext): Promise<Edr[]> { | ||
const actualContext = context || this.#context!; | ||
|
||
return this.#inner | ||
.request(actualContext.management, { | ||
path: "/v1/edrs/request", | ||
method: "POST", | ||
apiToken: actualContext.apiToken, | ||
body: | ||
Object.keys(query).length === 0 | ||
? null | ||
: { | ||
...query, | ||
"@context": JSON_LD_DEFAULT_CONTEXT, | ||
}, | ||
}) | ||
.then((body) => expandArray(body, () => new Edr())); | ||
} | ||
|
||
async delete(edrId: string, context?: EdcConnectorClientContext): Promise<void> { | ||
const actualContext = context || this.#context!; | ||
|
||
return this.#inner.request(actualContext.management, { | ||
path: `/v1/edrs/${edrId}`, | ||
method: "DELETE", | ||
apiToken: actualContext.apiToken, | ||
}); | ||
} | ||
|
||
async dataAddress(edrId: string, context?: EdcConnectorClientContext): Promise<JsonLdObject> { | ||
const actualContext = context || this.#context!; | ||
|
||
return this.#inner.request(actualContext.management, { | ||
path: `/v1/edrs/${edrId}/dataaddress`, | ||
method: "GET", | ||
apiToken: actualContext.apiToken, | ||
}) | ||
.then((body) => expand(body, () => new JsonLdObject())); | ||
} | ||
|
||
} |
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,29 @@ | ||
import { JsonLdId } from "./jsonld"; | ||
|
||
export class Edr extends JsonLdId { | ||
|
||
get transferProcessId(): string { | ||
return this.mandatoryValue('edc', 'transferProcessId'); | ||
} | ||
|
||
get agreementId(): string { | ||
return this.mandatoryValue('edc', 'agreementId'); | ||
} | ||
|
||
get contractNegotiationId(): string { | ||
return this.mandatoryValue('edc', 'contractNegotiationId'); | ||
} | ||
|
||
get assetId(): string { | ||
return this.mandatoryValue('edc', 'assetId'); | ||
} | ||
|
||
get providerId(): string { | ||
return this.mandatoryValue('edc', 'providerId'); | ||
} | ||
|
||
get createdAt(): string { | ||
return this.mandatoryValue('edc', 'createdAt'); | ||
} | ||
|
||
} |
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
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,48 @@ | ||
import { GenericContainer, StartedTestContainer } from "testcontainers"; | ||
import { EdcConnectorClient } from "../../../src"; | ||
|
||
describe("edrs", () => { | ||
let startedContainer: StartedTestContainer; | ||
let edcClient: EdcConnectorClient; | ||
|
||
beforeAll(async () => { | ||
startedContainer = await new GenericContainer("stoplight/prism:5.8.1") | ||
.withCopyFilesToContainer([{ source: "tests/management-api.yaml", target: "/management-api.yml" }]) | ||
.withCommand(["mock", "-h", "0.0.0.0", "/management-api.yml"]) | ||
.withExposedPorts(4010) | ||
.start(); | ||
|
||
edcClient = new EdcConnectorClient.Builder() | ||
.managementUrl("http://localhost:" + startedContainer.getFirstMappedPort()) | ||
.build(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await startedContainer.stop(); | ||
}); | ||
|
||
it("should request edrs", async () => { | ||
const result = await edcClient.management.edrs.request(); | ||
|
||
expect(result.length).toBeGreaterThan(0); | ||
expect(result[0].transferProcessId).not.toBeNull(); | ||
expect(result[0].contractNegotiationId).not.toBeNull(); | ||
expect(result[0].assetId).not.toBeNull(); | ||
expect(result[0].providerId).not.toBeNull(); | ||
expect(result[0].agreementId).not.toBeNull(); | ||
}) | ||
|
||
it("should delete edrs", async () => { | ||
await expect(edcClient.management.edrs.delete("edrId")).resolves | ||
.not.toThrowError(); | ||
}); | ||
|
||
it("should get data address", async () => { | ||
const dataAddress = await edcClient.management.edrs.dataAddress("edrId"); | ||
|
||
console.log(dataAddress) | ||
|
||
expect(dataAddress.types().length).toBeGreaterThan(0); | ||
}); | ||
|
||
}); |
Oops, something went wrong.