From 9a1a3b350d4147243dbe2ecfcdcb846c0f3c6dcb Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 6 Sep 2023 11:23:33 +0200 Subject: harness: get rid of deprecated merchant API client --- packages/taler-harness/src/harness/harness.ts | 143 +++++++------------------- 1 file changed, 38 insertions(+), 105 deletions(-) (limited to 'packages/taler-harness/src/harness/harness.ts') diff --git a/packages/taler-harness/src/harness/harness.ts b/packages/taler-harness/src/harness/harness.ts index 99151b219..a16cef7ba 100644 --- a/packages/taler-harness/src/harness/harness.ts +++ b/packages/taler-harness/src/harness/harness.ts @@ -1364,6 +1364,9 @@ export const harnessHttpLib = createPlatformHttpLib({ enableThrottling: false, }); +/** + * FIXME: Move this out of the harness. + */ export class MerchantApiClient { /** * Base URL for the particular instance that this merchant API client @@ -1513,95 +1516,32 @@ export class MerchantApiClient { ); } - private makeAuthHeader(): Record { - switch (this.auth.method) { - case "external": - return {}; - case "token": - return { - Authorization: `Bearer ${this.auth.token}`, - }; - } - } -} - -/** - * FIXME: This should be deprecated in favor of MerchantApiClient - * - * @deprecated use MerchantApiClient instead - */ -export namespace MerchantPrivateApi { - export async function createOrder( - merchantService: MerchantServiceInterface, - instanceName: string, - req: MerchantPostOrderRequest, - withAuthorization: WithAuthorization = {}, - ): Promise { - const baseUrl = merchantService.makeInstanceBaseUrl(instanceName); - let url = new URL("private/orders", baseUrl); - const resp = await harnessHttpLib.fetch(url.href, { - method: "POST", - body: req, - headers: withAuthorization as Record, - }); - return readSuccessResponseJsonOrThrow( - resp, - codecForMerchantPostOrderResponse(), - ); - } - - export async function createTemplate( - merchantService: MerchantServiceInterface, - instanceName: string, - req: MerchantTemplateAddDetails, - withAuthorization: WithAuthorization = {}, - ) { - const baseUrl = merchantService.makeInstanceBaseUrl(instanceName); - let url = new URL("private/templates", baseUrl); - const resp = await harnessHttpLib.fetch(url.href, { + async giveTip(req: RewardCreateRequest): Promise { + const reqUrl = new URL(`private/tips`, this.baseUrl); + const resp = await harnessHttpLib.fetch(reqUrl.href, { method: "POST", body: req, - headers: withAuthorization as Record, }); - if (resp.status !== 204) { - throw Error("failed to create template"); - } + // FIXME: validate + return resp.json(); } - export async function queryPrivateOrderStatus( - merchantService: MerchantServiceInterface, - query: PrivateOrderStatusQuery, - withAuthorization: WithAuthorization = {}, - ): Promise { - const reqUrl = new URL( - `private/orders/${query.orderId}`, - merchantService.makeInstanceBaseUrl(query.instance), - ); - if (query.sessionId) { - reqUrl.searchParams.set("session_id", query.sessionId); - } + async queryTippingReserves(): Promise { + const reqUrl = new URL(`private/reserves`, this.baseUrl); const resp = await harnessHttpLib.fetch(reqUrl.href, { - headers: withAuthorization as Record, + headers: this.makeAuthHeader(), }); - return readSuccessResponseJsonOrThrow( - resp, - codecForMerchantOrderPrivateStatusResponse(), - ); + // FIXME: validate + return resp.json(); } - export async function giveRefund( - merchantService: MerchantServiceInterface, - r: { - instance: string; - orderId: string; - amount: string; - justification: string; - }, - ): Promise<{ talerRefundUri: string }> { - const reqUrl = new URL( - `private/orders/${r.orderId}/refund`, - merchantService.makeInstanceBaseUrl(r.instance), - ); + async giveRefund(r: { + instance: string; + orderId: string; + amount: string; + justification: string; + }): Promise<{ talerRefundUri: string }> { + const reqUrl = new URL(`private/orders/${r.orderId}/refund`, this.baseUrl); const resp = await harnessHttpLib.fetch(reqUrl.href, { method: "POST", body: { @@ -1615,34 +1555,27 @@ export namespace MerchantPrivateApi { }; } - export async function queryTippingReserves( - merchantService: MerchantServiceInterface, - instance: string, - ): Promise { - const reqUrl = new URL( - `private/reserves`, - merchantService.makeInstanceBaseUrl(instance), - ); - const resp = await harnessHttpLib.fetch(reqUrl.href); - // FIXME: validate - return resp.json(); - } - - export async function giveTip( - merchantService: MerchantServiceInterface, - instance: string, - req: RewardCreateRequest, - ): Promise { - const reqUrl = new URL( - `private/tips`, - merchantService.makeInstanceBaseUrl(instance), - ); - const resp = await harnessHttpLib.fetch(reqUrl.href, { + async createTemplate(req: MerchantTemplateAddDetails) { + let url = new URL("private/templates", this.baseUrl); + const resp = await harnessHttpLib.fetch(url.href, { method: "POST", body: req, + headers: this.makeAuthHeader(), }); - // FIXME: validate - return resp.json(); + if (resp.status !== 204) { + throw Error("failed to create template"); + } + } + + private makeAuthHeader(): Record { + switch (this.auth.method) { + case "external": + return {}; + case "token": + return { + Authorization: `Bearer ${this.auth.token}`, + }; + } } } -- cgit v1.2.3