Skip to content

Commit

Permalink
feat(api): api update (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stainless Bot committed Oct 28, 2024
1 parent 10b7fce commit e701e4f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 19
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/new%2Fblockaid-059a67bc85cdc7bb732ce96115b37ffd3f1e0342e986a903718f0ad53f91fe15.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/new%2Fblockaid-247e47596e9ade7b9e7bb4e1ae9f3febeff30e98066b7fef4daae8eb60673fd2.yml
10 changes: 7 additions & 3 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,13 @@ export abstract class APIClient {
delete reqHeaders['content-type'];
}

// Don't set the retry count header if it was already set or removed by the caller. We check `headers`,
// which can contain nulls, instead of `reqHeaders` to account for the removal case.
if (getHeader(headers, 'x-stainless-retry-count') === undefined) {
// Don't set the retry count header if it was already set or removed through default headers or by the
// caller. We check `defaultHeaders` and `headers`, which can contain nulls, instead of `reqHeaders` to
// account for the removal case.
if (
getHeader(defaultHeaders, 'x-stainless-retry-count') === undefined &&
getHeader(headers, 'x-stainless-retry-count') === undefined
) {
reqHeaders['x-stainless-retry-count'] = String(retryCount);
}

Expand Down
3 changes: 2 additions & 1 deletion src/resources/evm/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,8 @@ export type TransactionScanSupportedChain =
| 'gnosis'
| 'worldchain'
| 'soneium-minato'
| 'ronin';
| 'ronin'
| 'apechain';

export interface TransactionSimulation {
/**
Expand Down
33 changes: 33 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,39 @@ describe('retries', () => {
expect(capturedRequest!.headers as Headers).not.toHaveProperty('x-stainless-retry-count');
});

test('omit retry count header by default', async () => {
let count = 0;
let capturedRequest: RequestInit | undefined;
const testFetch = async (url: RequestInfo, init: RequestInit = {}): Promise<Response> => {
count++;
if (count <= 2) {
return new Response(undefined, {
status: 429,
headers: {
'Retry-After': '0.1',
},
});
}
capturedRequest = init;
return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } });
};
const client = new Blockaid({
apiKey: 'My API Key',
fetch: testFetch,
maxRetries: 4,
defaultHeaders: { 'X-Stainless-Retry-Count': null },
});

expect(
await client.request({
path: '/foo',
method: 'get',
}),
).toEqual({ a: 1 });

expect(capturedRequest!.headers as Headers).not.toHaveProperty('x-stainless-retry-count');
});

test('overwrite retry count header', async () => {
let count = 0;
let capturedRequest: RequestInit | undefined;
Expand Down

0 comments on commit e701e4f

Please sign in to comment.