From 592ecda944bf5b32e86f6c42ee8e1f17d9c86451 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sat, 14 Oct 2023 01:19:30 -0300 Subject: complet bank api --- packages/taler-util/src/http-client/bank-wire.ts | 98 ++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 packages/taler-util/src/http-client/bank-wire.ts (limited to 'packages/taler-util/src/http-client/bank-wire.ts') diff --git a/packages/taler-util/src/http-client/bank-wire.ts b/packages/taler-util/src/http-client/bank-wire.ts new file mode 100644 index 000000000..9f2b859ed --- /dev/null +++ b/packages/taler-util/src/http-client/bank-wire.ts @@ -0,0 +1,98 @@ +import { HttpRequestLibrary, makeBasicAuthHeader, readSuccessResponseJsonOrThrow } from "../http-common.js"; +import { createPlatformHttpLib } from "../http.js"; +import { TalerWireGatewayApi, codecForAddIncomingResponse, codecForIncomingHistory, codecForOutgoingHistory, codecForTransferResponse } from "./types.js"; +import { PaginationParams, UserAndPassword, addPaginationParams } from "./utils.js"; + +/** + * The API is used by the exchange to trigger transactions and query + * incoming transactions, as well as by the auditor to query incoming + * and outgoing transactions. + * + * https://docs.taler.net/core/api-bank-wire.html + */ +export class TalerWireGatewayHttpClient { + httpLib: HttpRequestLibrary; + + constructor( + private baseUrl: string, + private username: string, + httpClient?: HttpRequestLibrary, + ) { + this.httpLib = httpClient ?? createPlatformHttpLib(); + } + + /** + * https://docs.taler.net/core/api-bank-wire.html#post-$BASE_URL-transfer + * + */ + async transfer( + auth: string, + body: TalerWireGatewayApi.TransferRequest, + ): Promise { + const url = new URL(`transfer`, this.baseUrl); + const resp = await this.httpLib.fetch(url.href, { + method: "POST", + headers: { + Authorization: makeBasicAuthHeader(this.username, auth), + }, + body + }); + return readSuccessResponseJsonOrThrow(resp, codecForTransferResponse()); + } + + /** + * https://docs.taler.net/core/api-bank-wire.html#get-$BASE_URL-history-incoming + * + */ + async getHistoryIncoming( + auth: string, + pagination?: PaginationParams + ): Promise { + const url = new URL(`history/incoming`, this.baseUrl); + addPaginationParams(url, pagination) + const resp = await this.httpLib.fetch(url.href, { + method: "GET", + headers: { + Authorization: makeBasicAuthHeader(this.username, auth), + } + }); + return readSuccessResponseJsonOrThrow(resp, codecForIncomingHistory()); + } + /** + * https://docs.taler.net/core/api-bank-wire.html#get-$BASE_URL-history-outgoing + * + */ + async getHistoryOutgoing( + auth: string, + pagination?: PaginationParams + ): Promise { + const url = new URL(`history/outgoing`, this.baseUrl); + addPaginationParams(url, pagination) + const resp = await this.httpLib.fetch(url.href, { + method: "GET", + headers: { + Authorization: makeBasicAuthHeader(this.username, auth), + } + }); + return readSuccessResponseJsonOrThrow(resp, codecForOutgoingHistory()); + } + /** + * https://docs.taler.net/core/api-bank-wire.html#post-$BASE_URL-admin-add-incoming + * + */ + async addIncoming( + auth: string, + body: TalerWireGatewayApi.AddIncomingRequest, + ): Promise { + const url = new URL(`admin/add-incoming`, this.baseUrl); + const resp = await this.httpLib.fetch(url.href, { + method: "POST", + headers: { + Authorization: makeBasicAuthHeader(this.username, auth), + }, + body + }); + return readSuccessResponseJsonOrThrow(resp, codecForAddIncomingResponse()); + } +} + -- cgit v1.2.3