feat(core): switch to native fetch API for all HTTP requests

This commit is contained in:
2025-07-27 07:19:34 +00:00
parent fb30c6f4e3
commit c9fab7def2
8 changed files with 85 additions and 54 deletions

View File

@@ -47,17 +47,19 @@ export class BunqAttachment {
'X-Bunq-Client-Authentication': this.bunqAccount.apiContext.getSession().getContext().sessionToken
};
const requestOptions = {
method: 'PUT' as const,
headers: headers,
requestBody: options.body
};
await plugins.smartrequest.request(
const response = await fetch(
`${this.bunqAccount.apiContext.getBaseUrl()}${uploadUrl}`,
requestOptions
{
method: 'PUT',
headers: headers,
body: options.body
}
);
if (!response.ok) {
throw new Error(`Failed to upload attachment: HTTP ${response.status}`);
}
return attachmentUuid;
}
@@ -67,7 +69,7 @@ export class BunqAttachment {
public async getContent(attachmentUuid: string): Promise<Buffer> {
await this.bunqAccount.apiContext.ensureValidSession();
const response = await plugins.smartrequest.request(
const response = await fetch(
`${this.bunqAccount.apiContext.getBaseUrl()}/v1/attachment-public/${attachmentUuid}/content`,
{
method: 'GET',
@@ -77,7 +79,12 @@ export class BunqAttachment {
}
);
return Buffer.from(response.body);
if (!response.ok) {
throw new Error(`Failed to get attachment: HTTP ${response.status}`);
}
const arrayBuffer = await response.arrayBuffer();
return Buffer.from(arrayBuffer);
}
/**