Skip to content
Open
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 .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "1.0.5"
".": "1.0.6"
}
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Changelog

## 1.0.6 (2026-02-24)

Full Changelog: [v1.0.5...v1.0.6](https://github.com/brapi-dev/brapi-typescript/compare/v1.0.5...v1.0.6)

### Bug Fixes

* **client:** avoid memory leak with abort signals ([8d95d6f](https://github.com/brapi-dev/brapi-typescript/commit/8d95d6fd20b0c692206731b9130df6a49ef9e217))
* **client:** avoid removing abort listener too early ([13b9922](https://github.com/brapi-dev/brapi-typescript/commit/13b99225a929f1cfc968313464df754b9f64b9fb))
* **docs/contributing:** correct pnpm link command ([1a93d46](https://github.com/brapi-dev/brapi-typescript/commit/1a93d46145de5605b9b1fc088f5ba998626246d0))


### Chores

* **client:** do not parse responses with empty content-length ([8d77067](https://github.com/brapi-dev/brapi-typescript/commit/8d770677b7685b6b5115eec2a678f05bab13b5fd))
* **client:** restructure abort controller binding ([940d1c2](https://github.com/brapi-dev/brapi-typescript/commit/940d1c22aec74bbb2394953b189c57eda013baff))
* **internal/client:** fix form-urlencoded requests ([4767da4](https://github.com/brapi-dev/brapi-typescript/commit/4767da44630b6bb2ca454d103f4098ab1c57561e))
* **internal:** avoid type checking errors with ts-reset ([fccc6b5](https://github.com/brapi-dev/brapi-typescript/commit/fccc6b5f06cb7463889b71d0792e3af84b069ff2))
* **internal:** remove mock server code ([3ed6269](https://github.com/brapi-dev/brapi-typescript/commit/3ed6269f28554ca012cd8470afd7f1d99a30b33c))
* update mock server docs ([fde3193](https://github.com/brapi-dev/brapi-typescript/commit/fde31931e0c13f8bdca6aca52062c87e0c0d6aab))

## 1.0.5 (2026-01-24)

Full Changelog: [v1.0.4...v1.0.5](https://github.com/brapi-dev/brapi-typescript/compare/v1.0.4...v1.0.5)
Expand Down
8 changes: 1 addition & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,11 @@ $ yarn link brapi
# With pnpm
$ pnpm link --global
$ cd ../my-package
$ pnpm link -global brapi
$ pnpm link --global brapi
```

## Running tests

Most tests require you to [set up a mock server](https://github.com/stoplightio/prism) against the OpenAPI spec to run the tests.

```sh
$ npx prism mock path/to/your/openapi.yml
```

```sh
$ yarn run test
```
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "brapi",
"version": "1.0.5",
"version": "1.0.6",
"description": "The official TypeScript library for the Brapi API",
"author": "Brapi <contact@brapi.dev>",
"types": "dist/index.d.ts",
Expand Down
41 changes: 0 additions & 41 deletions scripts/mock

This file was deleted.

46 changes: 0 additions & 46 deletions scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,7 @@ set -e

cd "$(dirname "$0")/.."

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color

function prism_is_running() {
curl --silent "http://localhost:4010" >/dev/null 2>&1
}

kill_server_on_port() {
pids=$(lsof -t -i tcp:"$1" || echo "")
if [ "$pids" != "" ]; then
kill "$pids"
echo "Stopped $pids."
fi
}

function is_overriding_api_base_url() {
[ -n "$TEST_API_BASE_URL" ]
}

if ! is_overriding_api_base_url && ! prism_is_running ; then
# When we exit this script, make sure to kill the background mock server process
trap 'kill_server_on_port 4010' EXIT

# Start the dev server
./scripts/mock --daemon
fi

if is_overriding_api_base_url ; then
echo -e "${GREEN}✔ Running tests against ${TEST_API_BASE_URL}${NC}"
echo
elif ! prism_is_running ; then
echo -e "${RED}ERROR:${NC} The test suite will not run without a mock Prism server"
echo -e "running against your OpenAPI spec."
echo
echo -e "To run the server, pass in the path or url of your OpenAPI"
echo -e "spec to the prism command:"
echo
echo -e " \$ ${YELLOW}npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock path/to/your.openapi.yml${NC}"
echo

exit 1
else
echo -e "${GREEN}✔ Mock prism server is running with your OpenAPI spec${NC}"
echo
fi

echo "==> Running tests"
./node_modules/.bin/jest "$@"
21 changes: 18 additions & 3 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ export class Brapi {
loggerFor(this).info(`${responseInfo} - ${retryMessage}`);

const errText = await response.text().catch((err: any) => castToError(err).message);
const errJSON = safeJSON(errText);
const errJSON = safeJSON(errText) as any;
const errMessage = errJSON ? undefined : errText;

loggerFor(this).debug(
Expand Down Expand Up @@ -512,9 +512,10 @@ export class Brapi {
controller: AbortController,
): Promise<Response> {
const { signal, method, ...options } = init || {};
if (signal) signal.addEventListener('abort', () => controller.abort());
const abort = this._makeAbort(controller);
if (signal) signal.addEventListener('abort', abort, { once: true });

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

const isReadableBody =
((globalThis as any).ReadableStream && options.body instanceof (globalThis as any).ReadableStream) ||
Expand Down Expand Up @@ -681,6 +682,12 @@ export class Brapi {
return headers.values;
}

private _makeAbort(controller: AbortController) {
// note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
// would capture all request options, and cause a memory leak.
return () => controller.abort();
}

private buildBody({ options: { body, headers: rawHeaders } }: { options: FinalRequestOptions }): {
bodyHeaders: HeadersLike;
body: BodyInit | undefined;
Expand Down Expand Up @@ -713,6 +720,14 @@ export class Brapi {
(Symbol.iterator in body && 'next' in body && typeof body.next === 'function'))
) {
return { bodyHeaders: undefined, body: Shims.ReadableStreamFrom(body as AsyncIterable<Uint8Array>) };
} else if (
typeof body === 'object' &&
headers.values.get('content-type') === 'application/x-www-form-urlencoded'
) {
return {
bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },
body: this.stringifyQuery(body as Record<string, unknown>),
};
} else {
return this.#encoder({ body, headers });
}
Expand Down
6 changes: 6 additions & 0 deletions src/internal/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ export async function defaultParseResponse<T>(client: Brapi, props: APIResponseP
const mediaType = contentType?.split(';')[0]?.trim();
const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
if (isJSON) {
const contentLength = response.headers.get('content-length');
if (contentLength === '0') {
// if there is no content we can't do anything
return undefined as T;
}

const json = await response.json();
return json as T;
}
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = '1.0.5'; // x-release-please-version
export const VERSION = '1.0.6'; // x-release-please-version
4 changes: 2 additions & 2 deletions tests/api-resources/available.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const client = new Brapi({
});

describe('resource available', () => {
// Prism tests are disabled
// Mock server tests are disabled
test.skip('list', async () => {
const responsePromise = client.available.list();
const rawResponse = await responsePromise.asResponse();
Expand All @@ -20,7 +20,7 @@ describe('resource available', () => {
expect(dataAndResponse.response).toBe(rawResponse);
});

// Prism tests are disabled
// Mock server tests are disabled
test.skip('list: request options and params are passed correctly', async () => {
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
await expect(
Expand Down
8 changes: 4 additions & 4 deletions tests/api-resources/quote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const client = new Brapi({
});

describe('resource quote', () => {
// Prism tests are disabled
// Mock server tests are disabled
test.skip('retrieve', async () => {
const responsePromise = client.quote.retrieve('PETR4,MGLU3');
const rawResponse = await responsePromise.asResponse();
Expand All @@ -20,7 +20,7 @@ describe('resource quote', () => {
expect(dataAndResponse.response).toBe(rawResponse);
});

// Prism tests are disabled
// Mock server tests are disabled
test.skip('retrieve: request options and params are passed correctly', async () => {
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
await expect(
Expand All @@ -39,7 +39,7 @@ describe('resource quote', () => {
).rejects.toThrow(Brapi.NotFoundError);
});

// Prism tests are disabled
// Mock server tests are disabled
test.skip('list', async () => {
const responsePromise = client.quote.list();
const rawResponse = await responsePromise.asResponse();
Expand All @@ -51,7 +51,7 @@ describe('resource quote', () => {
expect(dataAndResponse.response).toBe(rawResponse);
});

// Prism tests are disabled
// Mock server tests are disabled
test.skip('list: request options and params are passed correctly', async () => {
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
await expect(
Expand Down
8 changes: 4 additions & 4 deletions tests/api-resources/v2/crypto.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const client = new Brapi({
});

describe('resource crypto', () => {
// Prism tests are disabled
// Mock server tests are disabled
test.skip('retrieve: only required params', async () => {
const responsePromise = client.v2.crypto.retrieve({ coin: 'coin' });
const rawResponse = await responsePromise.asResponse();
Expand All @@ -20,7 +20,7 @@ describe('resource crypto', () => {
expect(dataAndResponse.response).toBe(rawResponse);
});

// Prism tests are disabled
// Mock server tests are disabled
test.skip('retrieve: required and optional params', async () => {
const response = await client.v2.crypto.retrieve({
coin: 'coin',
Expand All @@ -31,7 +31,7 @@ describe('resource crypto', () => {
});
});

// Prism tests are disabled
// Mock server tests are disabled
test.skip('listAvailable', async () => {
const responsePromise = client.v2.crypto.listAvailable();
const rawResponse = await responsePromise.asResponse();
Expand All @@ -43,7 +43,7 @@ describe('resource crypto', () => {
expect(dataAndResponse.response).toBe(rawResponse);
});

// Prism tests are disabled
// Mock server tests are disabled
test.skip('listAvailable: request options and params are passed correctly', async () => {
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
await expect(
Expand Down
8 changes: 4 additions & 4 deletions tests/api-resources/v2/currency.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const client = new Brapi({
});

describe('resource currency', () => {
// Prism tests are disabled
// Mock server tests are disabled
test.skip('retrieve: only required params', async () => {
const responsePromise = client.v2.currency.retrieve({ currency: 'USD-BRL,EUR-USD' });
const rawResponse = await responsePromise.asResponse();
Expand All @@ -20,12 +20,12 @@ describe('resource currency', () => {
expect(dataAndResponse.response).toBe(rawResponse);
});

// Prism tests are disabled
// Mock server tests are disabled
test.skip('retrieve: required and optional params', async () => {
const response = await client.v2.currency.retrieve({ currency: 'USD-BRL,EUR-USD', token: 'token' });
});

// Prism tests are disabled
// Mock server tests are disabled
test.skip('listAvailable', async () => {
const responsePromise = client.v2.currency.listAvailable();
const rawResponse = await responsePromise.asResponse();
Expand All @@ -37,7 +37,7 @@ describe('resource currency', () => {
expect(dataAndResponse.response).toBe(rawResponse);
});

// Prism tests are disabled
// Mock server tests are disabled
test.skip('listAvailable: request options and params are passed correctly', async () => {
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
await expect(
Expand Down
8 changes: 4 additions & 4 deletions tests/api-resources/v2/inflation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const client = new Brapi({
});

describe('resource inflation', () => {
// Prism tests are disabled
// Mock server tests are disabled
test.skip('retrieve', async () => {
const responsePromise = client.v2.inflation.retrieve();
const rawResponse = await responsePromise.asResponse();
Expand All @@ -20,7 +20,7 @@ describe('resource inflation', () => {
expect(dataAndResponse.response).toBe(rawResponse);
});

// Prism tests are disabled
// Mock server tests are disabled
test.skip('retrieve: request options and params are passed correctly', async () => {
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
await expect(
Expand All @@ -39,7 +39,7 @@ describe('resource inflation', () => {
).rejects.toThrow(Brapi.NotFoundError);
});

// Prism tests are disabled
// Mock server tests are disabled
test.skip('listAvailable', async () => {
const responsePromise = client.v2.inflation.listAvailable();
const rawResponse = await responsePromise.asResponse();
Expand All @@ -51,7 +51,7 @@ describe('resource inflation', () => {
expect(dataAndResponse.response).toBe(rawResponse);
});

// Prism tests are disabled
// Mock server tests are disabled
test.skip('listAvailable: request options and params are passed correctly', async () => {
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
await expect(
Expand Down
Loading