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

feat: use v3 asset endpoints and drop deprecated v2 #58

Merged
merged 2 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
128 changes: 68 additions & 60 deletions src/controllers/management-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
ContractNegotiation,
ContractNegotiationRequest,
ContractNegotiationState,
DataAddressProperties,
Dataplane,
DataplaneInput,
IdResponse,
Expand Down Expand Up @@ -54,12 +53,13 @@ export class ManagementController {
async listDataplanes(
context: EdcConnectorClientContext,
): Promise<Dataplane[]> {
return this.#inner.request(context.management, {
path: "/v2/dataplanes",
method: "GET",
apiToken: context.apiToken,
})
.then(body => expandArray(body, () => new Dataplane()));
return this.#inner
.request(context.management, {
path: "/v2/dataplanes",
method: "GET",
apiToken: context.apiToken,
})
.then((body) => expandArray(body, () => new Dataplane()));
}

async createAsset(
Expand All @@ -68,23 +68,23 @@ export class ManagementController {
): Promise<IdResponse> {
return this.#inner
.request(context.management, {
path: "/v2/assets",
path: "/v3/assets",
method: "POST",
apiToken: context.apiToken,
body: {
...input,
"@context": this.defaultContextValues,
},
})
.then(body => expand(body, () => new IdResponse()));
.then((body) => expand(body, () => new IdResponse()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a question, why do we put brackets also when there's only a parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done automatically by my linter

}

async deleteAsset(
context: EdcConnectorClientContext,
assetId: string,
): Promise<void> {
return this.#inner.request(context.management, {
path: `/v2/assets/${assetId}`,
path: `/v3/assets/${assetId}`,
method: "DELETE",
apiToken: context.apiToken,
});
Expand All @@ -95,18 +95,7 @@ export class ManagementController {
assetId: string,
): Promise<AssetResponse> {
return this.#inner.request(context.management, {
path: `/v2/assets/${assetId}`,
method: "GET",
apiToken: context.apiToken,
});
}

async getAssetDataAddress(
context: EdcConnectorClientContext,
assetId: string,
): Promise<DataAddressProperties> {
return this.#inner.request(context.management, {
path: `/v2/assets/${assetId}/dataaddress`,
path: `/v3/assets/${assetId}`,
method: "GET",
apiToken: context.apiToken,
});
Expand All @@ -117,7 +106,7 @@ export class ManagementController {
query: QuerySpec = {},
): Promise<AssetResponse[]> {
return this.#inner.request(context.management, {
path: "/v2/assets/request",
path: "/v3/assets/request",
method: "POST",
apiToken: context.apiToken,
body:
Expand All @@ -130,6 +119,21 @@ export class ManagementController {
});
}

async updateAsset(
context: EdcConnectorClientContext,
input: AssetInput,
): Promise<void> {
return this.#inner.request(context.management, {
path: "/v3/assets",
method: "PUT",
apiToken: context.apiToken,
body: {
...input,
"@context": this.defaultContextValues,
},
});
}

async createPolicy(
context: EdcConnectorClientContext,
input: PolicyDefinitionInput,
Expand All @@ -144,7 +148,7 @@ export class ManagementController {
"@context": this.defaultContextValues,
},
})
.then(body => expand(body, () => new IdResponse()));
.then((body) => expand(body, () => new IdResponse()));
}

async deletePolicy(
Expand All @@ -162,12 +166,13 @@ export class ManagementController {
context: EdcConnectorClientContext,
policyId: string,
): Promise<PolicyDefinition> {
return this.#inner.request(context.management, {
path: `/v2/policydefinitions/${policyId}`,
method: "GET",
apiToken: context.apiToken,
})
.then(body => expand(body, () => new PolicyDefinition()));
return this.#inner
.request(context.management, {
path: `/v2/policydefinitions/${policyId}`,
method: "GET",
apiToken: context.apiToken,
})
.then((body) => expand(body, () => new PolicyDefinition()));
}

async queryAllPolicies(
Expand All @@ -187,7 +192,7 @@ export class ManagementController {
"@context": this.defaultContextValues,
},
})
.then(body => expandArray(body, () => new PolicyDefinition()));
.then((body) => expandArray(body, () => new PolicyDefinition()));
}

async createContractDefinition(
Expand All @@ -204,7 +209,7 @@ export class ManagementController {
"@context": this.defaultContextValues,
},
})
.then(body => expand(body, () => new IdResponse()));
.then((body) => expand(body, () => new IdResponse()));
}

