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
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ${{ github.repository == 'stainless-sdks/spreadsheet-api-typescript' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Set up Node
uses: actions/setup-node@v4
Expand All @@ -41,7 +41,7 @@ jobs:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Set up Node
uses: actions/setup-node@v4
Expand All @@ -57,7 +57,7 @@ jobs:
- name: Get GitHub OIDC Token
if: github.repository == 'stainless-sdks/spreadsheet-api-typescript'
id: github-oidc
uses: actions/github-script@v6
uses: actions/github-script@v8
with:
script: core.setOutput('github_token', await core.getIDToken());

Expand All @@ -74,7 +74,7 @@ jobs:
runs-on: ${{ github.repository == 'stainless-sdks/spreadsheet-api-typescript' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Set up Node
uses: actions/setup-node@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Set up Node
uses: actions/setup-node@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-doctor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
if: github.repository == 'GRID-is/api-sdk-ts' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || startsWith(github.head_ref, 'release-please') || github.head_ref == 'next')

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Check release environment
run: |
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.5.3"
".": "1.5.4"
}
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# Changelog

## 1.5.4 (2026-02-24)

Full Changelog: [v1.5.3...v1.5.4](https://github.com/GRID-is/api-sdk-ts/compare/v1.5.3...v1.5.4)

### Bug Fixes

* **client:** avoid memory leak with abort signals ([92deb42](https://github.com/GRID-is/api-sdk-ts/commit/92deb42121aa6e599d9a113bde98bb54871b6bf1))
* **client:** avoid removing abort listener too early ([85aabaa](https://github.com/GRID-is/api-sdk-ts/commit/85aabaaf5ee94b2f0475651c04a78a105d854ea8))
* **docs/contributing:** correct pnpm link command ([d1a0543](https://github.com/GRID-is/api-sdk-ts/commit/d1a054363d2a9515f40a6346c804f60a2f21985d))
* **internal:** skip tests that depend on mock server ([edb06bc](https://github.com/GRID-is/api-sdk-ts/commit/edb06bcad3c5a4a5b72afa05947fa42f8eb2b640))


### Chores

* **ci:** upgrade `actions/github-script` ([6b1118b](https://github.com/GRID-is/api-sdk-ts/commit/6b1118b6c13bcfce03c1fc6e94c10ac6bf7de61c))
* **client:** do not parse responses with empty content-length ([468f36a](https://github.com/GRID-is/api-sdk-ts/commit/468f36ad9e4ea4ad82ee5f01d4242213e5b73148))
* **client:** restructure abort controller binding ([6ec57ff](https://github.com/GRID-is/api-sdk-ts/commit/6ec57ff6a5356df317f3d1416d0e5b2399e56d29))
* **internal/client:** fix form-urlencoded requests ([fae488f](https://github.com/GRID-is/api-sdk-ts/commit/fae488f0b1e332a71e41155a4a5c05489cbf881f))
* **internal:** avoid type checking errors with ts-reset ([25002d6](https://github.com/GRID-is/api-sdk-ts/commit/25002d6a003ba24b945814af4a16edabe650e9f7))
* **internal:** fix pagination internals not accepting option promises ([5676b81](https://github.com/GRID-is/api-sdk-ts/commit/5676b81ef4736e55e6e50fc30761eb732876701d))
* **internal:** remove mock server code ([8dd5a3d](https://github.com/GRID-is/api-sdk-ts/commit/8dd5a3dff4dabb79a9f33641943322f5caddbe62))
* **internal:** update `actions/checkout` version ([1cf7c38](https://github.com/GRID-is/api-sdk-ts/commit/1cf7c38f4ab22e331e9c2e3bd6d1c5f7512e5264))
* **internal:** upgrade babel, qs, js-yaml ([0089abf](https://github.com/GRID-is/api-sdk-ts/commit/0089abf96ea8c063c216b008ef3edf8533d93351))
* update mock server docs ([90e8c2d](https://github.com/GRID-is/api-sdk-ts/commit/90e8c2d7d7e17423dea9a97f0cb9e1fb1f262e87))

## 1.5.3 (2026-01-07)

Full Changelog: [v1.5.2...v1.5.3](https://github.com/GRID-is/api-sdk-ts/compare/v1.5.2...v1.5.3)
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 @grid-is/api
# With pnpm
$ pnpm link --global
$ cd ../my-package
$ pnpm link -global @grid-is/api
$ pnpm link --global @grid-is/api
```

## 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": "@grid-is/api",
"version": "1.5.3",
"version": "1.5.4",
"description": "The official TypeScript library for the Grid API",
"author": "Grid <info@grid.is>",
"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 "$@"
32 changes: 26 additions & 6 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ export class Grid {
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 @@ -509,17 +509,22 @@ export class Grid {
getAPIList<Item, PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>>(
path: string,
Page: new (...args: any[]) => PageClass,
opts?: RequestOptions,
opts?: PromiseOrValue<RequestOptions>,
): Pagination.PagePromise<PageClass, Item> {
return this.requestAPIList(Page, { method: 'get', path, ...opts });
return this.requestAPIList(
Page,
opts && 'then' in opts ?
opts.then((opts) => ({ method: 'get', path, ...opts }))
: { method: 'get', path, ...opts },
);
}

requestAPIList<
Item = unknown,
PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>,
>(
Page: new (...args: ConstructorParameters<typeof Pagination.AbstractPage>) => PageClass,
options: FinalRequestOptions,
options: PromiseOrValue<FinalRequestOptions>,
): Pagination.PagePromise<PageClass, Item> {
const request = this.makeRequest(options, null, undefined);
return new Pagination.PagePromise<PageClass, Item>(this as any as Grid, request, Page);
Expand All @@ -532,9 +537,10 @@ export class Grid {
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 @@ -702,6 +708,12 @@ export class Grid {
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 @@ -734,6 +746,14 @@ export class Grid {
(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: Grid, props: APIResponsePr
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.5.3'; // x-release-please-version
export const VERSION = '1.5.4'; // x-release-please-version
8 changes: 4 additions & 4 deletions tests/api-resources/beta.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const client = new Grid({
});

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

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

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

// Prism tests are disabled
// Mock server tests are disabled
test.skip('searchLabels: required and optional params', async () => {
const response = await client.beta.searchLabels({
query: 'profit',
Expand Down
Loading