summaryrefslogtreecommitdiff
path: root/packages/taler-util/src/bank-api-client.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-util/src/bank-api-client.ts')
-rw-r--r--packages/taler-util/src/bank-api-client.ts41
1 files changed, 38 insertions, 3 deletions
diff --git a/packages/taler-util/src/bank-api-client.ts b/packages/taler-util/src/bank-api-client.ts
index d42317f91..a8cd4b0da 100644
--- a/packages/taler-util/src/bank-api-client.ts
+++ b/packages/taler-util/src/bank-api-client.ts
@@ -264,7 +264,7 @@ export class TalerCorebankApiClient {
const resp = await this.httpLib.fetch(url.href, {
headers: this.makeAuthHeader(),
});
- return await resp.json();
+ return readSuccessResponseJsonOrThrow(resp, codecForAny());
}
async getTransactions(username: string): Promise<void> {
@@ -295,6 +295,30 @@ export class TalerCorebankApiClient {
return await readSuccessResponseJsonOrThrow(resp, codecForAny());
}
+ async registerAccountExtended(req: RegisterAccountRequest): Promise<void> {
+ const url = new URL("accounts", this.baseUrl);
+ const resp = await this.httpLib.fetch(url.href, {
+ method: "POST",
+ body: req,
+ });
+
+ if (
+ resp.status !== 200 &&
+ resp.status !== 201 &&
+ resp.status !== 202 &&
+ resp.status !== 204
+ ) {
+ logger.error(`unexpected status ${resp.status} from POST ${url.href}`);
+ logger.error(`${j2s(await resp.json())}`);
+ throw TalerError.fromDetail(
+ TalerErrorCode.GENERIC_UNEXPECTED_REQUEST_ERROR,
+ {
+ httpStatusCode: resp.status,
+ },
+ );
+ }
+ }
+
/**
* Register a new account and return information about it.
*
@@ -311,7 +335,13 @@ export class TalerCorebankApiClient {
name: username,
},
});
- if (resp.status !== 200 && resp.status !== 202 && resp.status !== 204) {
+ if (
+ resp.status !== 200 &&
+ resp.status !== 201 &&
+ resp.status !== 202 &&
+ resp.status !== 204
+ ) {
+ logger.error(`unexpected status ${resp.status} from POST ${url.href}`);
logger.error(`${j2s(await resp.json())}`);
throw TalerError.fromDetail(
TalerErrorCode.GENERIC_UNEXPECTED_REQUEST_ERROR,
@@ -320,8 +350,13 @@ export class TalerCorebankApiClient {
},
);
}
+ // FIXME: Corebank should directly return this info!
const infoUrl = new URL(`accounts/${username}`, this.baseUrl);
- const infoResp = await this.httpLib.fetch(infoUrl.href);
+ const infoResp = await this.httpLib.fetch(infoUrl.href, {
+ headers: {
+ Authorization: makeBasicAuthHeader(username, password),
+ },
+ });
// FIXME: Validate!
const acctInfo: AccountData = await readSuccessResponseJsonOrThrow(
infoResp,