async deleteContractDefinition(
Expand Down Expand Up @@ -246,7 +251,7 @@ export class ManagementController {
"@context": this.defaultContextValues,
},
})
.then(body => expandArray(body, () => new ContractDefinition()));
.then((body) => expandArray(body, () => new ContractDefinition()));
}

async requestCatalog(
Expand All @@ -264,7 +269,7 @@ export class ManagementController {
...input,
},
})
.then(body => expand(body, () => new Catalog()));
.then((body) => expand(body, () => new Catalog()));
}

async initiateContractNegotiation(
Expand All @@ -282,26 +287,27 @@ export class ManagementController {
...input,
},
})
.then(body => expand(body, () => new IdResponse()));
.then((body) => expand(body, () => new IdResponse()));
}

async queryNegotiations(
context: EdcConnectorClientContext,
query: QuerySpec = {},
): Promise<ContractNegotiation[]> {
return this.#inner.request(context.management, {
path: "/v2/contractnegotiations/request",
method: "POST",
apiToken: context.apiToken,
body:
Object.keys(query).length === 0
? null
: {
...query,
"@context": this.defaultContextValues,
},
})
.then(body => expandArray(body, () => new ContractNegotiation()));
return this.#inner
.request(context.management, {
path: "/v2/contractnegotiations/request",
method: "POST",
apiToken: context.apiToken,
body:
Object.keys(query).length === 0
? null
: {
...query,
"@context": this.defaultContextValues,
},
})
.then((body) => expandArray(body, () => new ContractNegotiation()));
}

async getNegotiation(
Expand All @@ -314,7 +320,7 @@ export class ManagementController {
method: "GET",
apiToken: context.apiToken,
})
.then(body => expand(body, () => new ContractNegotiation()));
.then((body) => expand(body, () => new ContractNegotiation()));
}

async getNegotiationState(
Expand All @@ -327,7 +333,7 @@ export class ManagementController {
method: "GET",
apiToken: context.apiToken,
})
.then(body => expand(body, () => new ContractNegotiationState()));
.then((body) => expand(body, () => new ContractNegotiationState()));
}

async cancelNegotiation(
Expand Down Expand Up @@ -362,7 +368,7 @@ export class ManagementController {
method: "GET",
apiToken: context.apiToken,
})
.then(body => expand(body, () => new ContractAgreement()));
.then((body) => expand(body, () => new ContractAgreement()));
}

async queryAllAgreements(
Expand All @@ -382,7 +388,7 @@ export class ManagementController {
"@context": this.defaultContextValues,
},
})
.then(body => expandArray(body, () => new ContractAgreement()));
.then((body) => expandArray(body, () => new ContractAgreement()));
}

async getAgreement(
Expand All @@ -395,7 +401,7 @@ export class ManagementController {
method: "GET",
apiToken: context.apiToken,
})
.then(body => expand(body, () => new ContractAgreement()));
.then((body) => expand(body, () => new ContractAgreement()));
}

async initiateTransfer(
Expand All @@ -413,7 +419,7 @@ export class ManagementController {
...input,
},
})
.then(body => expand(body, () => new IdResponse()));
.then((body) => expand(body, () => new IdResponse()));
}

async queryAllTransferProcesses(
Expand All @@ -425,12 +431,14 @@ export class ManagementController {
path: "/v2/transferprocesses/request",
method: "POST",
apiToken: context.apiToken,
body: Object.keys(query).length === 0 ? null : {
...query,
"@context": this.defaultContextValues,
},
body:
Object.keys(query).length === 0
? null
: {
...query,
"@context": this.defaultContextValues,
},
})
.then(body => expandArray(body, () => new TransferProcess()));
.then((body) => expandArray(body, () => new TransferProcess()));
}

}
3 changes: 1 addition & 2 deletions src/entities/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ interface AssetProperties {
contenttype?: string;
}

export interface AssetInput {
asset: Partial<Asset>;
export interface AssetInput extends Partial<Asset> {
dataAddress: Partial<DataAddress> & { properties?: Partial<DataAddress> };
}

Expand Down
1 change: 0 additions & 1 deletion src/entities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export interface ApiErrorDetail {
}

export interface QuerySpec {
filter?: string;
filterExpression?: Criterion[];
limit?: number;
offset?: number;
Expand Down
Loading