From ecd0912273945a262c29c7520410d6ae927ff177 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 5 Feb 2025 03:54:56 +0000 Subject: [PATCH 01/19] feat(client): send `X-Stainless-Timeout` header (#28) --- src/core.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/core.ts b/src/core.ts index 37e4b6e..2922bb7 100644 --- a/src/core.ts +++ b/src/core.ts @@ -280,6 +280,7 @@ export abstract class APIClient { options: FinalRequestOptions, { retryCount = 0 }: { retryCount?: number } = {}, ): { req: RequestInit; url: string; timeout: number } { + options = { ...options }; const { method, path, query, headers: headers = {} } = options; const body = @@ -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) @@ -323,7 +324,7 @@ export abstract class APIClient { signal: options.signal ?? null, }; - return { req, url, timeout }; + return { req, url, timeout: options.timeout }; } private buildHeaders({ @@ -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); From 1518181a12687feeb94e7634194f73f7c6d2a92b Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 14 Feb 2025 06:19:26 +0000 Subject: [PATCH 02/19] fix(client): fix export map for index exports (#30) --- package.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index b42e730..83515c2 100644 --- a/package.json +++ b/package.json @@ -107,17 +107,17 @@ "default": "./dist/index.mjs" }, "./*.mjs": { - "types": "./dist/*.d.ts", - "default": "./dist/*.mjs" + "types": ["./dist/*.d.ts", "./dist/*/index.d.ts"], + "default": ["./dist/*.mjs", "./dist/*/index.mjs"] }, "./*.js": { - "types": "./dist/*.d.ts", - "default": "./dist/*.js" + "types": ["./dist/*.d.ts", "./dist/*/index.d.ts"], + "default": ["./dist/*.js", "./dist/*/index.js"] }, "./*": { - "types": "./dist/*.d.ts", - "require": "./dist/*.js", - "default": "./dist/*.mjs" + "types": ["./dist/*.d.ts", "./dist/*/index.d.ts"], + "require": ["./dist/*.js", "./dist/*/index.js"], + "default": ["./dist/*.mjs", "./dist/*/index.mjs"] } } } From 0de15d2ba4cfc81f769646ade15a88c3f30fcaa9 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 22 Feb 2025 06:14:48 +0000 Subject: [PATCH 03/19] chore(internal): fix devcontainers setup (#31) --- .devcontainer/Dockerfile | 23 ----------------------- .devcontainer/devcontainer.json | 27 ++++++++++++--------------- 2 files changed, 12 insertions(+), 38 deletions(-) delete mode 100644 .devcontainer/Dockerfile diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile deleted file mode 100644 index 8ea34be..0000000 --- a/.devcontainer/Dockerfile +++ /dev/null @@ -1,23 +0,0 @@ -# syntax=docker/dockerfile:1 -FROM debian:bookworm-slim AS stainless - -RUN apt-get update && apt-get install -y \ - nodejs \ - npm \ - yarnpkg \ - && apt-get clean autoclean - -# Ensure UTF-8 encoding -ENV LANG=C.UTF-8 -ENV LC_ALL=C.UTF-8 - -# Yarn -RUN ln -sf /usr/bin/yarnpkg /usr/bin/yarn - -WORKDIR /workspace - -COPY package.json yarn.lock /workspace/ - -RUN yarn install - -COPY . /workspace diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index d55fc4d..763462f 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -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" } From f8ec2343b8ac63893220f698353a5e127899523f Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 4 Jun 2025 17:53:12 +0000 Subject: [PATCH 04/19] docs: update URLs from stainlessapi.com to stainless.com (#32) More details at https://www.stainless.com/changelog/stainless-com --- README.md | 6 ++++-- SECURITY.md | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 25f042b..fda754c 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@ -# ZeroEntropy Node API Library +# ZeroEntropy Node SDK [![NPM version](https://img.shields.io/npm/v/zeroentropy.svg)](https://npmjs.org/package/zeroentropy) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/zeroentropy) -This library provides convenient access to the ZeroEntropy REST API from server-side TypeScript or JavaScript. +The ZeroEntropy Node SDK provides convenient access to the [ZeroEntropy REST API](https://docs.zeroentropy.dev/api-reference/) from any TypeScript or JavaScript application. The REST API documentation can be found on [docs.zeroentropy.dev](https://docs.zeroentropy.dev/api-reference). The full API of this library can be found in [api.md](api.md). +In order to get an API Key, you can visit our [dashboard](https://dashboard.zeroentropy.dev/). + ## Installation ```sh diff --git a/SECURITY.md b/SECURITY.md index 73d8066..374311e 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -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 From 1db65f912a1a5f23668ea2519ac8e1f379f0a806 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 11 Mar 2025 11:22:42 +0000 Subject: [PATCH 05/19] feat: add SKIP_BREW env var to ./scripts/bootstrap (#34) --- scripts/bootstrap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/bootstrap b/scripts/bootstrap index 05dd47a..0af58e2 100755 --- a/scripts/bootstrap +++ b/scripts/bootstrap @@ -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 From 5175743984e1379e05c4baaa5dded94dc1ae6b85 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 11 Mar 2025 11:35:13 +0000 Subject: [PATCH 06/19] feat(client): accept RFC6838 JSON content types (#35) --- src/core.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core.ts b/src/core.ts index 2922bb7..eacee53 100644 --- a/src/core.ts +++ b/src/core.ts @@ -48,8 +48,8 @@ async function defaultParseResponse(props: APIResponseProps): Promise { } 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(); From 5b8b92f2a64634a3a792b705c066c01132368d3d Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 14 Mar 2025 08:34:55 +0000 Subject: [PATCH 07/19] chore(internal): remove extra empty newlines (#36) --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e3530dc..0312165 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,4 +63,3 @@ jobs: - name: Run tests run: ./scripts/test - From e447d3b306acdcd7460b8329dd31cc78fedc4388 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 20 Mar 2025 08:41:53 +0000 Subject: [PATCH 08/19] chore(exports): cleaner resource index imports (#37) --- src/resources.ts | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/resources.ts diff --git a/src/resources.ts b/src/resources.ts new file mode 100644 index 0000000..b283d57 --- /dev/null +++ b/src/resources.ts @@ -0,0 +1 @@ +export * from './resources/index'; From f7460de48f5deaead21c777199dfb6acacfdf4ff Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 20 Mar 2025 08:42:43 +0000 Subject: [PATCH 09/19] chore(exports): stop using path fallbacks (#38) --- package.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 83515c2..b42e730 100644 --- a/package.json +++ b/package.json @@ -107,17 +107,17 @@ "default": "./dist/index.mjs" }, "./*.mjs": { - "types": ["./dist/*.d.ts", "./dist/*/index.d.ts"], - "default": ["./dist/*.mjs", "./dist/*/index.mjs"] + "types": "./dist/*.d.ts", + "default": "./dist/*.mjs" }, "./*.js": { - "types": ["./dist/*.d.ts", "./dist/*/index.d.ts"], - "default": ["./dist/*.js", "./dist/*/index.js"] + "types": "./dist/*.d.ts", + "default": "./dist/*.js" }, "./*": { - "types": ["./dist/*.d.ts", "./dist/*/index.d.ts"], - "require": ["./dist/*.js", "./dist/*/index.js"], - "default": ["./dist/*.mjs", "./dist/*/index.mjs"] + "types": "./dist/*.d.ts", + "require": "./dist/*.js", + "default": "./dist/*.mjs" } } } From 5be66ffd2783b79bda15848632f46c1a2b0bd53c Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 22 Mar 2025 07:31:47 +0000 Subject: [PATCH 10/19] fix: avoid type error in certain environments (#39) --- src/core.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core.ts b/src/core.ts index eacee53..77c7859 100644 --- a/src/core.ts +++ b/src/core.ts @@ -395,7 +395,7 @@ export abstract class APIClient { !headers ? {} : Symbol.iterator in headers ? Object.fromEntries(Array.from(headers as Iterable).map((header) => [...header])) - : { ...headers } + : { ...(headers as any as Record) } ); } From 861f79266b6e92e8dd53a84bf73464ad148bdc22 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 27 Mar 2025 05:52:06 +0000 Subject: [PATCH 11/19] codegen metadata --- .stats.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.stats.yml b/.stats.yml index d9064ff..d0fd0cf 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,4 @@ configured_endpoints: 15 openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/zeroentropy%2Fzeroentropy-99a41bb73e432cb47fe1937219b3c7b109ae534456e8dd019cc00cc1e6018a16.yml +openapi_spec_hash: 25800181cde6b0a31d6726d77ade2aff +config_hash: caa8421b07b8eb2eeb82175ec8427837 From d60d3218f82dc4782cfddb2e164b1e3eb05835c7 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 27 Mar 2025 05:54:56 +0000 Subject: [PATCH 12/19] chore(internal): codegen related update (#40) --- README.md | 33 ------------------ api.md | 2 +- src/index.ts | 4 --- src/resources/documents.ts | 71 +++++++++++++++++++++----------------- src/resources/index.ts | 1 - 5 files changed, 40 insertions(+), 71 deletions(-) diff --git a/README.md b/README.md index fda754c..20d792e 100644 --- a/README.md +++ b/README.md @@ -138,39 +138,6 @@ On timeout, an `APIConnectionTimeoutError` is thrown. Note that requests which time out will be [retried twice by default](#retries). -## Auto-pagination - -List methods in the ZeroEntropy API are paginated. -You can use the `for await … of` syntax to iterate through items across all pages: - -```ts -async function fetchAllDocuments(params) { - const allDocuments = []; - // Automatically fetches more pages as needed. - for await (const documentGetInfoListResponse of client.documents.getInfoList({ - collection_name: 'example_collection', - })) { - allDocuments.push(documentGetInfoListResponse); - } - return allDocuments; -} -``` - -Alternatively, you can request a single page at a time: - -```ts -let page = await client.documents.getInfoList({ collection_name: 'example_collection' }); -for (const documentGetInfoListResponse of page.documents) { - console.log(documentGetInfoListResponse); -} - -// Convenience methods are provided for manually paginating: -while (page.hasNextPage()) { - page = await page.getNextPage(); - // ... -} -``` - ## Advanced Usage ### Accessing raw Response data (e.g., headers) diff --git a/api.md b/api.md index dc39621..23dc689 100644 --- a/api.md +++ b/api.md @@ -49,7 +49,7 @@ Methods: - client.documents.delete({ ...params }) -> DocumentDeleteResponse - client.documents.add({ ...params }) -> DocumentAddResponse - client.documents.getInfo({ ...params }) -> DocumentGetInfoResponse -- client.documents.getInfoList({ ...params }) -> DocumentGetInfoListResponsesGetDocumentInfoListCursor +- client.documents.getInfoList({ ...params }) -> DocumentGetInfoListResponse - client.documents.getPageInfo({ ...params }) -> DocumentGetPageInfoResponse # Queries diff --git a/src/index.ts b/src/index.ts index 5fa5cbb..254837f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,7 +24,6 @@ import { DocumentDeleteResponse, DocumentGetInfoListParams, DocumentGetInfoListResponse, - DocumentGetInfoListResponsesGetDocumentInfoListCursor, DocumentGetInfoParams, DocumentGetInfoResponse, DocumentGetPageInfoParams, @@ -205,8 +204,6 @@ ZeroEntropy.Admin = Admin; ZeroEntropy.Status = Status; ZeroEntropy.Collections = Collections; ZeroEntropy.Documents = Documents; -ZeroEntropy.DocumentGetInfoListResponsesGetDocumentInfoListCursor = - DocumentGetInfoListResponsesGetDocumentInfoListCursor; ZeroEntropy.Queries = Queries; ZeroEntropy.Parsers = Parsers; export declare namespace ZeroEntropy { @@ -248,7 +245,6 @@ export declare namespace ZeroEntropy { type DocumentGetInfoResponse as DocumentGetInfoResponse, type DocumentGetInfoListResponse as DocumentGetInfoListResponse, type DocumentGetPageInfoResponse as DocumentGetPageInfoResponse, - DocumentGetInfoListResponsesGetDocumentInfoListCursor as DocumentGetInfoListResponsesGetDocumentInfoListCursor, type DocumentUpdateParams as DocumentUpdateParams, type DocumentDeleteParams as DocumentDeleteParams, type DocumentAddParams as DocumentAddParams, diff --git a/src/resources/documents.ts b/src/resources/documents.ts index cee81ce..3a6457a 100644 --- a/src/resources/documents.ts +++ b/src/resources/documents.ts @@ -2,7 +2,6 @@ import { APIResource } from '../resource'; import * as Core from '../core'; -import { GetDocumentInfoListCursor, type GetDocumentInfoListCursorParams } from '../pagination'; export class Documents extends APIResource { /** @@ -80,12 +79,8 @@ export class Documents extends APIResource { getInfoList( body: DocumentGetInfoListParams, options?: Core.RequestOptions, - ): Core.PagePromise { - return this._client.getAPIList( - '/documents/get-document-info-list', - DocumentGetInfoListResponsesGetDocumentInfoListCursor, - { body, method: 'post', ...options }, - ); + ): Core.APIPromise { + return this._client.post('/documents/get-document-info-list', { body, ...options }); } /** @@ -103,8 +98,6 @@ export class Documents extends APIResource { } } -export class DocumentGetInfoListResponsesGetDocumentInfoListCursor extends GetDocumentInfoListCursor {} - export interface DocumentUpdateResponse { new_id: string; @@ -163,29 +156,35 @@ export namespace DocumentGetInfoResponse { } export interface DocumentGetInfoListResponse { - id: string; + documents: Array; +} - collection_name: string; +export namespace DocumentGetInfoListResponse { + export interface Document { + id: string; - index_status: - | 'not_parsed' - | 'parsing' - | 'not_indexed' - | 'indexing' - | 'indexed' - | 'parsing_failed' - | 'indexing_failed'; + collection_name: string; - metadata: Record>; + index_status: + | 'not_parsed' + | 'parsing' + | 'not_indexed' + | 'indexing' + | 'indexed' + | 'parsing_failed' + | 'indexing_failed'; - /** - * The number of pages in this document. This will be `null` if the document is - * parsing or failed to parse. It can also be `null` if the document is a filetype - * that does not support pages. - */ - num_pages: number | null; + metadata: Record>; - path: string; + /** + * The number of pages in this document. This will be `null` if the document is + * parsing or failed to parse. It can also be `null` if the document is a filetype + * that does not support pages. + */ + num_pages: number | null; + + path: string; + } } export interface DocumentGetPageInfoResponse { @@ -369,11 +368,23 @@ export interface DocumentGetInfoParams { include_content?: boolean; } -export interface DocumentGetInfoListParams extends GetDocumentInfoListCursorParams { +export interface DocumentGetInfoListParams { /** * The name of the collection. */ collection_name: string; + + /** + * All documents returned will have a UUID strictly greater than the provided UUID. + * (Comparison will be on the binary representations of the UUIDs) + */ + id_gt?: string | null; + + /** + * The maximum number of documents to return. This field is by default 1024, and + * cannot be set larger than 1024 + */ + limit?: number; } export interface DocumentGetPageInfoParams { @@ -404,9 +415,6 @@ export interface DocumentGetPageInfoParams { include_content?: boolean; } -Documents.DocumentGetInfoListResponsesGetDocumentInfoListCursor = - DocumentGetInfoListResponsesGetDocumentInfoListCursor; - export declare namespace Documents { export { type DocumentUpdateResponse as DocumentUpdateResponse, @@ -415,7 +423,6 @@ export declare namespace Documents { type DocumentGetInfoResponse as DocumentGetInfoResponse, type DocumentGetInfoListResponse as DocumentGetInfoListResponse, type DocumentGetPageInfoResponse as DocumentGetPageInfoResponse, - DocumentGetInfoListResponsesGetDocumentInfoListCursor as DocumentGetInfoListResponsesGetDocumentInfoListCursor, type DocumentUpdateParams as DocumentUpdateParams, type DocumentDeleteParams as DocumentDeleteParams, type DocumentAddParams as DocumentAddParams, diff --git a/src/resources/index.ts b/src/resources/index.ts index 46063e4..9956798 100644 --- a/src/resources/index.ts +++ b/src/resources/index.ts @@ -11,7 +11,6 @@ export { type CollectionGetListParams, } from './collections'; export { - DocumentGetInfoListResponsesGetDocumentInfoListCursor, Documents, type DocumentUpdateResponse, type DocumentDeleteResponse, From a78fd51e969d8ab08858b5871a86609c8067b8ce Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 28 Mar 2025 05:51:12 +0000 Subject: [PATCH 13/19] fix(internal): work around https://github.com/vercel/next.js/issues/76881 (#41) --- src/_shims/index-deno.ts | 2 ++ src/_shims/index.d.ts | 2 ++ src/_shims/index.js | 6 +++++- src/_shims/index.mjs | 6 +++++- src/core.ts | 5 +++++ 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/_shims/index-deno.ts b/src/_shims/index-deno.ts index 2fd8565..769920a 100644 --- a/src/_shims/index-deno.ts +++ b/src/_shims/index-deno.ts @@ -108,3 +108,5 @@ export declare class FsReadStream extends Readable { const _ReadableStream = ReadableStream; type _ReadableStream = ReadableStream; export { _ReadableStream as ReadableStream }; + +export const init = () => {}; diff --git a/src/_shims/index.d.ts b/src/_shims/index.d.ts index 32e86b7..0446ffe 100644 --- a/src/_shims/index.d.ts +++ b/src/_shims/index.d.ts @@ -79,3 +79,5 @@ export function fileFromPath(path: string, options?: FileFromPathOptions): Promi export function fileFromPath(path: string, filename?: string, options?: FileFromPathOptions): Promise; export function isFsReadStream(value: any): value is FsReadStream; + +export const init: () => void; diff --git a/src/_shims/index.js b/src/_shims/index.js index 578831c..0289ef5 100644 --- a/src/_shims/index.js +++ b/src/_shims/index.js @@ -3,7 +3,9 @@ */ const shims = require('./registry'); const auto = require('zeroentropy/_shims/auto/runtime'); -if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true }); +exports.init = () => { + if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true }); +}; for (const property of Object.keys(shims)) { Object.defineProperty(exports, property, { get() { @@ -11,3 +13,5 @@ for (const property of Object.keys(shims)) { }, }); } + +exports.init(); diff --git a/src/_shims/index.mjs b/src/_shims/index.mjs index 6508140..1bcfa59 100644 --- a/src/_shims/index.mjs +++ b/src/_shims/index.mjs @@ -3,5 +3,9 @@ */ import * as shims from './registry.mjs'; import * as auto from 'zeroentropy/_shims/auto/runtime'; -if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true }); +export const init = () => { + if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true }); +}; export * from './registry.mjs'; + +init(); diff --git a/src/core.ts b/src/core.ts index 77c7859..e8a5d73 100644 --- a/src/core.ts +++ b/src/core.ts @@ -16,7 +16,12 @@ import { type RequestInit, type Response, type HeadersInit, + init, } from './_shims/index'; + +// try running side effects outside of _shims/index to workaround https://github.com/vercel/next.js/issues/76881 +init(); + export { type Response }; import { BlobLike, isBlobLike, isMultipartBody } from './uploads'; export { From 6c6d3e19561559312962e5b0e0d14c0127519418 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 3 Jun 2025 22:25:40 +0000 Subject: [PATCH 14/19] feat(api): manual updates --- .github/workflows/ci.yml | 46 ++++++++++++------- .github/workflows/publish-npm.yml | 2 +- .stats.yml | 4 +- README.md | 46 +++++++------------ SECURITY.md | 4 +- bin/publish-npm | 30 ++++++++++--- scripts/utils/upload-artifact.sh | 25 +++++++++++ src/core.ts | 24 +++++++--- src/resources/documents.ts | 59 ++++++++++++++++++++---- src/resources/queries.ts | 64 ++++++++++++++++++++++++++- tests/api-resources/documents.test.ts | 3 +- tests/api-resources/queries.test.ts | 1 + 12 files changed, 235 insertions(+), 73 deletions(-) create mode 100755 scripts/utils/upload-artifact.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0312165..333fdc2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,19 +1,18 @@ name: CI on: push: - branches: - - main - pull_request: - branches: - - main - - next + branches-ignore: + - 'generated' + - 'codegen/**' + - 'integrated/**' + - 'stl-preview-head/**' + - 'stl-preview-base/**' jobs: lint: + timeout-minutes: 10 name: lint - runs-on: ubuntu-latest - - + runs-on: ${{ github.repository == 'stainless-sdks/zeroentropy-node' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} steps: - uses: actions/checkout@v4 @@ -29,10 +28,12 @@ jobs: run: ./scripts/lint build: + timeout-minutes: 5 name: build - runs-on: ubuntu-latest - - + runs-on: ${{ github.repository == 'stainless-sdks/zeroentropy-node' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} + permissions: + contents: read + id-token: write steps: - uses: actions/checkout@v4 @@ -46,17 +47,32 @@ jobs: - name: Check build run: ./scripts/build + + - name: Get GitHub OIDC Token + if: github.repository == 'stainless-sdks/zeroentropy-node' + id: github-oidc + uses: actions/github-script@v6 + with: + script: core.setOutput('github_token', await core.getIDToken()); + + - name: Upload tarball + if: github.repository == 'stainless-sdks/zeroentropy-node' + env: + URL: https://pkg.stainless.com/s + AUTH: ${{ steps.github-oidc.outputs.github_token }} + SHA: ${{ github.sha }} + run: ./scripts/utils/upload-artifact.sh test: + timeout-minutes: 10 name: test - runs-on: ubuntu-latest - + runs-on: ${{ github.repository == 'stainless-sdks/zeroentropy-node' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} steps: - uses: actions/checkout@v4 - name: Set up Node uses: actions/setup-node@v4 with: - node-version: '18' + node-version: '20' - name: Bootstrap run: ./scripts/bootstrap diff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-npm.yml index 5fd2ab4..7f37f1c 100644 --- a/.github/workflows/publish-npm.yml +++ b/.github/workflows/publish-npm.yml @@ -19,7 +19,7 @@ jobs: - name: Set up Node uses: actions/setup-node@v3 with: - node-version: '18' + node-version: '20' - name: Install dependencies run: | diff --git a/.stats.yml b/.stats.yml index d0fd0cf..d4574b4 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 15 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/zeroentropy%2Fzeroentropy-99a41bb73e432cb47fe1937219b3c7b109ae534456e8dd019cc00cc1e6018a16.yml -openapi_spec_hash: 25800181cde6b0a31d6726d77ade2aff +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/zeroentropy%2Fzeroentropy-6d4d2509d6d6d6f6cb90dcad9ddc75dc7562ff8ed3a055bee111921a83cb26d3.yml +openapi_spec_hash: 9cf0d15c10c9061cebd0816868366d1d config_hash: caa8421b07b8eb2eeb82175ec8427837 diff --git a/README.md b/README.md index 20d792e..2c38851 100644 --- a/README.md +++ b/README.md @@ -26,17 +26,13 @@ const client = new ZeroEntropy({ apiKey: process.env['ZEROENTROPY_API_KEY'], // This is the default and can be omitted }); -async function main() { - const response = await client.documents.add({ - collection_name: 'example_collection', - content: { type: 'text', text: 'Example Content' }, - path: 'my_document.txt', - }); - - console.log(response.message); -} +const response = await client.documents.add({ + collection_name: 'example_collection', + content: { type: 'text', text: 'Example Content' }, + path: 'my_document.txt', +}); -main(); +console.log(response.message); ``` ### Request & Response types @@ -51,11 +47,7 @@ const client = new ZeroEntropy({ apiKey: process.env['ZEROENTROPY_API_KEY'], // This is the default and can be omitted }); -async function main() { - const response: ZeroEntropy.StatusGetStatusResponse = await client.status.getStatus(); -} - -main(); +const response: ZeroEntropy.StatusGetStatusResponse = await client.status.getStatus(); ``` Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors. @@ -68,22 +60,18 @@ a subclass of `APIError` will be thrown: ```ts -async function main() { - const response = await client.status.getStatus().catch(async (err) => { - if (err instanceof ZeroEntropy.APIError) { - console.log(err.status); // 400 - console.log(err.name); // BadRequestError - console.log(err.headers); // {server: 'nginx', ...} - } else { - throw err; - } - }); -} - -main(); +const response = await client.status.getStatus().catch(async (err) => { + if (err instanceof ZeroEntropy.APIError) { + console.log(err.status); // 400 + console.log(err.name); // BadRequestError + console.log(err.headers); // {server: 'nginx', ...} + } else { + throw err; + } +}); ``` -Error codes are as followed: +Error codes are as follows: | Status Code | Error Type | | ----------- | -------------------------- | diff --git a/SECURITY.md b/SECURITY.md index 374311e..7856016 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -16,11 +16,11 @@ before making any information public. ## Reporting Non-SDK Related Security Issues If you encounter security issues that are not directly related to SDKs but pertain to the services -or products provided by ZeroEntropy please follow the respective company's security reporting guidelines. +or products provided by ZeroEntropy, please follow the respective company's security reporting guidelines. ### ZeroEntropy Terms and Policies -Please contact founders@zeroentropy.dev for any questions or concerns regarding security of our services. +Please contact founders@zeroentropy.dev for any questions or concerns regarding the security of our services. --- diff --git a/bin/publish-npm b/bin/publish-npm index 4c21181..2505dec 100644 --- a/bin/publish-npm +++ b/bin/publish-npm @@ -4,19 +4,35 @@ set -eux npm config set '//registry.npmjs.org/:_authToken' "$NPM_TOKEN" -# Build the project yarn build - -# Navigate to the dist directory cd dist -# Get the version from package.json +# Get latest version from npm +# +# If the package doesn't exist, yarn will return +# {"type":"error","data":"Received invalid response from npm."} +# where .data.version doesn't exist so LAST_VERSION will be an empty string. +LAST_VERSION="$(yarn info --json 2> /dev/null | jq -r '.data.version')" + +# Get current version from package.json VERSION="$(node -p "require('./package.json').version")" -# Extract the pre-release tag if it exists +# Check if current version is pre-release (e.g. alpha / beta / rc) +CURRENT_IS_PRERELEASE=false if [[ "$VERSION" =~ -([a-zA-Z]+) ]]; then - # Extract the part before any dot in the pre-release identifier - TAG="${BASH_REMATCH[1]}" + CURRENT_IS_PRERELEASE=true + CURRENT_TAG="${BASH_REMATCH[1]}" +fi + +# Check if last version is a stable release +LAST_IS_STABLE_RELEASE=true +if [[ -z "$LAST_VERSION" || "$LAST_VERSION" =~ -([a-zA-Z]+) ]]; then + LAST_IS_STABLE_RELEASE=false +fi + +# Use a corresponding alpha/beta tag if there already is a stable release and we're publishing a prerelease. +if $CURRENT_IS_PRERELEASE && $LAST_IS_STABLE_RELEASE; then + TAG="$CURRENT_TAG" else TAG="latest" fi diff --git a/scripts/utils/upload-artifact.sh b/scripts/utils/upload-artifact.sh new file mode 100755 index 0000000..ecda8ab --- /dev/null +++ b/scripts/utils/upload-artifact.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -exuo pipefail + +RESPONSE=$(curl -X POST "$URL" \ + -H "Authorization: Bearer $AUTH" \ + -H "Content-Type: application/json") + +SIGNED_URL=$(echo "$RESPONSE" | jq -r '.url') + +if [[ "$SIGNED_URL" == "null" ]]; then + echo -e "\033[31mFailed to get signed URL.\033[0m" + exit 1 +fi + +UPLOAD_RESPONSE=$(tar -cz dist | curl -v -X PUT \ + -H "Content-Type: application/gzip" \ + --data-binary @- "$SIGNED_URL" 2>&1) + +if echo "$UPLOAD_RESPONSE" | grep -q "HTTP/[0-9.]* 200"; then + echo -e "\033[32mUploaded build to Stainless storage.\033[0m" + echo -e "\033[32mInstallation: npm install 'https://pkg.stainless.com/s/zeroentropy-node/$SHA'\033[0m" +else + echo -e "\033[31mFailed to upload artifact.\033[0m" + exit 1 +fi diff --git a/src/core.ts b/src/core.ts index e8a5d73..199205d 100644 --- a/src/core.ts +++ b/src/core.ts @@ -33,6 +33,20 @@ export { export type Fetch = (url: RequestInfo, init?: RequestInit) => Promise; +/** + * An alias to the builtin `Array` type so we can + * easily alias it in import statements if there are name clashes. + */ +type _Array = Array; + +/** + * An alias to the builtin `Record` type so we can + * easily alias it in import statements if there are name clashes. + */ +type _Record = Record; + +export type { _Array as Array, _Record as Record }; + type PromiseOrValue = T | Promise; type APIResponseProps = { @@ -282,10 +296,10 @@ export abstract class APIClient { } buildRequest( - options: FinalRequestOptions, + inputOptions: FinalRequestOptions, { retryCount = 0 }: { retryCount?: number } = {}, ): { req: RequestInit; url: string; timeout: number } { - options = { ...options }; + const options = { ...inputOptions }; const { method, path, query, headers: headers = {} } = options; const body = @@ -313,8 +327,8 @@ export abstract class APIClient { } if (this.idempotencyHeader && method !== 'get') { - if (!options.idempotencyKey) options.idempotencyKey = this.defaultIdempotencyKey(); - headers[this.idempotencyHeader] = options.idempotencyKey; + if (!inputOptions.idempotencyKey) inputOptions.idempotencyKey = this.defaultIdempotencyKey(); + headers[this.idempotencyHeader] = inputOptions.idempotencyKey; } const reqHeaders = this.buildHeaders({ options, headers, contentLength, retryCount }); @@ -371,7 +385,7 @@ export abstract class APIClient { getHeader(headers, 'x-stainless-timeout') === undefined && options.timeout ) { - reqHeaders['x-stainless-timeout'] = String(options.timeout); + reqHeaders['x-stainless-timeout'] = String(Math.trunc(options.timeout / 1000)); } this.validateHeaders(reqHeaders, headers); diff --git a/src/resources/documents.ts b/src/resources/documents.ts index 3a6457a..f9a6722 100644 --- a/src/resources/documents.ts +++ b/src/resources/documents.ts @@ -69,9 +69,9 @@ export class Documents extends APIResource { * Retrives a list of document metadata information that matches the provided * filters. * - * The documents returned will be sorted by ID in ascending order. `id_gt` can be - * used for pagination, and should be set to the ID of the last document returned - * in the previous call. + * The documents returned will be sorted by path in lexicographically ascending + * order. `path_gt` can be used for pagination, and should be set to the path of + * the last document returned in the previous call. * * A `404 Not Found` will be returned if either the collection name does not exist, * or the document path does not exist within the provided collection. @@ -128,6 +128,15 @@ export namespace DocumentGetInfoResponse { collection_name: string; + /** + * A URL to the document data, which can be used to download the raw document + * content or to display the document in frontend applications. + * + * NOTE: If a `/documents/update-document` call returned a new document id, then + * this url will be invalidated and must be retrieved again. + */ + file_url: string; + index_status: | 'not_parsed' | 'parsing' @@ -148,6 +157,11 @@ export namespace DocumentGetInfoResponse { path: string; + /** + * The total size of the raw document data, in bytes. + */ + size: number; + /** * This will be `null`, unless `include_content` was available and set to `true`. */ @@ -165,6 +179,17 @@ export namespace DocumentGetInfoListResponse { collection_name: string; + created_at: string; + + /** + * A URL to the document data, which can be used to download the raw document + * content or to display the document in frontend applications. + * + * NOTE: If a `/documents/update-document` call returned a new document id, then + * this url will be invalidated and must be retrieved again. + */ + file_url: string; + index_status: | 'not_parsed' | 'parsing' @@ -184,6 +209,11 @@ export namespace DocumentGetInfoListResponse { num_pages: number | null; path: string; + + /** + * The total size of the raw document data, in bytes. + */ + size: number; } } @@ -205,6 +235,9 @@ export namespace DocumentGetPageInfoResponse { * has finished parsing, and if it is a filetype that is capable of producing * images (e.g. PDF, DOCX, PPT, etc). In all other cases, this field will be * `null`. + * + * NOTE: If a `/documents/update-document` call returned a new document id, then + * this url will be invalidated and must be retrieved again. */ image_url: string | null; @@ -374,17 +407,25 @@ export interface DocumentGetInfoListParams { */ collection_name: string; - /** - * All documents returned will have a UUID strictly greater than the provided UUID. - * (Comparison will be on the binary representations of the UUIDs) - */ - id_gt?: string | null; - /** * The maximum number of documents to return. This field is by default 1024, and * cannot be set larger than 1024 */ limit?: number; + + /** + * All documents returned will have a path strictly greater than the provided + * `path_gt` argument. (Comparison will be based on lexicographic comparison. It is + * guaranteed that two strings are lexicographically equal if and only if they have + * identical binary representations.). + */ + path_gt?: string | null; + + /** + * All documents returned will have a path that starts with the provided path + * prefix. + */ + path_prefix?: string | null; } export interface DocumentGetPageInfoParams { diff --git a/src/resources/queries.ts b/src/resources/queries.ts index 890e4fe..da83539 100644 --- a/src/resources/queries.ts +++ b/src/resources/queries.ts @@ -42,6 +42,15 @@ export interface QueryTopDocumentsResponse { export namespace QueryTopDocumentsResponse { export interface Result { + /** + * A URL to the document data, which can be used to download the raw document + * content or to display the document in frontend applications. + * + * NOTE: If a `/documents/update-document` call returned a new document id, then + * this url will be invalidated and must be retrieved again. + */ + file_url: string; + /** * The metadata for that document. Will be `None` if `include_metadata` is `False`. */ @@ -79,6 +88,9 @@ export namespace QueryTopPagesResponse { * has finished parsing, and if it is a filetype that is capable of producing * images (e.g. PDF, DOCX, PPT, etc). In all other cases, this field will be * `null`. + * + * NOTE: If a `/documents/update-document` call returned a new document id, then + * this url will be invalidated and must be retrieved again. */ image_url: string | null; @@ -101,16 +113,57 @@ export namespace QueryTopPagesResponse { } export interface QueryTopSnippetsResponse { + /** + * The array of associated document information. Note how each snippet has an + * associated document path. After deduplicating the document paths, this array + * will contain document info for each document path that is referenced by at least + * one snippet result. + */ + document_results: Array; + + /** + * The array of snippets returned by this endpoint. Each snippet result refers to a + * particular document path, and index range. Note that all documents, regardless + * of filetype, are converted into `UTF-8`-encoded strings. The `start_index` and + * `end_index` of a snippet refer to the range of characters in that string, that + * have been matched by this snippet. + */ results: Array; } export namespace QueryTopSnippetsResponse { + export interface DocumentResult { + /** + * A URL to the document data, which can be used to download the raw document + * content or to display the document in frontend applications. + * + * NOTE: If a `/documents/update-document` call returned a new document id, then + * this url will be invalidated and must be retrieved again. + */ + file_url: string; + + /** + * The metadata for that document. Will be `None` if `include_metadata` is `False`. + */ + metadata: Record> | null; + + /** + * The path of the document. + */ + path: string; + + /** + * The relevancy score assigned to this document. + */ + score: number; + } + /** * This is a Snippet. * * A snippet refers to a particular document path, and index range. Note that all * documents, regardless of filetype, are converted into `UTF-8`-encoded strings. - * The `start_index` and `end_index` refer to the range of characters. in that + * The `start_index` and `end_index` refer to the range of characters in that * string, that have been matched by this snippet. */ export interface Result { @@ -128,7 +181,7 @@ export namespace QueryTopSnippetsResponse { * The range of page indices spanned by this snippet, as a 2-tuple of integers. * Inclusive on the first page_index and exclusive on the second page_index. */ - page_span: Array; + page_span: Array; /** * The path of the document that this snippet comes from. @@ -253,6 +306,13 @@ export interface QueryTopSnippetsParams { */ filter?: Record | null; + /** + * If true, the `document_results` returns will additionally contain document + * metadata. This is false by default, as returning metadata can add overhead if + * the amount of data to return is large. + */ + include_document_metadata?: boolean; + /** * Note that for Top K Snippets, only latency_mode "low" is available. This option * selects between our latency modes. The higher latency mode takes longer, but can diff --git a/tests/api-resources/documents.test.ts b/tests/api-resources/documents.test.ts index d27758e..56b9b03 100644 --- a/tests/api-resources/documents.test.ts +++ b/tests/api-resources/documents.test.ts @@ -101,8 +101,9 @@ describe('resource documents', () => { test('getInfoList: required and optional params', async () => { const response = await client.documents.getInfoList({ collection_name: 'collection_name', - id_gt: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', limit: 0, + path_gt: 'path_gt', + path_prefix: 'path_prefix', }); }); diff --git a/tests/api-resources/queries.test.ts b/tests/api-resources/queries.test.ts index 811e940..7836b69 100644 --- a/tests/api-resources/queries.test.ts +++ b/tests/api-resources/queries.test.ts @@ -82,6 +82,7 @@ describe('resource queries', () => { k: 0, query: 'query', filter: { foo: 'bar' }, + include_document_metadata: true, latency_mode: 'low', precise_responses: true, }); From a9ac4152f59d0fabb2866c628a9d87155b2a471d Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 3 Jun 2025 22:29:39 +0000 Subject: [PATCH 15/19] feat(api): manual updates --- .stats.yml | 2 +- src/pagination.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.stats.yml b/.stats.yml index d4574b4..b84f19f 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 15 openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/zeroentropy%2Fzeroentropy-6d4d2509d6d6d6f6cb90dcad9ddc75dc7562ff8ed3a055bee111921a83cb26d3.yml openapi_spec_hash: 9cf0d15c10c9061cebd0816868366d1d -config_hash: caa8421b07b8eb2eeb82175ec8427837 +config_hash: a7dc8380ffa9d78eee964a96e0eb7b54 diff --git a/src/pagination.ts b/src/pagination.ts index 782b64c..1828ce1 100644 --- a/src/pagination.ts +++ b/src/pagination.ts @@ -7,7 +7,7 @@ export interface GetDocumentInfoListCursorResponse { } export interface GetDocumentInfoListCursorParams { - id_gt?: string; + path_gt?: string; limit?: number; } @@ -54,6 +54,6 @@ export class GetDocumentInfoListCursor return null; } - return { params: { id_gt: id } }; + return { params: { path_gt: id } }; } } From d68a8eb68f20f0e2735b0a74d74593f92265cd03 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 3 Jun 2025 22:30:24 +0000 Subject: [PATCH 16/19] feat(api): manual updates --- .stats.yml | 4 ++-- src/resources/queries.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.stats.yml b/.stats.yml index b84f19f..e679301 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 15 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/zeroentropy%2Fzeroentropy-6d4d2509d6d6d6f6cb90dcad9ddc75dc7562ff8ed3a055bee111921a83cb26d3.yml -openapi_spec_hash: 9cf0d15c10c9061cebd0816868366d1d +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/zeroentropy%2Fzeroentropy-f06c49dfd4b38a4f9d5bcad56348156bbf641aa8b7968acfbf655ad6ceff2126.yml +openapi_spec_hash: cac52dd65fbcb65ffa7a183e764b7f06 config_hash: a7dc8380ffa9d78eee964a96e0eb7b54 diff --git a/src/resources/queries.ts b/src/resources/queries.ts index da83539..594d098 100644 --- a/src/resources/queries.ts +++ b/src/resources/queries.ts @@ -181,7 +181,7 @@ export namespace QueryTopSnippetsResponse { * The range of page indices spanned by this snippet, as a 2-tuple of integers. * Inclusive on the first page_index and exclusive on the second page_index. */ - page_span: Array; + page_span: Array; /** * The path of the document that this snippet comes from. From 4f364c5925cf3203ec0cfefbd30f28280019ac13 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 3 Jun 2025 22:41:49 +0000 Subject: [PATCH 17/19] feat(api): manual updates --- .stats.yml | 2 +- README.md | 33 +++++++++++++ api.md | 2 +- src/index.ts | 4 ++ src/resources/documents.ts | 99 +++++++++++++++++--------------------- src/resources/index.ts | 1 + 6 files changed, 85 insertions(+), 56 deletions(-) diff --git a/.stats.yml b/.stats.yml index e679301..482b6d4 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 15 openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/zeroentropy%2Fzeroentropy-f06c49dfd4b38a4f9d5bcad56348156bbf641aa8b7968acfbf655ad6ceff2126.yml openapi_spec_hash: cac52dd65fbcb65ffa7a183e764b7f06 -config_hash: a7dc8380ffa9d78eee964a96e0eb7b54 +config_hash: 34c8a6deaedce51a258bc46b38c9caa0 diff --git a/README.md b/README.md index 2c38851..455ac58 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,39 @@ On timeout, an `APIConnectionTimeoutError` is thrown. Note that requests which time out will be [retried twice by default](#retries). +## Auto-pagination + +List methods in the ZeroEntropy API are paginated. +You can use the `for await … of` syntax to iterate through items across all pages: + +```ts +async function fetchAllDocumentGetInfoListResponses(params) { + const allDocumentGetInfoListResponses = []; + // Automatically fetches more pages as needed. + for await (const documentGetInfoListResponse of client.documents.getInfoList({ + collection_name: 'example_collection', + })) { + allDocumentGetInfoListResponses.push(documentGetInfoListResponse); + } + return allDocumentGetInfoListResponses; +} +``` + +Alternatively, you can request a single page at a time: + +```ts +let page = await client.documents.getInfoList({ collection_name: 'example_collection' }); +for (const documentGetInfoListResponse of page.documents) { + console.log(documentGetInfoListResponse); +} + +// Convenience methods are provided for manually paginating: +while (page.hasNextPage()) { + page = await page.getNextPage(); + // ... +} +``` + ## Advanced Usage ### Accessing raw Response data (e.g., headers) diff --git a/api.md b/api.md index 23dc689..dc39621 100644 --- a/api.md +++ b/api.md @@ -49,7 +49,7 @@ Methods: - client.documents.delete({ ...params }) -> DocumentDeleteResponse - client.documents.add({ ...params }) -> DocumentAddResponse - client.documents.getInfo({ ...params }) -> DocumentGetInfoResponse -- client.documents.getInfoList({ ...params }) -> DocumentGetInfoListResponse +- client.documents.getInfoList({ ...params }) -> DocumentGetInfoListResponsesGetDocumentInfoListCursor - client.documents.getPageInfo({ ...params }) -> DocumentGetPageInfoResponse # Queries diff --git a/src/index.ts b/src/index.ts index 254837f..5fa5cbb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,6 +24,7 @@ import { DocumentDeleteResponse, DocumentGetInfoListParams, DocumentGetInfoListResponse, + DocumentGetInfoListResponsesGetDocumentInfoListCursor, DocumentGetInfoParams, DocumentGetInfoResponse, DocumentGetPageInfoParams, @@ -204,6 +205,8 @@ ZeroEntropy.Admin = Admin; ZeroEntropy.Status = Status; ZeroEntropy.Collections = Collections; ZeroEntropy.Documents = Documents; +ZeroEntropy.DocumentGetInfoListResponsesGetDocumentInfoListCursor = + DocumentGetInfoListResponsesGetDocumentInfoListCursor; ZeroEntropy.Queries = Queries; ZeroEntropy.Parsers = Parsers; export declare namespace ZeroEntropy { @@ -245,6 +248,7 @@ export declare namespace ZeroEntropy { type DocumentGetInfoResponse as DocumentGetInfoResponse, type DocumentGetInfoListResponse as DocumentGetInfoListResponse, type DocumentGetPageInfoResponse as DocumentGetPageInfoResponse, + DocumentGetInfoListResponsesGetDocumentInfoListCursor as DocumentGetInfoListResponsesGetDocumentInfoListCursor, type DocumentUpdateParams as DocumentUpdateParams, type DocumentDeleteParams as DocumentDeleteParams, type DocumentAddParams as DocumentAddParams, diff --git a/src/resources/documents.ts b/src/resources/documents.ts index f9a6722..2110cee 100644 --- a/src/resources/documents.ts +++ b/src/resources/documents.ts @@ -2,6 +2,7 @@ import { APIResource } from '../resource'; import * as Core from '../core'; +import { GetDocumentInfoListCursor, type GetDocumentInfoListCursorParams } from '../pagination'; export class Documents extends APIResource { /** @@ -79,8 +80,12 @@ export class Documents extends APIResource { getInfoList( body: DocumentGetInfoListParams, options?: Core.RequestOptions, - ): Core.APIPromise { - return this._client.post('/documents/get-document-info-list', { body, ...options }); + ): Core.PagePromise { + return this._client.getAPIList( + '/documents/get-document-info-list', + DocumentGetInfoListResponsesGetDocumentInfoListCursor, + { body, method: 'post', ...options }, + ); } /** @@ -98,6 +103,8 @@ export class Documents extends APIResource { } } +export class DocumentGetInfoListResponsesGetDocumentInfoListCursor extends GetDocumentInfoListCursor {} + export interface DocumentUpdateResponse { new_id: string; @@ -170,51 +177,45 @@ export namespace DocumentGetInfoResponse { } export interface DocumentGetInfoListResponse { - documents: Array; -} + id: string; -export namespace DocumentGetInfoListResponse { - export interface Document { - id: string; + collection_name: string; - collection_name: string; + created_at: string; - created_at: string; + /** + * A URL to the document data, which can be used to download the raw document + * content or to display the document in frontend applications. + * + * NOTE: If a `/documents/update-document` call returned a new document id, then + * this url will be invalidated and must be retrieved again. + */ + file_url: string; - /** - * A URL to the document data, which can be used to download the raw document - * content or to display the document in frontend applications. - * - * NOTE: If a `/documents/update-document` call returned a new document id, then - * this url will be invalidated and must be retrieved again. - */ - file_url: string; + index_status: + | 'not_parsed' + | 'parsing' + | 'not_indexed' + | 'indexing' + | 'indexed' + | 'parsing_failed' + | 'indexing_failed'; - index_status: - | 'not_parsed' - | 'parsing' - | 'not_indexed' - | 'indexing' - | 'indexed' - | 'parsing_failed' - | 'indexing_failed'; + metadata: Record>; - metadata: Record>; - - /** - * The number of pages in this document. This will be `null` if the document is - * parsing or failed to parse. It can also be `null` if the document is a filetype - * that does not support pages. - */ - num_pages: number | null; + /** + * The number of pages in this document. This will be `null` if the document is + * parsing or failed to parse. It can also be `null` if the document is a filetype + * that does not support pages. + */ + num_pages: number | null; - path: string; + path: string; - /** - * The total size of the raw document data, in bytes. - */ - size: number; - } + /** + * The total size of the raw document data, in bytes. + */ + size: number; } export interface DocumentGetPageInfoResponse { @@ -401,26 +402,12 @@ export interface DocumentGetInfoParams { include_content?: boolean; } -export interface DocumentGetInfoListParams { +export interface DocumentGetInfoListParams extends GetDocumentInfoListCursorParams { /** * The name of the collection. */ collection_name: string; - /** - * The maximum number of documents to return. This field is by default 1024, and - * cannot be set larger than 1024 - */ - limit?: number; - - /** - * All documents returned will have a path strictly greater than the provided - * `path_gt` argument. (Comparison will be based on lexicographic comparison. It is - * guaranteed that two strings are lexicographically equal if and only if they have - * identical binary representations.). - */ - path_gt?: string | null; - /** * All documents returned will have a path that starts with the provided path * prefix. @@ -456,6 +443,9 @@ export interface DocumentGetPageInfoParams { include_content?: boolean; } +Documents.DocumentGetInfoListResponsesGetDocumentInfoListCursor = + DocumentGetInfoListResponsesGetDocumentInfoListCursor; + export declare namespace Documents { export { type DocumentUpdateResponse as DocumentUpdateResponse, @@ -464,6 +454,7 @@ export declare namespace Documents { type DocumentGetInfoResponse as DocumentGetInfoResponse, type DocumentGetInfoListResponse as DocumentGetInfoListResponse, type DocumentGetPageInfoResponse as DocumentGetPageInfoResponse, + DocumentGetInfoListResponsesGetDocumentInfoListCursor as DocumentGetInfoListResponsesGetDocumentInfoListCursor, type DocumentUpdateParams as DocumentUpdateParams, type DocumentDeleteParams as DocumentDeleteParams, type DocumentAddParams as DocumentAddParams, diff --git a/src/resources/index.ts b/src/resources/index.ts index 9956798..46063e4 100644 --- a/src/resources/index.ts +++ b/src/resources/index.ts @@ -11,6 +11,7 @@ export { type CollectionGetListParams, } from './collections'; export { + DocumentGetInfoListResponsesGetDocumentInfoListCursor, Documents, type DocumentUpdateResponse, type DocumentDeleteResponse, From 188e90a6a7008044bd3a88baa76433b86e1bafa9 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 4 Jun 2025 01:29:48 +0000 Subject: [PATCH 18/19] feat(api): manual updates --- .stats.yml | 2 +- src/pagination.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.stats.yml b/.stats.yml index 482b6d4..5e6082f 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 15 openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/zeroentropy%2Fzeroentropy-f06c49dfd4b38a4f9d5bcad56348156bbf641aa8b7968acfbf655ad6ceff2126.yml openapi_spec_hash: cac52dd65fbcb65ffa7a183e764b7f06 -config_hash: 34c8a6deaedce51a258bc46b38c9caa0 +config_hash: beba80a17ba64c5439712e85129ab5ad diff --git a/src/pagination.ts b/src/pagination.ts index 1828ce1..e0f0b4f 100644 --- a/src/pagination.ts +++ b/src/pagination.ts @@ -12,7 +12,7 @@ export interface GetDocumentInfoListCursorParams { limit?: number; } -export class GetDocumentInfoListCursor +export class GetDocumentInfoListCursor extends AbstractPage implements GetDocumentInfoListCursorResponse { @@ -49,11 +49,11 @@ export class GetDocumentInfoListCursor return null; } - const id = documents[documents.length - 1]?.id; - if (!id) { + const path = documents[documents.length - 1]?.path; + if (!path) { return null; } - return { params: { path_gt: id } }; + return { params: { path_gt: path } }; } } From 0e7316729045330fa35ce95c206a6bc5a94910e7 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 4 Jun 2025 17:57:01 +0000 Subject: [PATCH 19/19] release: 0.1.0-alpha.4 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 36 +++++++++++++++++++++++++++++++++++ package.json | 2 +- src/version.ts | 2 +- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 17473a2..b3b5e58 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.1.0-alpha.3" + ".": "0.1.0-alpha.4" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 88990a5..9cdf091 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,41 @@ # Changelog +## 0.1.0-alpha.4 (2025-06-04) + +Full Changelog: [v0.1.0-alpha.3...v0.1.0-alpha.4](https://github.com/zeroentropy-ai/zeroentropy-node/compare/v0.1.0-alpha.3...v0.1.0-alpha.4) + +### Features + +* add SKIP_BREW env var to ./scripts/bootstrap ([#34](https://github.com/zeroentropy-ai/zeroentropy-node/issues/34)) ([1db65f9](https://github.com/zeroentropy-ai/zeroentropy-node/commit/1db65f912a1a5f23668ea2519ac8e1f379f0a806)) +* **api:** manual updates ([188e90a](https://github.com/zeroentropy-ai/zeroentropy-node/commit/188e90a6a7008044bd3a88baa76433b86e1bafa9)) +* **api:** manual updates ([4f364c5](https://github.com/zeroentropy-ai/zeroentropy-node/commit/4f364c5925cf3203ec0cfefbd30f28280019ac13)) +* **api:** manual updates ([d68a8eb](https://github.com/zeroentropy-ai/zeroentropy-node/commit/d68a8eb68f20f0e2735b0a74d74593f92265cd03)) +* **api:** manual updates ([a9ac415](https://github.com/zeroentropy-ai/zeroentropy-node/commit/a9ac4152f59d0fabb2866c628a9d87155b2a471d)) +* **api:** manual updates ([6c6d3e1](https://github.com/zeroentropy-ai/zeroentropy-node/commit/6c6d3e19561559312962e5b0e0d14c0127519418)) +* **client:** accept RFC6838 JSON content types ([#35](https://github.com/zeroentropy-ai/zeroentropy-node/issues/35)) ([5175743](https://github.com/zeroentropy-ai/zeroentropy-node/commit/5175743984e1379e05c4baaa5dded94dc1ae6b85)) +* **client:** send `X-Stainless-Timeout` header ([#28](https://github.com/zeroentropy-ai/zeroentropy-node/issues/28)) ([ecd0912](https://github.com/zeroentropy-ai/zeroentropy-node/commit/ecd0912273945a262c29c7520410d6ae927ff177)) + + +### Bug Fixes + +* avoid type error in certain environments ([#39](https://github.com/zeroentropy-ai/zeroentropy-node/issues/39)) ([5be66ff](https://github.com/zeroentropy-ai/zeroentropy-node/commit/5be66ffd2783b79bda15848632f46c1a2b0bd53c)) +* **client:** fix export map for index exports ([#30](https://github.com/zeroentropy-ai/zeroentropy-node/issues/30)) ([1518181](https://github.com/zeroentropy-ai/zeroentropy-node/commit/1518181a12687feeb94e7634194f73f7c6d2a92b)) +* **internal:** work around https://github.com/vercel/next.js/issues/76881 ([#41](https://github.com/zeroentropy-ai/zeroentropy-node/issues/41)) ([a78fd51](https://github.com/zeroentropy-ai/zeroentropy-node/commit/a78fd51e969d8ab08858b5871a86609c8067b8ce)) + + +### Chores + +* **exports:** cleaner resource index imports ([#37](https://github.com/zeroentropy-ai/zeroentropy-node/issues/37)) ([e447d3b](https://github.com/zeroentropy-ai/zeroentropy-node/commit/e447d3b306acdcd7460b8329dd31cc78fedc4388)) +* **exports:** stop using path fallbacks ([#38](https://github.com/zeroentropy-ai/zeroentropy-node/issues/38)) ([f7460de](https://github.com/zeroentropy-ai/zeroentropy-node/commit/f7460de48f5deaead21c777199dfb6acacfdf4ff)) +* **internal:** codegen related update ([#40](https://github.com/zeroentropy-ai/zeroentropy-node/issues/40)) ([d60d321](https://github.com/zeroentropy-ai/zeroentropy-node/commit/d60d3218f82dc4782cfddb2e164b1e3eb05835c7)) +* **internal:** fix devcontainers setup ([#31](https://github.com/zeroentropy-ai/zeroentropy-node/issues/31)) ([0de15d2](https://github.com/zeroentropy-ai/zeroentropy-node/commit/0de15d2ba4cfc81f769646ade15a88c3f30fcaa9)) +* **internal:** remove extra empty newlines ([#36](https://github.com/zeroentropy-ai/zeroentropy-node/issues/36)) ([5b8b92f](https://github.com/zeroentropy-ai/zeroentropy-node/commit/5b8b92f2a64634a3a792b705c066c01132368d3d)) + + +### Documentation + +* update URLs from stainlessapi.com to stainless.com ([#32](https://github.com/zeroentropy-ai/zeroentropy-node/issues/32)) ([f8ec234](https://github.com/zeroentropy-ai/zeroentropy-node/commit/f8ec2343b8ac63893220f698353a5e127899523f)) + ## 0.1.0-alpha.3 (2025-01-28) Full Changelog: [v0.1.0-alpha.2...v0.1.0-alpha.3](https://github.com/zeroentropy-ai/zeroentropy-node/compare/v0.1.0-alpha.2...v0.1.0-alpha.3) diff --git a/package.json b/package.json index b42e730..1935c19 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zeroentropy", - "version": "0.1.0-alpha.3", + "version": "0.1.0-alpha.4", "description": "The official TypeScript library for the ZeroEntropy API", "author": "ZeroEntropy ", "types": "dist/index.d.ts", diff --git a/src/version.ts b/src/version.ts index a64b06c..fe6d1df 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const VERSION = '0.1.0-alpha.3'; // x-release-please-version +export const VERSION = '0.1.0-alpha.4'; // x-release-please-version