diff options
author | Sebastian <sebasjm@gmail.com> | 2024-03-08 15:36:50 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-03-08 15:39:59 -0300 |
commit | e92440e257b4df4a232a28701143a4f9db730458 (patch) | |
tree | 85c8bc084cf0089de9b7034de6f9db82d58e308e /packages/taler-util | |
parent | 8dea5ac8f41e1d17163a08ba203f15ec372cd442 (diff) | |
download | wallet-core-e92440e257b4df4a232a28701143a4f9db730458.tar.xz |
fix #8489
Diffstat (limited to 'packages/taler-util')
-rw-r--r-- | packages/taler-util/src/http-client/bank-core.ts | 48 | ||||
-rw-r--r-- | packages/taler-util/src/index.ts | 1 | ||||
-rw-r--r-- | packages/taler-util/src/observability.ts | 35 |
3 files changed, 56 insertions, 28 deletions
diff --git a/packages/taler-util/src/http-client/bank-core.ts b/packages/taler-util/src/http-client/bank-core.ts index 4131edb11..b9fd6da80 100644 --- a/packages/taler-util/src/http-client/bank-core.ts +++ b/packages/taler-util/src/http-client/bank-core.ts @@ -86,16 +86,16 @@ export enum TalerCoreBankCacheEviction { CREATE_WITHDRAWAL, CREATE_CASHOUT, } - /** - * Protocol version spoken with the core bank. - * - * Endpoint must be ordered in the same way that in the docs - * Response code (http and taler) must have the same order that in the docs - * That way is easier to see changes - * - * Uses libtool's current:revision:age versioning. - */ - export class TalerCoreBankHttpClient { +/** + * Protocol version spoken with the core bank. + * + * Endpoint must be ordered in the same way that in the docs + * Response code (http and taler) must have the same order that in the docs + * That way is easier to see changes + * + * Uses libtool's current:revision:age versioning. + */ +export class TalerCoreBankHttpClient { public readonly PROTOCOL_VERSION = "4:0:0"; httpLib: HttpRequestLibrary; @@ -960,47 +960,39 @@ export enum TalerCoreBankCacheEviction { * https://docs.taler.net/core/api-corebank.html#taler-bank-integration-api * */ - getIntegrationAPI(): string { - return new URL(`taler-integration/`, this.baseUrl).href; - // return new TalerBankIntegrationHttpClient(url.href, this.httpLib); + getIntegrationAPI(): URL { + return new URL(`taler-integration/`, this.baseUrl); } /** * https://docs.taler.net/core/api-corebank.html#taler-bank-integration-api * */ - getWireGatewayAPI(username: string): string { - return new URL( - `accounts/${username}/taler-wire-gateway/`, - this.baseUrl, - ).href; - // return new TalerWireGatewayHttpClient(url.href, username, this.httpLib); + getWireGatewayAPI(username: string): URL { + return new URL(`accounts/${username}/taler-wire-gateway/`, this.baseUrl); } /** * https://docs.taler.net/core/api-corebank.html#taler-bank-integration-api * */ - getRevenueAPI(username: string): string { - return new URL(`accounts/${username}/taler-revenue/`, this.baseUrl).href; - // return new TalerRevenueHttpClient(url.href, username, this.httpLib); + getRevenueAPI(username: string): URL { + return new URL(`accounts/${username}/taler-revenue/`, this.baseUrl); } /** * https://docs.taler.net/core/api-corebank.html#post--accounts-$USERNAME-token * */ - getAuthenticationAPI(username: string): string { - return new URL(`accounts/${username}/`, this.baseUrl).href; - // return new TalerAuthenticationHttpClient(url.href, username, this.httpLib); + getAuthenticationAPI(username: string): URL { + return new URL(`accounts/${username}/`, this.baseUrl); } /** * https://docs.taler.net/core/api-corebank.html#post--accounts-$USERNAME-token * */ - getConversionInfoAPI(): string { - return new URL(`conversion-info/`, this.baseUrl).href; - // TalerBankConversionHttpClient + getConversionInfoAPI(): URL { + return new URL(`conversion-info/`, this.baseUrl); } } diff --git a/packages/taler-util/src/index.ts b/packages/taler-util/src/index.ts index 74ef9e8e6..6b9a4ae2f 100644 --- a/packages/taler-util/src/index.ts +++ b/packages/taler-util/src/index.ts @@ -25,6 +25,7 @@ export * from "./http-client/bank-integration.js"; export * from "./http-client/bank-revenue.js"; export * from "./http-client/bank-wire.js"; export * from "./http-client/exchange.js"; +export { CacheEvictor } from "./http-client/utils.js"; export * from "./http-client/officer-account.js"; export * from "./http-client/types.js"; export * from "./http-status-codes.js"; diff --git a/packages/taler-util/src/observability.ts b/packages/taler-util/src/observability.ts index fde951e37..198dcbe6e 100644 --- a/packages/taler-util/src/observability.ts +++ b/packages/taler-util/src/observability.ts @@ -15,6 +15,9 @@ */ import { ObservabilityEvent } from "./index.js"; +import { HttpRequestLibrary, HttpRequestOptions, HttpResponse } from "./http-common.js"; +import { ObservabilityEventType } from "./notifications.js" +import { getErrorDetailFromException } from "./errors.js"; /** * Observability sink can be passed into various operations (HTTP requests, DB access) @@ -23,3 +26,35 @@ import { ObservabilityEvent } from "./index.js"; export interface ObservabilityContext { observe(evt: ObservabilityEvent): void; } + +export class ObservableHttpClientLibrary implements HttpRequestLibrary { + constructor( + private impl: HttpRequestLibrary, + private oc: ObservabilityContext, + ) { } + async fetch( + url: string, + opt?: HttpRequestOptions | undefined, + ): Promise<HttpResponse> { + this.oc.observe({ + type: ObservabilityEventType.HttpFetchStart, + url: url, + }); + try { + const res = await this.impl.fetch(url, opt); + this.oc.observe({ + type: ObservabilityEventType.HttpFetchFinishSuccess, + url, + status: res.status, + }); + return res; + } catch (e) { + this.oc.observe({ + type: ObservabilityEventType.HttpFetchFinishError, + url, + error: getErrorDetailFromException(e), + }); + throw e; + } + } +} |