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

## 3.6.2 (2026-02-06)

Full Changelog: [v3.6.1...v3.6.2](https://github.com/moderation-api/sdk-typescript/compare/v3.6.1...v3.6.2)

### Bug Fixes

* **client:** avoid removing abort listener too early ([1d89cb2](https://github.com/moderation-api/sdk-typescript/commit/1d89cb27203faa83ff1709b03d0ec9b44003d510))


### Chores

* **client:** do not parse responses with empty content-length ([532f911](https://github.com/moderation-api/sdk-typescript/commit/532f9110239e90c4230ed122a89756719d588b66))
* **client:** restructure abort controller binding ([78d4ba7](https://github.com/moderation-api/sdk-typescript/commit/78d4ba7ae247a74c4e275db1874249badb11dc02))

## 3.6.1 (2026-02-03)

Full Changelog: [v3.6.0...v3.6.1](https://github.com/moderation-api/sdk-typescript/compare/v3.6.0...v3.6.1)
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": "@moderation-api/sdk",
"version": "3.6.1",
"version": "3.6.2",
"description": "The official TypeScript library for the Moderation API API",
"author": "Moderation API <support@moderationapi.com>",
"types": "dist/index.d.ts",
Expand Down
8 changes: 7 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ export class ModerationAPI {
controller: AbortController,
): Promise<Response> {
const { signal, method, ...options } = init || {};
const abort = controller.abort.bind(controller);
const abort = this._makeAbort(controller);
if (signal) signal.addEventListener('abort', abort, { once: true });

const timeout = setTimeout(abort, ms);
Expand Down Expand Up @@ -697,6 +697,12 @@ export class ModerationAPI {
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
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: ModerationAPI, props: APIR
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 = '3.6.1'; // x-release-please-version
export const VERSION = '3.6.2'; // x-release-please-version