diff options
Diffstat (limited to 'packages/taler-util/src/http-client/types.ts')
-rw-r--r-- | packages/taler-util/src/http-client/types.ts | 456 |
1 files changed, 261 insertions, 195 deletions
diff --git a/packages/taler-util/src/http-client/types.ts b/packages/taler-util/src/http-client/types.ts index a2f709769..9268f6387 100644 --- a/packages/taler-util/src/http-client/types.ts +++ b/packages/taler-util/src/http-client/types.ts @@ -1,4 +1,3 @@ -import { deprecate } from "util"; import { codecForAmountString } from "../amounts.js"; import { Codec, @@ -14,11 +13,14 @@ import { codecForNumber, codecForString, codecOptional, + codecOptionalDefault, } from "../codec.js"; import { PaytoString, codecForPaytoString } from "../payto.js"; import { AmountString, + ExchangeWireAccount, InternationalizedString, + codecForExchangeWireAccount, codecForInternationalizedString, codecForLocation, } from "../taler-types.js"; @@ -27,7 +29,6 @@ import { AbsoluteTime, TalerProtocolDuration, TalerProtocolTimestamp, - codecForAbsoluteTime, codecForDuration, codecForTimestamp, } from "../time.js"; @@ -196,16 +197,19 @@ export type AccessToken = string & { /** * Create a rfc8959 access token. * Adds secret-token: prefix if there is none. + * Encode the token with rfc7230 to send in a http header. * - * @deprecated use createRFC8959AccessToken * @param token * @returns */ -export function createAccessToken(token: string): AccessToken { +export function createRFC8959AccessTokenEncoded(token: string): AccessToken { return ( - token.startsWith("secret-token:") ? token : `secret-token:${token}` + token.startsWith("secret-token:") + ? token + : `secret-token:${encodeURIComponent(token)}` ) as AccessToken; } + /** * Create a rfc8959 access token. * Adds secret-token: prefix if there is none. @@ -213,11 +217,12 @@ export function createAccessToken(token: string): AccessToken { * @param token * @returns */ -export function createRFC8959AccessToken(token: string): AccessToken { +export function createRFC8959AccessTokenPlain(token: string): AccessToken { return ( token.startsWith("secret-token:") ? token : `secret-token:${token}` ) as AccessToken; } + /** * Convert string to access token. * @@ -336,6 +341,7 @@ export const codecForCoreBankConfig = (): Codec<TalerCorebankApi.Config> => .property("name", codecForConstString("libeufin-bank")) .property("version", codecForString()) .property("bank_name", codecForString()) + .property("base_url", codecOptional(codecForString())) .property("allow_conversion", codecForBoolean()) .property("allow_registrations", codecForBoolean()) .property("allow_deletions", codecForBoolean()) @@ -353,7 +359,7 @@ export const codecForCoreBankConfig = (): Codec<TalerCorebankApi.Config> => ), ), ) - .property("wire_type", codecForString()) + .property("wire_type", codecOptionalDefault(codecForString(), "iban")) .build("TalerCorebankApi.Config"); //FIXME: implement this codec @@ -598,6 +604,37 @@ export const codecForInventoryEntry = .property("product_serial", codecForNumber()) .build("TalerMerchantApi.InventoryEntry"); +export const codecForMerchantPosProductDetail = + (): Codec<TalerMerchantApi.MerchantPosProductDetail> => + buildCodecForObject<TalerMerchantApi.MerchantPosProductDetail>() + .property("product_serial", codecForNumber()) + .property("product_id", codecOptional(codecForString())) + .property("categories", codecForList(codecForNumber())) + .property("description", codecForString()) + .property("description_i18n", codecForInternationalizedString()) + .property("unit", codecForString()) + .property("price", codecForAmountString()) + .property("image", codecForString()) + .property("taxes", codecOptional(codecForList(codecForTax()))) + .property("total_stock", codecForNumber()) + .property("minimum_age", codecOptional(codecForNumber())) + .build("TalerMerchantApi.MerchantPosProductDetail"); + +export const codecForMerchantCategory = + (): Codec<TalerMerchantApi.MerchantCategory> => + buildCodecForObject<TalerMerchantApi.MerchantCategory>() + .property("id", codecForNumber()) + .property("name", codecForString()) + .property("name_i18n", codecForInternationalizedString()) + .build("TalerMerchantApi.MerchantCategory"); + +export const codecForFullInventoryDetailsResponse = + (): Codec<TalerMerchantApi.FullInventoryDetailsResponse> => + buildCodecForObject<TalerMerchantApi.FullInventoryDetailsResponse>() + .property("categories", codecForList(codecForMerchantCategory())) + .property("products", codecForList(codecForMerchantPosProductDetail())) + .build("TalerMerchantApi.FullInventoryDetailsResponse"); + export const codecForProductDetail = (): Codec<TalerMerchantApi.ProductDetail> => buildCodecForObject<TalerMerchantApi.ProductDetail>() @@ -606,9 +643,9 @@ export const codecForProductDetail = .property("unit", codecForString()) .property("price", codecForAmountString()) .property("image", codecForString()) - .property("taxes", codecForList(codecForTax())) - .property("address", codecForLocation()) - .property("next_restock", codecForTimestamp) + .property("taxes", codecOptional(codecForList(codecForTax()))) + .property("address", codecOptional(codecForLocation())) + .property("next_restock", codecOptional(codecForTimestamp)) .property("total_stock", codecForNumber()) .property("total_sold", codecForNumber()) .property("total_lost", codecForNumber()) @@ -888,8 +925,6 @@ export const codecForTemplateContractDetailsDefaults = .property("summary", codecOptional(codecForString())) .property("currency", codecOptional(codecForString())) .property("amount", codecOptional(codecForAmountString())) - .property("minimum_age", codecOptional(codecForNumber())) - .property("pay_duration", codecOptional(codecForDuration)) .build("TalerMerchantApi.TemplateContractDetailsDefaults"); export const codecForWalletTemplateDetails = @@ -1033,10 +1068,20 @@ export const codecForAccountMinimalData = .property("name", codecForString()) .property("payto_uri", codecForPaytoString()) .property("balance", codecForBalance()) + .property("row_id", codecForNumber()) .property("debit_threshold", codecForAmountString()) + .property("min_cashout", codecOptional(codecForAmountString())) .property("is_public", codecForBoolean()) .property("is_taler_exchange", codecForBoolean()) - .property("row_id", codecOptional(codecForNumber())) + .property( + "status", + codecOptional( + codecForEither( + codecForConstString("active"), + codecForConstString("deleted"), + ), + ), + ) .build("TalerCorebankApi.AccountMinimalData"); export const codecForListBankAccountsResponse = @@ -1051,6 +1096,7 @@ export const codecForAccountData = (): Codec<TalerCorebankApi.AccountData> => .property("balance", codecForBalance()) .property("payto_uri", codecForPaytoString()) .property("debit_threshold", codecForAmountString()) + .property("min_cashout", codecOptional(codecForAmountString())) .property("contact_data", codecOptional(codecForChallengeContactData())) .property("cashout_payto_uri", codecOptional(codecForPaytoString())) .property("is_public", codecForBoolean()) @@ -1064,6 +1110,15 @@ export const codecForAccountData = (): Codec<TalerCorebankApi.AccountData> => ), ), ) + .property( + "status", + codecOptional( + codecForEither( + codecForConstString("active"), + codecForConstString("deleted"), + ), + ), + ) .build("TalerCorebankApi.AccountData"); export const codecForChallengeContactData = @@ -1256,7 +1311,7 @@ export const codecForBankWithdrawalOperationStatus = codecForConstString("confirmed"), ), ) - .property("amount", codecForAmountString()) + .property("amount", codecOptional(codecForAmountString())) .property("sender_wire", codecOptional(codecForPaytoString())) .property("suggested_exchange", codecOptional(codecForString())) .property("confirm_transfer_url", codecOptional(codecForURL())) @@ -1387,7 +1442,7 @@ export const codecForAddIncomingResponse = export const codecForAmlRecords = (): Codec<TalerExchangeApi.AmlRecords> => buildCodecForObject<TalerExchangeApi.AmlRecords>() .property("records", codecForList(codecForAmlRecord())) - .build("TalerExchangeApi.PublicAccountsResponse"); + .build("TalerExchangeApi.AmlRecords"); export const codecForAmlRecord = (): Codec<TalerExchangeApi.AmlRecord> => buildCodecForObject<TalerExchangeApi.AmlRecord>() @@ -1562,6 +1617,21 @@ export const codecForChallengerInfoResponse = .property("expires", codecForTimestamp) .build("ChallengerApi.ChallengerInfoResponse"); +export const codecForTemplateEditableDetails = + (): Codec<TalerMerchantApi.TemplateEditableDetails> => + buildCodecForObject<TalerMerchantApi.TemplateEditableDetails>() + .property("summary", codecOptional(codecForString())) + .property("currency", codecOptional(codecForString())) + .property("amount", codecOptional(codecForAmountString())) + .build("TemplateEditableDetails"); + +export const codecForMerchantReserveCreateConfirmation = + (): Codec<TalerMerchantApi.MerchantReserveCreateConfirmation> => + buildCodecForObject<TalerMerchantApi.MerchantReserveCreateConfirmation>() + .property("accounts", codecForList(codecForExchangeWireAccount())) + .property("reserve_pub", codecForString()) + .build("MerchantReserveCreateConfirmation"); + type EmailAddress = string; type PhoneNumber = string; type EddsaSignature = string; @@ -1960,7 +2030,7 @@ export namespace TalerBankIntegrationApi { // Amount that will be withdrawn with this operation // (raw amount without fee considerations). - amount: AmountString; + amount: AmountString | undefined; // Bank account of the customer that is withdrawing, as a // payto URI. @@ -2039,6 +2109,11 @@ export namespace TalerCorebankApi { // @since v4, will become mandatory in the next version. bank_name: string; + // Advertised base URL to use when you sharing an URL with another + // program. + // @since v4. + base_url?: string; + // If 'true' the server provides local currency conversion support // If 'false' some parts of the API are not supported and return 501 allow_conversion: boolean; @@ -2197,6 +2272,11 @@ export namespace TalerCorebankApi { // Only admin can set this property. debit_threshold?: AmountString; + // If present, set a custom minimum cashout amount for this account. + // Only admin can set this property + // @since v4 + min_cashout?: AmountString; + // If present, enables 2FA and set the TAN channel used for challenges // Only admin can set this property, other user can reconfig their account // after creation. @@ -2238,7 +2318,11 @@ export namespace TalerCorebankApi { // Only admin can change this property. debit_threshold?: AmountString; - //FIX: missing in SPEC + // If present, change the custom minimum cashout amount for this account. + // Only admin can set this property + // @since v4 + min_cashout?: AmountString; + // If present, enables 2FA and set the TAN channel used for challenges tan_channel?: TanChannel | null; } @@ -2295,6 +2379,11 @@ export namespace TalerCorebankApi { // Number indicating the max debit allowed for the requesting user. debit_threshold: AmountString; + // Custom minimum cashout amount for this account. + // If null or absent, the global conversion fee is used. + // @since v4 + min_cashout?: AmountString; + // Is this account visible to anyone? is_public: boolean; @@ -2304,6 +2393,14 @@ export namespace TalerCorebankApi { // Opaque unique ID used for pagination. // @since v4, will become mandatory in the future. row_id?: Integer; + + // Current status of the account + // active: the account can be used + // deleted: the account has been deleted but is retained for compliance + // reasons, only the administrator can access it + // Default to 'active' is missing + // @since v4, will become mandatory in the next version. + status?: "active" | "deleted"; } export interface AccountData { @@ -2319,6 +2416,11 @@ export namespace TalerCorebankApi { // Number indicating the max debit allowed for the requesting user. debit_threshold: AmountString; + // Custom minimum cashout amount for this account. + // If null or absent, the global conversion fee is used. + // @since v4 + min_cashout?: AmountString; + contact_data?: ChallengeContactData; // 'payto' address pointing the bank account @@ -2337,6 +2439,14 @@ export namespace TalerCorebankApi { // Is 2FA enabled and what channel is used for challenges? tan_channel?: TanChannel; + + // Current status of the account + // active: the account can be used + // deleted: the account has been deleted but is retained for compliance + // reasons, only the administrator can access it + // Default to 'active' is missing + // @since v4, will become mandatory in the next version. + status?: "active" | "deleted"; } export interface CashoutRequest { @@ -4003,6 +4113,68 @@ export namespace TalerMerchantApi { product_serial: Integer; } + export interface FullInventoryDetailsResponse { + // List of products that are present in the inventory. + products: MerchantPosProductDetail[]; + + // List of categories in the inventory. + categories: MerchantCategory[]; + } + + export interface MerchantPosProductDetail { + // A unique numeric ID of the product + product_serial: number; + + // A merchant-internal unique identifier for the product + product_id?: string; + + // A list of category IDs this product belongs to. + // Typically, a product only belongs to one category, but more than one is supported. + categories: number[]; + + // Human-readable product description. + description: string; + + // Map from IETF BCP 47 language tags to localized descriptions. + description_i18n: { [lang_tag: string]: string }; + + // Unit in which the product is measured (liters, kilograms, packages, etc.). + unit: string; + + // The price for one unit of the product. Zero is used + // to imply that this product is not sold separately, or + // that the price is not fixed, and must be supplied by the + // front-end. If non-zero, this price MUST include applicable + // taxes. + price: AmountString; + + // An optional base64-encoded product image. + image?: ImageDataUrl; + + // A list of taxes paid by the merchant for one unit of this product. + taxes?: Tax[]; + + // Number of units of the product in stock in sum in total, + // including all existing sales ever. Given in product-specific + // units. + // Optional, if missing treat as "infinite". + total_stock?: Integer; + + // Minimum age buyer must have (in years). + minimum_age?: Integer; + } + + export interface MerchantCategory { + // A unique numeric ID of the category + id: number; + + // The name of the category. This will be shown to users and used in the order summary. + name: string; + + // Map from IETF BCP 47 language tags to localized names + name_i18n?: { [lang_tag: string]: string }; + } + export interface ProductDetail { // Human-readable product description. description: string; @@ -4024,7 +4196,7 @@ export namespace TalerMerchantApi { image: ImageDataUrl; // A list of taxes paid by the merchant for one unit of this product. - taxes: Tax[]; + taxes?: Tax[]; // Number of units of the product in stock in sum in total, // including all existing sales ever. Given in product-specific @@ -4039,7 +4211,7 @@ export namespace TalerMerchantApi { total_lost: Integer; // Identifies where the product is in stock. - address: Location; + address?: Location; // Identifies when we expect the next restocking to happen. next_restock?: Timestamp; @@ -4100,9 +4272,9 @@ export namespace TalerMerchantApi { otp_id?: string; } - type Order = MinimalOrderDetail | ContractTerms; + export type Order = MinimalOrderDetail & Partial<ContractTerms>; - interface MinimalOrderDetail { + export interface MinimalOrderDetail { // Amount to be paid by the customer. amount: AmountString; @@ -4121,7 +4293,7 @@ export namespace TalerMerchantApi { fulfillment_message?: string; } - interface MinimalInventoryProduct { + export interface MinimalInventoryProduct { // Which product is requested (here mandatory!). product_id: string; @@ -4399,174 +4571,6 @@ export namespace TalerMerchantApi { confirmed?: boolean; } - interface ReserveCreateRequest { - // Amount that the merchant promises to put into the reserve. - initial_balance: AmountString; - - // Exchange the merchant intends to use for rewards. - exchange_url: string; - - // Desired wire method, for example "iban" or "x-taler-bank". - wire_method: string; - } - interface ReserveCreateConfirmation { - // Public key identifying the reserve. - reserve_pub: EddsaPublicKey; - - // Wire accounts of the exchange where to transfer the funds. - accounts: TalerExchangeApi.WireAccount[]; - } - - interface RewardReserveStatus { - // Array of all known reserves (possibly empty!). - reserves: ReserveStatusEntry[]; - } - interface ReserveStatusEntry { - // Public key of the reserve. - reserve_pub: EddsaPublicKey; - - // Timestamp when it was established. - creation_time: Timestamp; - - // Timestamp when it expires. - expiration_time: Timestamp; - - // Initial amount as per reserve creation call. - merchant_initial_amount: AmountString; - - // Initial amount as per exchange, 0 if exchange did - // not confirm reserve creation yet. - exchange_initial_amount: AmountString; - - // Amount picked up so far. - pickup_amount: AmountString; - - // Amount approved for rewards that exceeds the pickup_amount. - committed_amount: AmountString; - - // Is this reserve active (false if it was deleted but not purged)? - active: boolean; - } - - interface ReserveDetail { - // Timestamp when it was established. - creation_time: Timestamp; - - // Timestamp when it expires. - expiration_time: Timestamp; - - // Initial amount as per reserve creation call. - merchant_initial_amount: AmountString; - - // Initial amount as per exchange, 0 if exchange did - // not confirm reserve creation yet. - exchange_initial_amount: AmountString; - - // Amount picked up so far. - pickup_amount: AmountString; - - // Amount approved for rewards that exceeds the pickup_amount. - committed_amount: AmountString; - - // Array of all rewards created by this reserves (possibly empty!). - // Only present if asked for explicitly. - rewards?: RewardStatusEntry[]; - - // Is this reserve active (false if it was deleted but not purged)? - active: boolean; - - // Array of wire accounts of the exchange that could - // be used to fill the reserve, can be NULL - // if the reserve is inactive or was already filled - accounts?: TalerExchangeApi.WireAccount[]; - - // URL of the exchange hosting the reserve, - // NULL if the reserve is inactive - exchange_url: string; - } - interface RewardStatusEntry { - // Unique identifier for the reward. - reward_id: HashCode; - - // Total amount of the reward that can be withdrawn. - total_amount: AmountString; - - // Human-readable reason for why the reward was granted. - reason: string; - } - - interface RewardCreateRequest { - // Amount that the customer should be rewarded. - amount: AmountString; - - // Justification for giving the reward. - justification: string; - - // URL that the user should be directed to after receiving the reward, - // will be included in the reward_token. - next_url: string; - } - interface RewardCreateConfirmation { - // Unique reward identifier for the reward that was created. - reward_id: HashCode; - - // taler://reward URI for the reward. - taler_reward_uri: string; - - // URL that will directly trigger processing - // the reward when the browser is redirected to it. - reward_status_url: string; - - // When does the reward expire? - reward_expiration: Timestamp; - } - - interface RewardDetails { - // Amount that we authorized for this reward. - total_authorized: AmountString; - - // Amount that was picked up by the user already. - total_picked_up: AmountString; - - // Human-readable reason given when authorizing the reward. - reason: string; - - // Timestamp indicating when the reward is set to expire (may be in the past). - expiration: Timestamp; - - // Reserve public key from which the reward is funded. - reserve_pub: EddsaPublicKey; - - // Array showing the pickup operations of the wallet (possibly empty!). - // Only present if asked for explicitly. - pickups?: PickupDetail[]; - } - interface PickupDetail { - // Unique identifier for the pickup operation. - pickup_id: HashCode; - - // Number of planchets involved. - num_planchets: Integer; - - // Total amount requested for this pickup_id. - requested_amount: AmountString; - } - - interface RewardsResponse { - // List of rewards that are present in the backend. - rewards: Reward[]; - } - interface Reward { - // ID of the reward in the backend database. - row_id: number; - - // Unique identifier for the reward. - reward_id: HashCode; - - // (Remaining) amount of the reward (including fees). - reward_amount: AmountString; - } - export interface OtpDeviceAddDetails { // Device ID to use. otp_device_id: string; @@ -4729,12 +4733,12 @@ export namespace TalerMerchantApi { currency?: string; - amount?: AmountString; - - minimum_age?: Integer; - - pay_duration?: RelativeTime; + /** + * Amount *or* a plain currency string. + */ + amount?: string; } + export interface TemplatePatchDetails { // Human-readable description for the template. template_description: string; @@ -5260,6 +5264,68 @@ export namespace TalerMerchantApi { // Master public key of the exchange. master_pub: EddsaPublicKey; } + + export interface MerchantReserveCreateConfirmation { + // Public key identifying the reserve. + reserve_pub: EddsaPublicKey; + + // Wire accounts of the exchange where to transfer the funds. + accounts: ExchangeWireAccount[]; + } + + export interface TemplateEditableDetails { + // Human-readable summary for the template. + summary?: string; + + // Required currency for payments to the template. + // The user may specify any amount, but it must be + // in this currency. + // This parameter is optional and should not be present + // if "amount" is given. + currency?: string; + + // The price is imposed by the merchant and cannot be changed by the customer. + // This parameter is optional. + amount?: AmountString; + } + + export interface MerchantTemplateContractDetails { + // Human-readable summary for the template. + summary?: string; + + // The price is imposed by the merchant and cannot be changed by the customer. + // This parameter is optional. + amount?: string; + + // Minimum age buyer must have (in years). Default is 0. + minimum_age: number; + + // The time the customer need to pay before his order will be deleted. + // It is deleted if the customer did not pay and if the duration is over. + pay_duration: TalerProtocolDuration; + } + + export interface MerchantTemplateAddDetails { + // Template ID to use. + template_id: string; + + // Human-readable description for the template. + template_description: string; + + // A base64-encoded image selected by the merchant. + // This parameter is optional. + // We are not sure about it. + image?: string; + + editable_defaults?: TemplateEditableDetails; + + // Additional information in a separate template. + template_contract: MerchantTemplateContractDetails; + + // OTP device ID. + // This parameter is optional. + otp_id?: string; + } } export namespace ChallengerApi { |