Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): OpenAPI spec update via Stainless API #281

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-860e4b6046731b74cc833cc9fcf517406363aed502f110328f67e9fff7fbc9d6.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/new%2Fblockaid-fd20b2bd3aadd81da92e6591830639223581074ce4d7f2279e38353f72ca6909.yml
18 changes: 3 additions & 15 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,7 @@ 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) {
reqHeaders['x-stainless-retry-count'] = String(retryCount);
}
reqHeaders['x-stainless-retry-count'] = String(retryCount);

this.validateHeaders(reqHeaders, headers);

Expand Down Expand Up @@ -1132,15 +1128,7 @@ export const isHeadersProtocol = (headers: any): headers is HeadersProtocol => {
return typeof headers?.get === 'function';
};

export const getRequiredHeader = (headers: HeadersLike | Headers, header: string): string => {
const foundHeader = getHeader(headers, header);
if (foundHeader === undefined) {
throw new Error(`Could not find ${header} header`);
}
return foundHeader;
};

export const getHeader = (headers: HeadersLike | Headers, header: string): string | undefined => {
export const getRequiredHeader = (headers: HeadersLike, header: string): string => {
const lowerCasedHeader = header.toLowerCase();
if (isHeadersProtocol(headers)) {
// to deal with the case where the header looks like Stainless-Event-Id
Expand All @@ -1166,7 +1154,7 @@ export const getHeader = (headers: HeadersLike | Headers, header: string): strin
}
}

return undefined;
throw new Error(`Could not find ${header} header`);
};

/**
Expand Down
6 changes: 3 additions & 3 deletions src/resources/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ export namespace SiteScanParams {
}

export interface MultipleWalletRequestMetadata {
type: 'wallet';

/**
* List of all account addresses in different chains based on the CAIPs standard
* (https://github.com/ChainAgnostic/CAIPs). Ethereum mainnet example:
* eip155:1:0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb
*/
account_addresses?: Array<string>;
account_addresses: Array<string>;

type: 'wallet';

walletconnect_description?: string;

Expand Down
58 changes: 0 additions & 58 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,64 +279,6 @@ describe('retries', () => {
expect(count).toEqual(3);
});

test('omit retry count header', 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 });

expect(
await client.request({
path: '/foo',
method: 'get',
headers: { 'X-Stainless-Retry-Count': null },
}),
).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;
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 });

expect(
await client.request({
path: '/foo',
method: 'get',
headers: { 'X-Stainless-Retry-Count': '42' },
}),
).toEqual({ a: 1 });

expect((capturedRequest!.headers as Headers)['x-stainless-retry-count']).toBe('42');
});

test('retry on 429 with retry-after', async () => {
let count = 0;
const testFetch = async (url: RequestInfo, { signal }: RequestInit = {}): Promise<Response> => {
Expand Down