taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit e7055cac42b76459d30e94329133b55a470c5e9f
parent e63dfd6bb587ca65b2b418bf2e1851745b2da0b2
Author: Sebastian <sebasjm@gmail.com>
Date:   Mon, 17 Feb 2025 17:48:23 -0300

new api

Diffstat:
Mpackages/taler-util/src/http-client/exchange.ts | 86++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Mpackages/taler-util/src/types-taler-exchange.ts | 34++++++++++++++++++++++++++++++++++
2 files changed, 117 insertions(+), 3 deletions(-)

diff --git a/packages/taler-util/src/http-client/exchange.ts b/packages/taler-util/src/http-client/exchange.ts @@ -14,6 +14,7 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ +import { Codec, codecForAny } from "../codec.js"; import { HttpRequestLibrary, readSuccessResponseJsonOrThrow, @@ -35,7 +36,6 @@ import { opSuccessFromHttp, opUnknownFailure, } from "../operation.js"; -import { Codec, codecForAny } from "../codec.js"; import { TalerSignaturePurpose, amountToBuffer, @@ -71,6 +71,7 @@ import { codecForEventCounter, codecForExchangeConfig, codecForExchangeKeysResponse, + codecForExchangeTransferList, codecForKycProcessClientInformation, codecForKycProcessStartInformation, codecForLegitimizationNeededResponse, @@ -78,10 +79,11 @@ import { import { CacheEvictor, addPaginationParams, nullEvictor } from "./utils.js"; import { TalerError } from "../errors.js"; -import { TalerErrorCode } from "../taler-error-codes.js"; -import { codecForEmptyObject } from "../types-taler-wallet.js"; import { canonicalJson } from "../helpers.js"; +import { AmountJson, Amounts } from "../index.js"; +import { TalerErrorCode } from "../taler-error-codes.js"; import { AbsoluteTime } from "../time.js"; +import { codecForEmptyObject } from "../types-taler-wallet.js"; export type TalerExchangeResultByMethod< prop extends keyof TalerExchangeHttpClient, @@ -1020,6 +1022,84 @@ export class TalerExchangeHttpClient { } } + /** + * https://docs.taler.net/core/api-exchange.html#get--aml-$OFFICER_PUB-transfers-credit + * + */ + async getTransfersCredit( + auth: OfficerAccount, + params: PaginationParams & { threshold?: AmountJson } = {}, + ) { + const url = new URL(`aml/${auth.id}/transfers-credit`, this.baseUrl); + + addPaginationParams(url, params); + + if (params.threshold) { + url.searchParams.set("threshold", Amounts.stringify(params.threshold)); + } + + const resp = await this.httpLib.fetch(url.href, { + method: "GET", + headers: { + "Taler-AML-Officer-Signature": buildAMLQuerySignature(auth.signingKey), + }, + }); + + switch (resp.status) { + case HttpStatusCode.Ok: + return opSuccessFromHttp(resp, codecForExchangeTransferList()); + case HttpStatusCode.NoContent: + return opFixedSuccess({ transfers: [] }); + case HttpStatusCode.Forbidden: + return opKnownHttpFailure(resp.status, resp); + case HttpStatusCode.NotFound: + return opKnownHttpFailure(resp.status, resp); + case HttpStatusCode.Conflict: + return opKnownHttpFailure(resp.status, resp); + default: + return opUnknownFailure(resp, await readTalerErrorResponse(resp)); + } + } + + /** + * https://docs.taler.net/core/api-exchange.html#get--aml-$OFFICER_PUB-transfers-debit + * + */ + async getTransfersDebit( + auth: OfficerAccount, + params: PaginationParams & { threshold?: AmountString } = {}, + ) { + const url = new URL(`aml/${auth.id}/transfers-debit`, this.baseUrl); + + addPaginationParams(url, params); + + if (params.threshold) { + url.searchParams.set("threshold", Amounts.stringify(params.threshold)); + } + + const resp = await this.httpLib.fetch(url.href, { + method: "GET", + headers: { + "Taler-AML-Officer-Signature": buildAMLQuerySignature(auth.signingKey), + }, + }); + + switch (resp.status) { + case HttpStatusCode.Ok: + return opSuccessFromHttp(resp, codecForExchangeTransferList()); + case HttpStatusCode.NoContent: + return opFixedSuccess({ transfers: [] }); + case HttpStatusCode.Forbidden: + return opKnownHttpFailure(resp.status, resp); + case HttpStatusCode.NotFound: + return opKnownHttpFailure(resp.status, resp); + case HttpStatusCode.Conflict: + return opKnownHttpFailure(resp.status, resp); + default: + return opUnknownFailure(resp, await readTalerErrorResponse(resp)); + } + } + // RESERVE control /** diff --git a/packages/taler-util/src/types-taler-exchange.ts b/packages/taler-util/src/types-taler-exchange.ts @@ -34,6 +34,7 @@ import { codecForCurrencySpecificiation, codecForEither, codecForMap, + codecForPaytoString, codecForURN, codecOptionalDefault, strcmp, @@ -2551,6 +2552,39 @@ export const codecForKycProcessClientInformation = ) .build("TalerExchangeApi.KycProcessClientInformation"); +export const codecForExchangeTransferList = (): Codec<ExchangeTransferList> => + buildCodecForObject<ExchangeTransferList>() + .property("transfers", codecForList(codecForExchangeTransferListEntry())) + .build("TalerExchangeApi.ExchangeTransferList"); + +export const codecForExchangeTransferListEntry = + (): Codec<ExchangeTransferListEntry> => + buildCodecForObject<ExchangeTransferListEntry>() + .property("rowid", codecForNumber()) + .property("payto_uri", codecForPaytoString()) + .property("amount", codecForAmountString()) + .property("execution_time", codecForTimestamp) + .build("TalerExchangeApi.ExchangeTransferListEntry"); + +export interface ExchangeTransferList { + // Matching transaction of the exchange + transfers: ExchangeTransferListEntry[]; +} + +export interface ExchangeTransferListEntry { + // Row ID of the record. Used to filter by offset. + rowid: Integer; + + // payto://-URI of the other account. + payto_uri: string; + + // The amount involved. + amount: Amount; + + // Time when the transfer was made + execution_time: Timestamp; +} + export interface KycProcessStartInformation { // URL to open. redirect_url: string;