commit 485d8707002b64782ffcfe2a734880302b2b5527
parent 3054599b21c0a465c7c23a06b314648206b97120
Author: Florian Dold <dold@taler.net>
Date: Thu, 19 Nov 2026 23:22:23 +0100
taler-util: add merchant report test and delivery history requests
Diffstat:
3 files changed, 207 insertions(+), 0 deletions(-)
diff --git a/packages/taler-util/src/http-client/merchant.ts b/packages/taler-util/src/http-client/merchant.ts
@@ -79,6 +79,9 @@ import {
codecForReportAddedResponse,
codecForReportDetailResponse,
codecForReportsSummaryResponse,
+ codecForReportTestAccepted,
+ codecForReportDelivery,
+ codecForReportDeliveries,
codecForStatisticsAmountResponse,
codecForStatisticsCounterResponse,
codecForStatusGoto,
@@ -3540,6 +3543,82 @@ export class TalerMerchantInstanceHttpClient {
// Reports
//
+ async sendReportTest(
+ token: AccessToken,
+ body: TalerMerchantApi.ReportTestRequest,
+ ) {
+ const url = new URL(`private/report-tests`, this.baseUrl);
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "POST",
+ body,
+ cancellationToken: this.cancellationToken,
+ timeout: this.timeout,
+ headers: { Authorization: makeBearerTokenAuthHeader(token) },
+ });
+ switch (resp.status) {
+ case HttpStatusCode.Accepted:
+ return opSuccessFromHttp(resp, codecForReportTestAccepted());
+ case HttpStatusCode.BadRequest:
+ case HttpStatusCode.Unauthorized:
+ case HttpStatusCode.Forbidden:
+ case HttpStatusCode.NotFound:
+ case HttpStatusCode.NotImplemented:
+ return opKnownHttpFailure(resp.status, resp);
+ default:
+ return opUnknownHttpFailure(resp);
+ }
+ }
+
+ async getReportDelivery(token: AccessToken, id: number) {
+ const url = new URL(`private/report-deliveries/${id}`, this.baseUrl);
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "GET",
+ cancellationToken: this.cancellationToken,
+ timeout: this.timeout,
+ headers: { Authorization: makeBearerTokenAuthHeader(token) },
+ });
+ switch (resp.status) {
+ case HttpStatusCode.Ok:
+ return opSuccessFromHttp(resp, codecForReportDelivery());
+ case HttpStatusCode.BadRequest:
+ case HttpStatusCode.Unauthorized:
+ case HttpStatusCode.Forbidden:
+ case HttpStatusCode.NotFound:
+ case HttpStatusCode.NotImplemented:
+ return opKnownHttpFailure(resp.status, resp);
+ default:
+ return opUnknownHttpFailure(resp);
+ }
+ }
+
+ async listReportDeliveries(
+ token: AccessToken,
+ params: PaginationParams & { report_serial?: number } = {},
+ ) {
+ const url = new URL(`private/report-deliveries`, this.baseUrl);
+ addPaginationParams(url, params);
+ if (params.report_serial !== undefined)
+ url.searchParams.set("report_serial", String(params.report_serial));
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "GET",
+ cancellationToken: this.cancellationToken,
+ timeout: this.timeout,
+ headers: { Authorization: makeBearerTokenAuthHeader(token) },
+ });
+ switch (resp.status) {
+ case HttpStatusCode.Ok:
+ return opSuccessFromHttp(resp, codecForReportDeliveries());
+ case HttpStatusCode.BadRequest:
+ case HttpStatusCode.Unauthorized:
+ case HttpStatusCode.Forbidden:
+ case HttpStatusCode.NotFound:
+ case HttpStatusCode.NotImplemented:
+ return opKnownHttpFailure(resp.status, resp);
+ default:
+ return opUnknownHttpFailure(resp);
+ }
+ }
+
/**
* https://docs.taler.net/core/api-merchant.html#post--reports-$REPORT_ID
*/
diff --git a/packages/taler-util/src/http-client/report-deliveries.test.ts b/packages/taler-util/src/http-client/report-deliveries.test.ts
@@ -0,0 +1,58 @@
+/*
+ This file is part of GNU Taler
+ (C) 2026 Taler Systems S.A.
+
+ GNU Taler is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import assert from "node:assert";
+import { test } from "node:test";
+import { FakeHttpLib } from "../http-fake.js";
+import { HttpStatusCode } from "../http-status-codes.js";
+import { TalerMerchantInstanceHttpClient } from "./merchant.js";
+import { LongpollQueue } from "../longpoll-queue.js";
+
+import { CancellationToken } from "../CancellationToken.js";
+import type { AccessToken } from "../types-taler-common.js";
+
+test("report delivery requests forward the client's deadline and cancellation token", async () => {
+ const timeout = { d_ms: 1500 };
+ const cancellationToken = CancellationToken.CONTINUE;
+ const http = new FakeHttpLib().otherwise({
+ status: HttpStatusCode.Forbidden,
+ body: { code: 1 },
+ });
+ const client = new TalerMerchantInstanceHttpClient(
+ "https://merchant.example/",
+ {
+ httpClient: {
+ fetch(url, options) {
+ assert.equal(options?.timeout, timeout);
+ assert.equal(options?.cancellationToken, cancellationToken);
+ return http.fetch(url, options);
+ },
+ },
+ longpollQueue: new LongpollQueue(),
+ timeout,
+ cancellationToken,
+ },
+ );
+ const token = "secret-token:test" as AccessToken;
+ await client.sendReportTest(token, {
+ type: "scheduled",
+ report_serial: 3,
+ target_address: "test@example.com",
+ });
+ await client.getReportDelivery(token, 7);
+ await client.listReportDeliveries(token);
+ assert.equal(http.requests.length, 3);
+});
diff --git a/packages/taler-util/src/types-taler-merchant.ts b/packages/taler-util/src/types-taler-merchant.ts
@@ -25,6 +25,7 @@ import {
codecForList,
codecForNumber,
codecForString,
+ codecForStringUnion,
codecOptional,
} from "./codec.js";
import { CancellationToken } from "./CancellationToken.js";
@@ -5648,6 +5649,75 @@ export interface ReportAddRequest {
report_frequency_shift?: RelativeTime;
}
+export type ReportTestRequest =
+ | DraftReportTestRequest
+ | ScheduledReportTestRequest;
+
+export interface DraftReportTestRequest extends Omit<
+ ReportAddRequest,
+ "report_frequency" | "report_frequency_shift"
+> {
+ type: "draft";
+}
+
+export interface ScheduledReportTestRequest {
+ type: "scheduled";
+ report_serial: number;
+ target_address: string;
+}
+
+export interface ReportDelivery extends Omit<
+ ReportAddRequest,
+ "report_frequency" | "report_frequency_shift"
+> {
+ delivery_id: number;
+ report_serial?: number;
+ origin: "test" | "scheduled";
+ status: "queued" | "processing" | "succeeded" | "failed" | "unknown";
+ created_at: Timestamp;
+ started_at?: Timestamp;
+ finished_at?: Timestamp;
+ error_code?: number;
+ error_detail?: string;
+}
+
+export const codecForReportDelivery = () =>
+ buildCodecForObject<ReportDelivery>()
+ .property("delivery_id", codecForNumber())
+ .property("report_serial", codecOptional(codecForNumber()))
+ .property("origin", codecForStringUnion("test", "scheduled"))
+ .property(
+ "status",
+ codecForStringUnion(
+ "queued",
+ "processing",
+ "succeeded",
+ "failed",
+ "unknown",
+ ),
+ )
+ .property("description", codecForString())
+ .property("data_source", codecForString())
+ .property("program_section", codecForString())
+ .property("target_address", codecForString())
+ .property("mime_type", codecForString())
+ .property("created_at", codecForTimestamp)
+ .property("started_at", codecOptional(codecForTimestamp))
+ .property("finished_at", codecOptional(codecForTimestamp))
+ .property("error_code", codecOptional(codecForNumber()))
+ .property("error_detail", codecOptional(codecForString()))
+ .build("ReportDelivery");
+
+export const codecForReportDeliveries = () =>
+ buildCodecForObject<{ deliveries: ReportDelivery[] }>()
+ .property("deliveries", codecForList(codecForReportDelivery()))
+ .build("ReportDeliveries");
+
+export const codecForReportTestAccepted = () =>
+ buildCodecForObject<{ delivery_id: number }>()
+ .property("delivery_id", codecForNumber())
+ .build("ReportTestAccepted");
+
export interface ReportAddedResponse {
// Unique ID for the report.
report_serial_id: Integer;