Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4a2c34a
feat(api): update via SDK Studio (#20)
stainless-app[bot] Feb 4, 2025
4ad8147
feat(client): send `X-Stainless-Timeout` header (#22)
stainless-app[bot] Feb 5, 2025
c9aaf54
feat(api): api update (#23)
stainless-app[bot] Feb 5, 2025
5326693
feat(api): api update (#24)
stainless-app[bot] Feb 5, 2025
fdc83d1
feat(api): api update (#25)
stainless-app[bot] Feb 10, 2025
eef40b4
feat(api): api update (#26)
stainless-app[bot] Feb 11, 2025
5543d8e
fix(client): fix export map for index exports (#27)
stainless-app[bot] Feb 14, 2025
44c69e8
chore(internal): codegen related update (#28)
stainless-app[bot] Feb 19, 2025
26194ce
chore(internal): fix devcontainers setup (#29)
stainless-app[bot] Feb 22, 2025
f9c0492
docs: update URLs from stainlessapi.com to stainless.com (#30)
stainless-app[bot] Feb 28, 2025
2b286c1
chore(internal): codegen related update (#31)
stainless-app[bot] Mar 8, 2025
ecdef89
feat: add SKIP_BREW env var to ./scripts/bootstrap (#32)
stainless-app[bot] Mar 11, 2025
ca38adc
feat(client): accept RFC6838 JSON content types (#33)
stainless-app[bot] Mar 11, 2025
3677c0c
chore(internal): remove extra empty newlines (#34)
stainless-app[bot] Mar 14, 2025
641f5b3
chore(exports): cleaner resource index imports (#35)
stainless-app[bot] Mar 20, 2025
801d961
chore(exports): stop using path fallbacks (#36)
stainless-app[bot] Mar 20, 2025
42542b9
fix: avoid type error in certain environments (#37)
stainless-app[bot] Mar 22, 2025
a9f4767
feat(api): api update
stainless-app[bot] Mar 25, 2025
61373c8
feat(api): update via SDK Studio (#38)
stainless-app[bot] Mar 25, 2025
a0ce99a
feat(api): update via SDK Studio (#39)
stainless-app[bot] Mar 25, 2025
5614b84
feat(api): update via SDK Studio (#40)
stainless-app[bot] Mar 25, 2025
6f9da54
feat(api): update via SDK Studio (#41)
stainless-app[bot] Mar 25, 2025
9e25c59
feat(api): api update (#42)
stainless-app[bot] Mar 25, 2025
588ad3b
feat(api): update via SDK Studio (#43)
stainless-app[bot] Mar 25, 2025
324c847
release: 0.8.2
stainless-app[bot] Mar 26, 2025
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
23 changes: 0 additions & 23 deletions .devcontainer/Dockerfile

This file was deleted.

27 changes: 12 additions & 15 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/debian
{
"name": "Debian",
"build": {
"dockerfile": "Dockerfile"
"name": "Development",
"image": "mcr.microsoft.com/devcontainers/typescript-node:latest",
"features": {
"ghcr.io/devcontainers/features/node:1": {}
},
"postCreateCommand": "yarn install",
"customizations": {
"vscode": {
"extensions": [
"esbenp.prettier-vscode"
]
}
}

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,3 @@ jobs:

- name: Run tests
run: ./scripts/test

2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.5.3"
".": "0.8.2"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 10
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/hyperspell%2Fhyperspell-7632a025f14cf4ef9630966e00cb47fd93e8b43f1e9111f3917eb5adf145f0dd.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/hyperspell%2Fhyperspell-c562e6864fc7607b8a6ff45ad2abaf22344660501695ee0270350b37bbbf3bdf.yml
43 changes: 43 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,48 @@
# Changelog

## 0.8.2 (2025-03-26)

Full Changelog: [v0.5.3...v0.8.2](https://github.com/hyperspell/node-sdk/compare/v0.5.3...v0.8.2)

### Features

* add SKIP_BREW env var to ./scripts/bootstrap ([#32](https://github.com/hyperspell/node-sdk/issues/32)) ([ecdef89](https://github.com/hyperspell/node-sdk/commit/ecdef891f2210522efe31e5120d26ad572432f3b))
* **api:** api update ([a9f4767](https://github.com/hyperspell/node-sdk/commit/a9f47673364b5e8f8b2fcfee54b2c7a22eca9d2b))
* **api:** api update ([#23](https://github.com/hyperspell/node-sdk/issues/23)) ([c9aaf54](https://github.com/hyperspell/node-sdk/commit/c9aaf54d0505676b9cc6a75af87a9994cca2f5b3))
* **api:** api update ([#24](https://github.com/hyperspell/node-sdk/issues/24)) ([5326693](https://github.com/hyperspell/node-sdk/commit/53266933ad271b9f2f00b7c7e3607eb91f65b7f4))
* **api:** api update ([#25](https://github.com/hyperspell/node-sdk/issues/25)) ([fdc83d1](https://github.com/hyperspell/node-sdk/commit/fdc83d13e6e6d4de12378b219a3ed6b790c66466))
* **api:** api update ([#26](https://github.com/hyperspell/node-sdk/issues/26)) ([eef40b4](https://github.com/hyperspell/node-sdk/commit/eef40b4f33a39ad5a7887669414a4efdd3303f80))
* **api:** api update ([#42](https://github.com/hyperspell/node-sdk/issues/42)) ([9e25c59](https://github.com/hyperspell/node-sdk/commit/9e25c59176277df1cd2999ed875968d68137f93d))
* **api:** update via SDK Studio ([#20](https://github.com/hyperspell/node-sdk/issues/20)) ([4a2c34a](https://github.com/hyperspell/node-sdk/commit/4a2c34a97b3e2131ac1c0f6f392d54962bc50f62))
* **api:** update via SDK Studio ([#38](https://github.com/hyperspell/node-sdk/issues/38)) ([61373c8](https://github.com/hyperspell/node-sdk/commit/61373c843629c169d69c4dd133d5b3a9899a230f))
* **api:** update via SDK Studio ([#39](https://github.com/hyperspell/node-sdk/issues/39)) ([a0ce99a](https://github.com/hyperspell/node-sdk/commit/a0ce99aae41fa41ad8bde420f00870ce647ff5d1))
* **api:** update via SDK Studio ([#40](https://github.com/hyperspell/node-sdk/issues/40)) ([5614b84](https://github.com/hyperspell/node-sdk/commit/5614b84d9d2f34d59ba1b61dc43dd7ce4a143d3a))
* **api:** update via SDK Studio ([#41](https://github.com/hyperspell/node-sdk/issues/41)) ([6f9da54](https://github.com/hyperspell/node-sdk/commit/6f9da54a9104bbaab340cfb230f4217fdc8ec4ed))
* **api:** update via SDK Studio ([#43](https://github.com/hyperspell/node-sdk/issues/43)) ([588ad3b](https://github.com/hyperspell/node-sdk/commit/588ad3b6267ca1509e01babedaa2ff89c830bbc0))
* **client:** accept RFC6838 JSON content types ([#33](https://github.com/hyperspell/node-sdk/issues/33)) ([ca38adc](https://github.com/hyperspell/node-sdk/commit/ca38adc6b3125f68d682462e42f7c79ac0d65da1))
* **client:** send `X-Stainless-Timeout` header ([#22](https://github.com/hyperspell/node-sdk/issues/22)) ([4ad8147](https://github.com/hyperspell/node-sdk/commit/4ad814769ef6503eb9b5a51c14d1ea3f74c736c5))


### Bug Fixes

* avoid type error in certain environments ([#37](https://github.com/hyperspell/node-sdk/issues/37)) ([42542b9](https://github.com/hyperspell/node-sdk/commit/42542b91e05ae3543112c21eae0c110158b753e5))
* **client:** fix export map for index exports ([#27](https://github.com/hyperspell/node-sdk/issues/27)) ([5543d8e](https://github.com/hyperspell/node-sdk/commit/5543d8ea3804070de726997e8474deb01318eb68))


### Chores

* **exports:** cleaner resource index imports ([#35](https://github.com/hyperspell/node-sdk/issues/35)) ([641f5b3](https://github.com/hyperspell/node-sdk/commit/641f5b3a2311b4db0c16d4555e6073a502c94226))
* **exports:** stop using path fallbacks ([#36](https://github.com/hyperspell/node-sdk/issues/36)) ([801d961](https://github.com/hyperspell/node-sdk/commit/801d961baa29194a1ecc3656305297e893fb2bb0))
* **internal:** codegen related update ([#28](https://github.com/hyperspell/node-sdk/issues/28)) ([44c69e8](https://github.com/hyperspell/node-sdk/commit/44c69e887a6e32339a487e28e14e444e68ac32c5))
* **internal:** codegen related update ([#31](https://github.com/hyperspell/node-sdk/issues/31)) ([2b286c1](https://github.com/hyperspell/node-sdk/commit/2b286c14f6545cfaf65259fabc051c40dbe336e7))
* **internal:** fix devcontainers setup ([#29](https://github.com/hyperspell/node-sdk/issues/29)) ([26194ce](https://github.com/hyperspell/node-sdk/commit/26194ce3891b4f5e6bc89d13a7e8c85137dfe731))
* **internal:** remove extra empty newlines ([#34](https://github.com/hyperspell/node-sdk/issues/34)) ([3677c0c](https://github.com/hyperspell/node-sdk/commit/3677c0c5673c2f49e7f37072be45aad49f1ee5d6))


### Documentation

* update URLs from stainlessapi.com to stainless.com ([#30](https://github.com/hyperspell/node-sdk/issues/30)) ([f9c0492](https://github.com/hyperspell/node-sdk/commit/f9c04926d82f1f863e6e111feb3b6e4ab33ff0bf))

## 0.5.3 (2025-02-04)

Full Changelog: [v0.1.0-alpha.2...v0.5.3](https://github.com/hyperspell/node-sdk/compare/v0.1.0-alpha.2...v0.5.3)
Expand Down
74 changes: 53 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This library provides convenient access to the Hyperspell REST API from server-s

The REST API documentation can be found on [docs.hyperspell.com](https://docs.hyperspell.com/). The full API of this library can be found in [api.md](api.md).

It is generated with [Stainless](https://www.stainlessapi.com/).
It is generated with [Stainless](https://www.stainless.com/).

## Installation

Expand All @@ -27,7 +27,7 @@ const client = new Hyperspell({
});

async function main() {
const documentStatus = await client.documents.add({ collection: 'collection', text: 'text' });
const documentStatus = await client.documents.add({ text: 'text' });

console.log(documentStatus.id);
}
Expand All @@ -48,7 +48,7 @@ const client = new Hyperspell({
});

async function main() {
const params: Hyperspell.DocumentAddParams = { collection: 'collection', text: 'text' };
const params: Hyperspell.DocumentAddParams = { text: 'text' };
const documentStatus: Hyperspell.DocumentStatus = await client.documents.add(params);
}

Expand All @@ -57,6 +57,42 @@ main();

Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.

## File uploads

Request parameters that correspond to file uploads can be passed in many different forms:

- `File` (or an object with the same structure)
- a `fetch` `Response` (or an object with the same structure)
- an `fs.ReadStream`
- the return value of our `toFile` helper

```ts
import fs from 'fs';
import fetch from 'node-fetch';
import Hyperspell, { toFile } from 'hyperspell';

const client = new Hyperspell();

// If you have access to Node `fs` we recommend using `fs.createReadStream()`:
await client.documents.upload({ collection: 'collection', file: fs.createReadStream('/path/to/file') });

// Or if you have the web `File` API you can pass a `File` instance:
await client.documents.upload({ collection: 'collection', file: new File(['my bytes'], 'file') });

// You can also pass a `fetch` `Response`:
await client.documents.upload({ collection: 'collection', file: await fetch('https://somesite/file') });

// Finally, if none of the above are convenient, you can use our `toFile` helper:
await client.documents.upload({
collection: 'collection',
file: await toFile(Buffer.from('my bytes'), 'file'),
});
await client.documents.upload({
collection: 'collection',
file: await toFile(new Uint8Array([0, 1, 2]), 'file'),
});
```

## Handling errors

When the library is unable to connect to the API,
Expand All @@ -66,17 +102,15 @@ a subclass of `APIError` will be thrown:
<!-- prettier-ignore -->
```ts
async function main() {
const documentStatus = await client.documents
.add({ collection: 'collection', text: 'text' })
.catch(async (err) => {
if (err instanceof Hyperspell.APIError) {
console.log(err.status); // 400
console.log(err.name); // BadRequestError
console.log(err.headers); // {server: 'nginx', ...}
} else {
throw err;
}
});
const documentStatus = await client.documents.add({ text: 'text' }).catch(async (err) => {
if (err instanceof Hyperspell.APIError) {
console.log(err.status); // 400
console.log(err.name); // BadRequestError
console.log(err.headers); // {server: 'nginx', ...}
} else {
throw err;
}
});
}

main();
Expand Down Expand Up @@ -111,7 +145,7 @@ const client = new Hyperspell({
});

// Or, configure per-request:
await client.documents.add({ collection: 'collection', text: 'text' }, {
await client.documents.add({ text: 'text' }, {
maxRetries: 5,
});
```
Expand All @@ -128,7 +162,7 @@ const client = new Hyperspell({
});

// Override per-request:
await client.documents.add({ collection: 'collection', text: 'text' }, {
await client.documents.add({ text: 'text' }, {
timeout: 5 * 1000,
});
```
Expand Down Expand Up @@ -180,13 +214,11 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi
```ts
const client = new Hyperspell();

const response = await client.documents.add({ collection: 'collection', text: 'text' }).asResponse();
const response = await client.documents.add({ text: 'text' }).asResponse();
console.log(response.headers.get('X-My-Header'));
console.log(response.statusText); // access the underlying Response object

const { data: documentStatus, response: raw } = await client.documents
.add({ collection: 'collection', text: 'text' })
.withResponse();
const { data: documentStatus, response: raw } = await client.documents.add({ text: 'text' }).withResponse();
console.log(raw.headers.get('X-My-Header'));
console.log(documentStatus.id);
```
Expand Down Expand Up @@ -293,7 +325,7 @@ const client = new Hyperspell({

// Override per-request:
await client.documents.add(
{ collection: 'collection', text: 'text' },
{ text: 'text' },
{
httpAgent: new http.Agent({ keepAlive: false }),
},
Expand Down
4 changes: 2 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

## Reporting Security Issues

This SDK is generated by [Stainless Software Inc](http://stainlessapi.com). Stainless takes security seriously, and encourages you to report any security vulnerability promptly so that appropriate action can be taken.
This SDK is generated by [Stainless Software Inc](http://stainless.com). Stainless takes security seriously, and encourages you to report any security vulnerability promptly so that appropriate action can be taken.

To report a security issue, please contact the Stainless team at security@stainlessapi.com.
To report a security issue, please contact the Stainless team at security@stainless.com.

## Responsible Disclosure

Expand Down
1 change: 1 addition & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Types:

- <code><a href="./src/resources/documents.ts">Document</a></code>
- <code><a href="./src/resources/documents.ts">DocumentStatus</a></code>
- <code><a href="./src/resources/documents.ts">Scores</a></code>
- <code><a href="./src/resources/documents.ts">DocumentListResponse</a></code>

Methods:
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": "hyperspell",
"version": "0.5.3",
"version": "0.8.2",
"description": "The official TypeScript library for the Hyperspell API",
"author": "Hyperspell <hello@hyperspell.com>",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion scripts/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e

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

if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ]; then
if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ] && [ "$SKIP_BREW" != "1" ]; then
brew bundle check >/dev/null 2>&1 || {
echo "==> Installing Homebrew dependencies…"
brew bundle
Expand Down
26 changes: 17 additions & 9 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ async function defaultParseResponse<T>(props: APIResponseProps): Promise<T> {
}

const contentType = response.headers.get('content-type');
const isJSON =
contentType?.includes('application/json') || contentType?.includes('application/vnd.api+json');
const mediaType = contentType?.split(';')[0]?.trim();
const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
if (isJSON) {
const json = await response.json();

Expand Down Expand Up @@ -280,6 +280,7 @@ export abstract class APIClient {
options: FinalRequestOptions<Req>,
{ retryCount = 0 }: { retryCount?: number } = {},
): { req: RequestInit; url: string; timeout: number } {
options = { ...options };
const { method, path, query, headers: headers = {} } = options;

const body =
Expand All @@ -292,9 +293,9 @@ export abstract class APIClient {

const url = this.buildURL(path!, query);
if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);
const timeout = options.timeout ?? this.timeout;
options.timeout = options.timeout ?? this.timeout;
const httpAgent = options.httpAgent ?? this.httpAgent ?? getDefaultAgent(url);
const minAgentTimeout = timeout + 1000;
const minAgentTimeout = options.timeout + 1000;
if (
typeof (httpAgent as any)?.options?.timeout === 'number' &&
minAgentTimeout > ((httpAgent as any).options.timeout ?? 0)
Expand Down Expand Up @@ -323,7 +324,7 @@ export abstract class APIClient {
signal: options.signal ?? null,
};

return { req, url, timeout };
return { req, url, timeout: options.timeout };
}

private buildHeaders({
Expand Down Expand Up @@ -351,15 +352,22 @@ export abstract class APIClient {
delete reqHeaders['content-type'];
}

// Don't set the retry count header if it was already set or removed through default headers or by the
// caller. We check `defaultHeaders` and `headers`, which can contain nulls, instead of `reqHeaders` to
// account for the removal case.
// Don't set theses headers if they were already set or removed through default headers or by the caller.
// We check `defaultHeaders` and `headers`, which can contain nulls, instead of `reqHeaders` to account
// for the removal case.
if (
getHeader(defaultHeaders, 'x-stainless-retry-count') === undefined &&
getHeader(headers, 'x-stainless-retry-count') === undefined
) {
reqHeaders['x-stainless-retry-count'] = String(retryCount);
}
if (
getHeader(defaultHeaders, 'x-stainless-timeout') === undefined &&
getHeader(headers, 'x-stainless-timeout') === undefined &&
options.timeout
) {
reqHeaders['x-stainless-timeout'] = String(options.timeout);
}

this.validateHeaders(reqHeaders, headers);

Expand Down Expand Up @@ -387,7 +395,7 @@ export abstract class APIClient {
!headers ? {}
: Symbol.iterator in headers ?
Object.fromEntries(Array.from(headers as Iterable<string[]>).map((header) => [...header]))
: { ...headers }
: { ...(headers as any as Record<string, string>) }
);
}

Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
DocumentStatus,
DocumentUploadParams,
Documents,
Scores,
} from './resources/documents';
import { Query, QuerySearchParams, QuerySearchResponse } from './resources/query';

Expand Down Expand Up @@ -209,6 +210,7 @@ export declare namespace Hyperspell {
Documents as Documents,
type Document as Document,
type DocumentStatus as DocumentStatus,
type Scores as Scores,
type DocumentListResponse as DocumentListResponse,
DocumentListResponsesCursorPage as DocumentListResponsesCursorPage,
type DocumentListParams as DocumentListParams,
Expand Down
2 changes: 1 addition & 1 deletion src/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class CursorPage<Item> extends AbstractPage<Item> implements CursorPageRe

return {
params: {
cursor: cursor,
cursor,
},
};
}
Expand Down
1 change: 1 addition & 0 deletions src/resources.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './resources/index';
Loading