Nostro/interfaces/Nostro-Client.cppm

74 lines
4.2 KiB
Text
Raw Normal View History

2026-11-01 18:35:23 +01:00
// SPDX-License-Identifier: LGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
export module Nostro:Client;
#ifdef NOSTRO_DBUS_ENABLED
import std;
import :Account;
import :Bunq;
import :Bus;
import :Transaction;
namespace Nostro {
// An error nostrod answered with, by its D-Bus name, for the errors a client tells apart: Bus::errorBank,
// Bus::errorOAuthCannotPay, Bus::errorCancelled, org.freedesktop.DBus.Error.AccessDenied and the like. Input
// nostrod refused before doing anything comes as std::invalid_argument instead.
export struct DaemonError : std::runtime_error {
std::string name;
DaemonError(std::string name, const std::string& message);
};
// nostrod over the system bus: each method of its interface (Bus::methods), with nostro's own types. `account` is
// an account's name or IBAN. A call may wait for a password dialog, which nostrod has polkit show, and for the
// bank. The library's warnings during the calls come out of TakeNotes().
export class Client {
public:
// Connects to the system bus; D-Bus starts nostrod with the first call. A call waits up to `timeout` for its
// answer: long enough for the user to type a password, and for the bank's rate limits. Throws when there is
// no system bus.
static Client System(std::chrono::seconds timeout = std::chrono::minutes(10));
std::vector<ConnectorSummary> Connectors();
// `environment` is "production", "sandbox", or empty for the one the key's prefix says.
AddedConnector AddBunq(std::string_view apiKey, std::string_view allowedIps, std::string_view environment);
AddedConnector AddBunqOAuth(std::string_view environment, std::string_view clientId, std::string_view clientSecret, std::string_view redirectUri, std::string_view code);
// By name, or by its number in Connectors(); returns the name.
std::string RemoveConnector(std::string_view connector);
std::vector<ConnectorAccounts> Accounts();
// Fetches what is new first, then answers from the stored history.
std::vector<Transaction> Transactions(std::string_view account, const TransactionQuery& query);
Created Send(std::string_view account, std::string_view to, std::string_view name, std::int64_t amount, std::string_view description);
Created Schedule(std::string_view account, std::string_view to, std::string_view name, std::int64_t amount, std::string_view description, const BunqSchedule& schedule);
Created Draft(std::string_view account, std::string_view to, std::string_view name, std::int64_t amount, std::string_view description);
BunqPaymentRequest Request(std::string_view account, std::string_view from, std::string_view name, std::int64_t amount, std::string_view description);
std::vector<BunqPaymentRequest> Requests(std::string_view account);
void RevokeRequest(std::string_view account, std::uint64_t id);
std::vector<BunqIncomingRequest> IncomingRequests(std::string_view account);
void RespondToRequest(std::string_view account, std::uint64_t id, bool accept);
std::vector<BunqScheduledPayment> ScheduledPayments(std::string_view account);
void CancelScheduledPayment(std::string_view account, std::uint64_t id);
std::vector<BunqDraftPayment> DraftPayments(std::string_view account);
void RespondToDraftPayment(std::string_view account, std::uint64_t id, bool accept);
std::vector<ConnectorCards> Cards();
// "ACTIVE", "DEACTIVATED", "LOST" or "STOLEN"; returns the card as bunq has it afterwards.
BunqCard SetCardStatus(std::uint64_t card, std::string_view status);
// The account apps' checkouts (Nostro.Checkout) pay from: none until one is chosen, or once it is gone.
std::optional<Account> DefaultCheckoutAccount();
// Chooses it, and returns it. An account reached through OAuth cannot pay a shop, and is refused.
Account SetDefaultCheckoutAccount(std::string_view account);
// The library's warnings from the calls so far, taken out.
std::vector<std::string> TakeNotes();
private:
explicit Client(Bus::BusPtr bus);
Bus::BusPtr bus;
std::vector<std::string> notes;
};
}
#endif