diff options
author | Florian Dold <florian@dold.me> | 2023-09-06 11:23:33 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-09-06 11:23:33 +0200 |
commit | 9a1a3b350d4147243dbe2ecfcdcb846c0f3c6dcb (patch) | |
tree | f9b01f5748edf391146d2bbaec62aad285d261ec /packages/taler-harness/src/harness/harness.ts | |
parent | c9a0d2eb968133b1ad156e1dc86e6c06dad09c7a (diff) | |
download | wallet-core-9a1a3b350d4147243dbe2ecfcdcb846c0f3c6dcb.tar.xz |
harness: get rid of deprecated merchant API client
Diffstat (limited to 'packages/taler-harness/src/harness/harness.ts')
-rw-r--r-- | packages/taler-harness/src/harness/harness.ts | 143 |
1 files changed, 38 insertions, 105 deletions
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<string, string> { - 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<MerchantPostOrderResponse> { - 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<string, string>, - }); - 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<RewardCreateConfirmation> { + const reqUrl = new URL(`private/tips`, this.baseUrl); + const resp = await harnessHttpLib.fetch(reqUrl.href, { method: "POST", body: req, - headers: withAuthorization as Record<string, string>, }); - 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<MerchantOrderPrivateStatusResponse> { - 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<TippingReserveStatus> { + const reqUrl = new URL(`private/reserves`, this.baseUrl); const resp = await harnessHttpLib.fetch(reqUrl.href, { - headers: withAuthorization as Record<string, string>, + 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<TippingReserveStatus> { - 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<RewardCreateConfirmation> { - 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<string, string> { + switch (this.auth.method) { + case "external": + return {}; + case "token": + return { + Authorization: `Bearer ${this.auth.token}`, + }; + } } } |