gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-typescript-core] 01/02: new api


From: Admin
Subject: [taler-typescript-core] 01/02: new api
Date: Mon, 17 Feb 2025 21:49:50 +0100

This is an automated email from the git hooks/post-receive script.

sebasjm pushed a commit to branch master
in repository taler-typescript-core.

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

    new api
---
 packages/taler-util/src/http-client/exchange.ts | 86 ++++++++++++++++++++++++-
 packages/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
index 8c928aac5..38c9d9c35 100644
--- 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
index 0f874a4ef..09d5a65cc 100644
--- 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;

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]