diff options
Diffstat (limited to 'packages/taler-util/src')
-rw-r--r-- | packages/taler-util/src/http-client/bank-core.ts | 33 | ||||
-rw-r--r-- | packages/taler-util/src/http-client/types.ts | 17 | ||||
-rw-r--r-- | packages/taler-util/src/http-common.ts | 2 |
3 files changed, 36 insertions, 16 deletions
diff --git a/packages/taler-util/src/http-client/bank-core.ts b/packages/taler-util/src/http-client/bank-core.ts index 50cedefa9..dbb6c7112 100644 --- a/packages/taler-util/src/http-client/bank-core.ts +++ b/packages/taler-util/src/http-client/bank-core.ts @@ -122,12 +122,13 @@ export class TalerCoreBankHttpClient { * https://docs.taler.net/core/api-corebank.html#delete--accounts-$USERNAME * */ - async deleteAccount(auth: UserAndToken) { + async deleteAccount(auth: UserAndToken, cid?: string) { const url = new URL(`accounts/${auth.username}`, this.baseUrl); const resp = await this.httpLib.fetch(url.href, { method: "DELETE", headers: { - Authorization: makeBearerTokenAuthHeader(auth.token) + Authorization: makeBearerTokenAuthHeader(auth.token), + "X-Challenge-Id": cid, }, }); switch (resp.status) { @@ -152,13 +153,14 @@ export class TalerCoreBankHttpClient { * https://docs.taler.net/core/api-corebank.html#patch--accounts-$USERNAME * */ - async updateAccount(auth: UserAndToken, body: TalerCorebankApi.AccountReconfiguration) { + async updateAccount(auth: UserAndToken, body: TalerCorebankApi.AccountReconfiguration, cid?: string) { const url = new URL(`accounts/${auth.username}`, this.baseUrl); const resp = await this.httpLib.fetch(url.href, { method: "PATCH", body, headers: { - Authorization: makeBearerTokenAuthHeader(auth.token) + Authorization: makeBearerTokenAuthHeader(auth.token), + "X-Challenge-Id": cid, }, }); switch (resp.status) { @@ -186,13 +188,14 @@ export class TalerCoreBankHttpClient { * https://docs.taler.net/core/api-corebank.html#patch--accounts-$USERNAME-auth * */ - async updatePassword(auth: UserAndToken, body: TalerCorebankApi.AccountPasswordChange) { + async updatePassword(auth: UserAndToken, body: TalerCorebankApi.AccountPasswordChange, cid?: string) { const url = new URL(`accounts/${auth.username}/auth`, this.baseUrl); const resp = await this.httpLib.fetch(url.href, { method: "PATCH", body, headers: { - Authorization: makeBearerTokenAuthHeader(auth.token) + Authorization: makeBearerTokenAuthHeader(auth.token), + "X-Challenge-Id": cid, }, }); switch (resp.status) { @@ -328,12 +331,13 @@ export class TalerCoreBankHttpClient { * https://docs.taler.net/core/api-corebank.html#post--accounts-$USERNAME-transactions * */ - async createTransaction(auth: UserAndToken, body: TalerCorebankApi.CreateTransactionRequest) { + async createTransaction(auth: UserAndToken, body: TalerCorebankApi.CreateTransactionRequest, cid?: string) { const url = new URL(`accounts/${auth.username}/transactions`, this.baseUrl); const resp = await this.httpLib.fetch(url.href, { method: "POST", headers: { - Authorization: makeBearerTokenAuthHeader(auth.token) + Authorization: makeBearerTokenAuthHeader(auth.token), + "X-Challenge-Id": cid, }, body, }); @@ -409,12 +413,13 @@ export class TalerCoreBankHttpClient { * https://docs.taler.net/core/api-corebank.html#post--accounts-$USERNAME-withdrawals-$WITHDRAWAL_ID-confirm * */ - async confirmWithdrawalById(auth: UserAndToken, wid: string) { + async confirmWithdrawalById(auth: UserAndToken, wid: string, cid?: string) { const url = new URL(`accounts/${auth.username}/withdrawals/${wid}/confirm`, this.baseUrl); const resp = await this.httpLib.fetch(url.href, { method: "POST", headers: { - Authorization: makeBearerTokenAuthHeader(auth.token) + Authorization: makeBearerTokenAuthHeader(auth.token), + "X-Challenge-Id": cid, }, }); switch (resp.status) { @@ -470,12 +475,13 @@ export class TalerCoreBankHttpClient { * https://docs.taler.net/core/api-corebank.html#post--accounts-$USERNAME-cashouts * */ - async createCashout(auth: UserAndToken, body: TalerCorebankApi.CashoutRequest) { + async createCashout(auth: UserAndToken, body: TalerCorebankApi.CashoutRequest, cid?: string) { const url = new URL(`accounts/${auth.username}/cashouts`, this.baseUrl); const resp = await this.httpLib.fetch(url.href, { method: "POST", headers: { - Authorization: makeBearerTokenAuthHeader(auth.token) + Authorization: makeBearerTokenAuthHeader(auth.token), + "X-Challenge-Id": cid, }, body, }); @@ -685,13 +691,14 @@ export class TalerCoreBankHttpClient { } } - async confirmChallenge(auth: UserAndToken, cid: string) { + async confirmChallenge(auth: UserAndToken, cid: string, body: TalerCorebankApi.ChallengeSolve) { const url = new URL(`accounts/${auth.username}/challenge/${cid}/confirm`, this.baseUrl); const resp = await this.httpLib.fetch(url.href, { method: "POST", headers: { Authorization: makeBearerTokenAuthHeader(auth.token) }, + body, }); switch (resp.status) { case HttpStatusCode.NoContent: return opEmptySuccess() diff --git a/packages/taler-util/src/http-client/types.ts b/packages/taler-util/src/http-client/types.ts index 740d4204e..75241aa30 100644 --- a/packages/taler-util/src/http-client/types.ts +++ b/packages/taler-util/src/http-client/types.ts @@ -358,6 +358,13 @@ export const codecForAccountData = (): Codec<TalerCorebankApi.AccountData> => .property("cashout_payto_uri", codecOptional(codecForPaytoString())) .property("is_public", codecForBoolean()) .property("is_taler_exchange", codecForBoolean()) + .property( + "tan_channel", + codecOptional(codecForEither( + codecForConstString(TalerCorebankApi.TanChannel.SMS), + codecForConstString(TalerCorebankApi.TanChannel.EMAIL), + )), + ) .build("TalerCorebankApi.AccountData"); export const codecForChallengeContactData = @@ -740,7 +747,7 @@ export const codecForAmlDecisionDetail = export const codecForChallenge = (): Codec<TalerCorebankApi.Challenge> => buildCodecForObject<TalerCorebankApi.Challenge>() - .property("challenge_id", codecForString()) + .property("challenge_id", codecForNumber()) .build("TalerCorebankApi.Challenge"); export const codecForTanTransmission = @@ -1824,9 +1831,15 @@ export namespace TalerCorebankApi { export interface Challenge { // Unique identifier of the challenge to solve to run this protected // operation. - challenge_id: string; + challenge_id: number; } + export interface ChallengeSolve { + // The TAN code that solves $CHALLENGE_ID + tan: string; + } + + export enum TanChannel { SMS = "sms", EMAIL = "email" diff --git a/packages/taler-util/src/http-common.ts b/packages/taler-util/src/http-common.ts index 7c58b3874..68e1d2816 100644 --- a/packages/taler-util/src/http-common.ts +++ b/packages/taler-util/src/http-common.ts @@ -51,7 +51,7 @@ export const DEFAULT_REQUEST_TIMEOUT_MS = 60000; export interface HttpRequestOptions { method?: "POST" | "PATCH" | "PUT" | "GET" | "DELETE"; - headers?: { [name: string]: string }; + headers?: { [name: string]: string | undefined }; /** * Timeout after which the request should be aborted. |