Skip to content

Commit be0fb87

Browse files
chore(internal): codegen related update (#100)
1 parent 72be8df commit be0fb87

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Setting up the environment
22

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

66
To set up the repository, run:
@@ -29,10 +29,10 @@ All files in the `examples/` directory are not modified by the generator and can
2929
3030
```
3131

32-
```
33-
chmod +x examples/<your-example>.ts
32+
```sh
33+
$ chmod +x examples/<your-example>.ts
3434
# run the example against your api
35-
yarn tsn -T examples/<your-example>.ts
35+
$ yarn tsn -T examples/<your-example>.ts
3636
```
3737

3838
## Using the repository from source

src/core.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,19 @@ export abstract class APIClient {
522522

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

525+
const fetchOptions = {
526+
signal: controller.signal as any,
527+
...options,
528+
};
529+
if (fetchOptions.method) {
530+
// Custom methods like 'patch' need to be uppercased
531+
// See https://github.com/nodejs/undici/issues/2294
532+
fetchOptions.method = fetchOptions.method.toUpperCase();
533+
}
534+
525535
return (
526536
// use undefined this binding; fetch errors if bound to something else in browser/cloudflare
527-
this.fetch.call(undefined, url, { signal: controller.signal as any, ...options }).finally(() => {
537+
this.fetch.call(undefined, url, fetchOptions).finally(() => {
528538
clearTimeout(timeout);
529539
})
530540
);

tests/index.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,23 @@ describe('instantiate client', () => {
122122
expect(spy).toHaveBeenCalledTimes(1);
123123
});
124124

125+
test('normalized method', async () => {
126+
let capturedRequest: RequestInit | undefined;
127+
const testFetch = async (url: RequestInfo, init: RequestInit = {}): Promise<Response> => {
128+
capturedRequest = init;
129+
return new Response(JSON.stringify({}), { headers: { 'Content-Type': 'application/json' } });
130+
};
131+
132+
const client = new Browserbase({
133+
baseURL: 'http://localhost:5000/',
134+
apiKey: 'My API Key',
135+
fetch: testFetch,
136+
});
137+
138+
await client.patch('/foo');
139+
expect(capturedRequest?.method).toEqual('PATCH');
140+
});
141+
125142
describe('baseUrl', () => {
126143
test('trailing slash', () => {
127144
const client = new Browserbase({ baseURL: 'http://localhost:5000/custom/path/', apiKey: 'My API Key' });

0 commit comments

Comments
 (0)