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 .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- name: Get GitHub OIDC Token
if: github.repository == 'stainless-sdks/morphik-typescript'
id: github-oidc
uses: actions/github-script@v6
uses: actions/github-script@v8
with:
script: core.setOutput('github_token', await core.getIDToken());

Expand Down
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.9.0"
".": "1.9.1"
}
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Changelog

## 1.9.1 (2026-02-24)

Full Changelog: [v1.9.0...v1.9.1](https://github.com/morphik-org/morphik-ts/compare/v1.9.0...v1.9.1)

### Bug Fixes

* **client:** avoid memory leak with abort signals ([d4ab61c](https://github.com/morphik-org/morphik-ts/commit/d4ab61c33f1d02a5253e27841bb775a6ceea147d))
* **client:** avoid removing abort listener too early ([a4fdb09](https://github.com/morphik-org/morphik-ts/commit/a4fdb095674574af92643d5212923579b73f84cc))
* **docs/contributing:** correct pnpm link command ([874ab6d](https://github.com/morphik-org/morphik-ts/commit/874ab6dd5315f49a5070a61b2c88f3ad009191ae))


### Chores

* **ci:** upgrade `actions/github-script` ([8513ce5](https://github.com/morphik-org/morphik-ts/commit/8513ce589bdffbd702a3cc9fa868ad499f216969))
* **client:** do not parse responses with empty content-length ([3169d51](https://github.com/morphik-org/morphik-ts/commit/3169d51148b52561338eea977226341cfb7c0831))
* **client:** restructure abort controller binding ([b48b2b0](https://github.com/morphik-org/morphik-ts/commit/b48b2b0502d295c9a0cb4955437caddccc995bea))
* **internal/client:** fix form-urlencoded requests ([866c221](https://github.com/morphik-org/morphik-ts/commit/866c221aacbcf220b11e12b83feeacea9578645e))
* **internal:** avoid type checking errors with ts-reset ([ba8958a](https://github.com/morphik-org/morphik-ts/commit/ba8958a36758e190e863d6a032583fdd263ef942))
* **internal:** remove mock server code ([f64241c](https://github.com/morphik-org/morphik-ts/commit/f64241cbba49ce07de55752a373c796f1d5f30c5))
* update mock server docs ([b5ae452](https://github.com/morphik-org/morphik-ts/commit/b5ae452777e9f154aac0185050dcf49cf9e97da3))

## 1.9.0 (2026-01-22)

Full Changelog: [v1.8.0...v1.9.0](https://github.com/morphik-org/morphik-ts/compare/v1.8.0...v1.9.0)
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 morphik
# With pnpm
$ pnpm link --global
$ cd ../my-package
$ pnpm link -global morphik
$ pnpm link --global morphik
```

## 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": "morphik",
"version": "1.9.0",
"version": "1.9.1",
"description": "The official TypeScript library for the Morphik API",
"author": "Morphik <founders@morphik.ai>",
"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 @@ -534,7 +534,7 @@ export class Morphik {
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 @@ -575,9 +575,10 @@ export class Morphik {
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 @@ -744,6 +745,12 @@ export class Morphik {
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 @@ -776,6 +783,14 @@ export class Morphik {
(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: Morphik, props: APIRespons
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.9.0'; // x-release-please-version
export const VERSION = '1.9.1'; // x-release-please-version
6 changes: 3 additions & 3 deletions tests/api-resources/api-keys.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const client = new Morphik({
});

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

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

// Prism tests are disabled
// Mock server tests are disabled
test.skip('list', async () => {
const responsePromise = client.apiKeys.list();
const rawResponse = await responsePromise.asResponse();
Expand Down
4 changes: 2 additions & 2 deletions tests/api-resources/batch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const client = new Morphik({
});

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

// Prism tests are disabled
// Mock server tests are disabled
test.skip('retrieveDocuments', async () => {
const responsePromise = client.batch.retrieveDocuments({});
const rawResponse = await responsePromise.asResponse();
Expand Down
10 changes: 5 additions & 5 deletions tests/api-resources/chat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const client = new Morphik({
});

describe('resource chat', () => {
// Prism tests are disabled
// Mock server tests are disabled
test.skip('list', async () => {
const responsePromise = client.chat.list();
const rawResponse = await responsePromise.asResponse();
Expand All @@ -20,15 +20,15 @@ describe('resource chat', () => {
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(client.chat.list({ limit: 1 }, { path: '/_stainless_unknown_path' })).rejects.toThrow(
Morphik.NotFoundError,
);
});

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

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

// Prism tests are disabled
// Mock server tests are disabled
test.skip('updateTitle: required and optional params', async () => {
const response = await client.chat.updateTitle('chat_id', { title: 'title' });
});
Expand Down
Loading