Skip to content

Commit

Permalink
docs: minor formatting changes (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] committed Dec 20, 2024
1 parent 74797f1 commit b768b9b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Setting up the environment

This repository uses [`yarn@v1`](https://classic.yarnpkg.com/lang/en/docs/install/#mac-stable).
This repository uses [`yarn@v1`](https://classic.yarnpkg.com/lang/en/docs/install).
Other package managers may work but are not officially supported for development.

To set up the repository, run:
Expand Down Expand Up @@ -29,10 +29,10 @@ All files in the `examples/` directory are not modified by the generator and can
```

```
chmod +x examples/<your-example>.ts
```sh
$ chmod +x examples/<your-example>.ts
# run the example against your api
yarn tsn -T examples/<your-example>.ts
$ yarn tsn -T examples/<your-example>.ts
```

## Using the repository from source
Expand Down
12 changes: 11 additions & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,19 @@ export abstract class APIClient {

const timeout = setTimeout(() => controller.abort(), ms);

const fetchOptions = {
signal: controller.signal as any,
...options,
};
if (fetchOptions.method) {
// Custom methods like 'patch' need to be uppercased
// See https://github.com/nodejs/undici/issues/2294
fetchOptions.method = fetchOptions.method.toUpperCase();
}

return (
// use undefined this binding; fetch errors if bound to something else in browser/cloudflare
this.fetch.call(undefined, url, { signal: controller.signal as any, ...options }).finally(() => {
this.fetch.call(undefined, url, fetchOptions).finally(() => {
clearTimeout(timeout);
})
);
Expand Down
17 changes: 17 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,23 @@ describe('instantiate client', () => {
expect(spy).toHaveBeenCalledTimes(1);
});

test('normalized method', async () => {
let capturedRequest: RequestInit | undefined;
const testFetch = async (url: RequestInfo, init: RequestInit = {}): Promise<Response> => {
capturedRequest = init;
return new Response(JSON.stringify({}), { headers: { 'Content-Type': 'application/json' } });
};

const client = new StudioSDK({
baseURL: 'http://localhost:5000/',
bearerToken: 'My Bearer Token',
fetch: testFetch,
});

await client.patch('/foo');
expect(capturedRequest?.method).toEqual('PATCH');
});

describe('baseUrl', () => {
test('trailing slash', () => {
const client = new StudioSDK({
Expand Down

0 comments on commit b768b9b

Please sign in to comment.