Skip to content

Commit 9526c56

Browse files
committed
feat(cardano-services-client): extend Blockfrost request pipeline to include body
Needed for transaction submission
1 parent 6cc8937 commit 9526c56

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

packages/cardano-services-client/src/blockfrost/BlockfrostClient.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,13 @@ export class BlockfrostClient {
5050

5151
/**
5252
* @param endpoint e.g. 'blocks/latest'
53+
* @param body Payload body
5354
* @throws {BlockfrostError}
5455
*/
55-
public request<T>(endpoint: string): Promise<T> {
56+
public request<T>(endpoint: string, body?: RequestInit['body']): Promise<T> {
5657
return this.rateLimiter.schedule(() =>
5758
firstValueFrom(
58-
fromFetch(`${this.baseUrl}/${endpoint}`, this.requestInit).pipe(
59+
fromFetch(`${this.baseUrl}/${endpoint}`, { ...this.requestInit, body }).pipe(
5960
switchMap(async (response): Promise<T> => {
6061
if (response.ok) {
6162
try {
@@ -65,8 +66,8 @@ export class BlockfrostClient {
6566
}
6667
}
6768
try {
68-
const body = await response.text();
69-
throw new BlockfrostError(response.status, body);
69+
const responseBody = await response.text();
70+
throw new BlockfrostError(response.status, responseBody);
7071
} catch {
7172
throw new BlockfrostError(response.status);
7273
}

packages/cardano-services-client/src/blockfrost/BlockfrostProvider.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ export abstract class BlockfrostProvider implements Provider {
3636

3737
/**
3838
* @param endpoint e.g. 'blocks/latest'
39+
* @param body Payload body
3940
* @throws {ProviderError}
4041
*/
41-
protected async request<T>(endpoint: string): Promise<T> {
42+
protected async request<T>(endpoint: string, body?: RequestInit['body']): Promise<T> {
4243
try {
4344
this.logger.debug('request', endpoint);
44-
const response = await this.#client.request<T>(endpoint);
45+
const response = await this.#client.request<T>(endpoint, body);
4546
this.logger.debug('response', response);
4647
return response;
4748
} catch (error) {

packages/cardano-services-client/test/blockfrost/BlockfrostClient.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('BlockfrostClient', () => {
1717
const fetchResponse = new Response(JSON.stringify(responseData), { status: 200 });
1818
global.fetch = jest.fn().mockResolvedValue(fetchResponse);
1919

20-
const response = await client.request('/');
20+
const response = await client.request('/', '123');
2121
expect(response).toEqual(responseData);
2222
});
2323

0 commit comments

Comments
 (0)