Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2025 Zeroentropy
Copyright 2025 ZeroEntropy

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Zeroentropy Node API Library
# ZeroEntropy Node API Library

[![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.
This library provides convenient access to the ZeroEntropy REST API from server-side TypeScript or JavaScript.

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).

Expand All @@ -20,9 +20,9 @@ The full API of this library can be found in [api.md](api.md).

<!-- prettier-ignore -->
```js
import Zeroentropy from 'zeroentropy';
import ZeroEntropy from 'zeroentropy';

const client = new Zeroentropy({
const client = new ZeroEntropy({
apiKey: process.env['ZEROENTROPY_API_KEY'], // This is the default and can be omitted
});

Expand All @@ -45,14 +45,14 @@ This library includes TypeScript definitions for all request params and response

<!-- prettier-ignore -->
```ts
import Zeroentropy from 'zeroentropy';
import ZeroEntropy from 'zeroentropy';

const client = new Zeroentropy({
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();
const response: ZeroEntropy.StatusGetStatusResponse = await client.status.getStatus();
}

main();
Expand All @@ -70,7 +70,7 @@ 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) {
if (err instanceof ZeroEntropy.APIError) {
console.log(err.status); // 400
console.log(err.name); // BadRequestError
console.log(err.headers); // {server: 'nginx', ...}
Expand Down Expand Up @@ -107,7 +107,7 @@ You can use the `maxRetries` option to configure or disable this:
<!-- prettier-ignore -->
```js
// Configure the default for all requests:
const client = new Zeroentropy({
const client = new ZeroEntropy({
maxRetries: 0, // default is 2
});

Expand All @@ -124,7 +124,7 @@ Requests time out after 1 minute by default. You can configure this with a `time
<!-- prettier-ignore -->
```ts
// Configure the default for all requests:
const client = new Zeroentropy({
const client = new ZeroEntropy({
timeout: 20 * 1000, // 20 seconds (default is 1 minute)
});

Expand All @@ -140,7 +140,7 @@ Note that requests which time out will be [retried twice by default](#retries).

## Auto-pagination

List methods in the Zeroentropy API are paginated.
List methods in the ZeroEntropy API are paginated.
You can use the `for await … of` syntax to iterate through items across all pages:

```ts
Expand Down Expand Up @@ -181,7 +181,7 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi

<!-- prettier-ignore -->
```ts
const client = new Zeroentropy();
const client = new ZeroEntropy();

const response = await client.status.getStatus().asResponse();
console.log(response.headers.get('X-My-Header'));
Expand Down Expand Up @@ -242,13 +242,13 @@ By default, this library uses `node-fetch` in Node, and expects a global `fetch`

If you would prefer to use a global, web-standards-compliant `fetch` function even in a Node environment,
(for example, if you are running Node with `--experimental-fetch` or using NextJS which polyfills with `undici`),
add the following import before your first import `from "Zeroentropy"`:
add the following import before your first import `from "ZeroEntropy"`:

```ts
// Tell TypeScript and the package to use the global web fetch instead of node-fetch.
// Note, despite the name, this does not add any polyfills, but expects them to be provided if needed.
import 'zeroentropy/shims/web';
import Zeroentropy from 'zeroentropy';
import ZeroEntropy from 'zeroentropy';
```

To do the inverse, add `import "zeroentropy/shims/node"` (which does import polyfills).
Expand All @@ -261,9 +261,9 @@ which can be used to inspect or alter the `Request` or `Response` before/after e

```ts
import { fetch } from 'undici'; // as one example
import Zeroentropy from 'zeroentropy';
import ZeroEntropy from 'zeroentropy';

const client = new Zeroentropy({
const client = new ZeroEntropy({
fetch: async (url: RequestInfo, init?: RequestInit): Promise<Response> => {
console.log('About to make a request', url, init);
const response = await fetch(url, init);
Expand All @@ -288,7 +288,7 @@ import http from 'http';
import { HttpsProxyAgent } from 'https-proxy-agent';

// Configure the default for all requests:
const client = new Zeroentropy({
const client = new ZeroEntropy({
httpAgent: new HttpsProxyAgent(process.env.PROXY_URL),
});

Expand Down
4 changes: 2 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ 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
### ZeroEntropy Terms and Policies

Please contact [email protected] for any questions or concerns regarding security of our services.

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "zeroentropy",
"version": "0.1.0-alpha.1",
"description": "The official TypeScript library for the Zeroentropy API",
"author": "Zeroentropy <[email protected]>",
"description": "The official TypeScript library for the ZeroEntropy API",
"author": "ZeroEntropy <[email protected]>",
"types": "dist/index.d.ts",
"main": "dist/index.js",
"type": "commonjs",
Expand Down
2 changes: 1 addition & 1 deletion scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ npm exec tsc-multi
# copy over handwritten .js/.mjs/.d.ts files
cp src/_shims/*.{d.ts,js,mjs,md} dist/_shims
cp src/_shims/auto/*.{d.ts,js,mjs} dist/_shims/auto
# we need to add exports = module.exports = Zeroentropy to index.js;
# we need to add exports = module.exports = ZeroEntropy to index.js;
# No way to get that from index.ts because it would cause compile errors
# when building .mjs
node scripts/utils/fix-index-exports.cjs
Expand Down
20 changes: 10 additions & 10 deletions src/core.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { VERSION } from './version';
import {
ZeroentropyError,
ZeroEntropyError,
APIError,
APIConnectionError,
APIConnectionTimeoutError,
Expand Down Expand Up @@ -504,7 +504,7 @@ export abstract class APIClient {
if (value === null) {
return `${encodeURIComponent(key)}=`;
}
throw new ZeroentropyError(
throw new ZeroEntropyError(
`Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`,
);
})
Expand Down Expand Up @@ -654,7 +654,7 @@ export abstract class AbstractPage<Item> implements AsyncIterable<Item> {
async getNextPage(): Promise<this> {
const nextInfo = this.nextPageInfo();
if (!nextInfo) {
throw new ZeroentropyError(
throw new ZeroEntropyError(
'No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.',
);
}
Expand Down Expand Up @@ -990,10 +990,10 @@ export const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve

const validatePositiveInteger = (name: string, n: unknown): number => {
if (typeof n !== 'number' || !Number.isInteger(n)) {
throw new ZeroentropyError(`${name} must be an integer`);
throw new ZeroEntropyError(`${name} must be an integer`);
}
if (n < 0) {
throw new ZeroentropyError(`${name} must be a positive integer`);
throw new ZeroEntropyError(`${name} must be a positive integer`);
}
return n;
};
Expand All @@ -1010,7 +1010,7 @@ export const castToError = (err: any): Error => {

export const ensurePresent = <T>(value: T | null | undefined): T => {
if (value == null)
throw new ZeroentropyError(`Expected a value to be given but received ${value} instead.`);
throw new ZeroEntropyError(`Expected a value to be given but received ${value} instead.`);
return value;
};

Expand All @@ -1035,14 +1035,14 @@ export const coerceInteger = (value: unknown): number => {
if (typeof value === 'number') return Math.round(value);
if (typeof value === 'string') return parseInt(value, 10);

throw new ZeroentropyError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
throw new ZeroEntropyError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
};

export const coerceFloat = (value: unknown): number => {
if (typeof value === 'number') return value;
if (typeof value === 'string') return parseFloat(value);

throw new ZeroentropyError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
throw new ZeroEntropyError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
};

export const coerceBoolean = (value: unknown): boolean => {
Expand Down Expand Up @@ -1108,7 +1108,7 @@ function applyHeadersMut(targetHeaders: Headers, newHeaders: Headers): void {

export function debug(action: string, ...args: any[]) {
if (typeof process !== 'undefined' && process?.env?.['DEBUG'] === 'true') {
console.log(`Zeroentropy:DEBUG:${action}`, ...args);
console.log(`ZeroEntropy:DEBUG:${action}`, ...args);
}
}

Expand Down Expand Up @@ -1193,7 +1193,7 @@ export const toBase64 = (str: string | null | undefined): string => {
return btoa(str);
}

throw new ZeroentropyError('Cannot generate b64 string; Expected `Buffer` or `btoa` to be defined');
throw new ZeroEntropyError('Cannot generate b64 string; Expected `Buffer` or `btoa` to be defined');
};

export function isObj(obj: unknown): obj is Record<string, unknown> {
Expand Down
4 changes: 2 additions & 2 deletions src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import { castToError, Headers } from './core';

export class ZeroentropyError extends Error {}
export class ZeroEntropyError extends Error {}

export class APIError<
TStatus extends number | undefined = number | undefined,
THeaders extends Headers | undefined = Headers | undefined,
TError extends Object | undefined = Object | undefined,
> extends ZeroentropyError {
> extends ZeroEntropyError {
/** HTTP status for the response that caused the error */
readonly status: TStatus;
/** HTTP headers for the response that caused the error */
Expand Down
32 changes: 16 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ export interface ClientOptions {
}

/**
* API Client for interfacing with the Zeroentropy API.
* API Client for interfacing with the ZeroEntropy API.
*/
export class Zeroentropy extends Core.APIClient {
export class ZeroEntropy extends Core.APIClient {
apiKey: string;

private _options: ClientOptions;

/**
* API Client for interfacing with the Zeroentropy API.
* API Client for interfacing with the ZeroEntropy API.
*
* @param {string | undefined} [opts.apiKey=process.env['ZEROENTROPY_API_KEY'] ?? undefined]
* @param {string} [opts.baseURL=process.env['ZEROENTROPY_BASE_URL'] ?? https://api.zeroentropy.dev/v1] - Override the default base URL for the API.
Expand All @@ -131,8 +131,8 @@ export class Zeroentropy extends Core.APIClient {
...opts
}: ClientOptions = {}) {
if (apiKey === undefined) {
throw new Errors.ZeroentropyError(
"The ZEROENTROPY_API_KEY environment variable is missing or empty; either provide it, or instantiate the Zeroentropy client with an apiKey option, like new Zeroentropy({ apiKey: 'My API Key' }).",
throw new Errors.ZeroEntropyError(
"The ZEROENTROPY_API_KEY environment variable is missing or empty; either provide it, or instantiate the ZeroEntropy client with an apiKey option, like new ZeroEntropy({ apiKey: 'My API Key' }).",
);
}

Expand Down Expand Up @@ -176,10 +176,10 @@ export class Zeroentropy extends Core.APIClient {
return { Authorization: `Bearer ${this.apiKey}` };
}

static Zeroentropy = this;
static ZeroEntropy = this;
static DEFAULT_TIMEOUT = 60000; // 1 minute

static ZeroentropyError = Errors.ZeroentropyError;
static ZeroEntropyError = Errors.ZeroEntropyError;
static APIError = Errors.APIError;
static APIConnectionError = Errors.APIConnectionError;
static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
Expand All @@ -197,14 +197,14 @@ export class Zeroentropy extends Core.APIClient {
static fileFromPath = Uploads.fileFromPath;
}

Zeroentropy.Status = Status;
Zeroentropy.Collections = Collections;
Zeroentropy.Documents = Documents;
Zeroentropy.DocumentGetInfoListResponsesGetDocumentInfoListCursor =
ZeroEntropy.Status = Status;
ZeroEntropy.Collections = Collections;
ZeroEntropy.Documents = Documents;
ZeroEntropy.DocumentGetInfoListResponsesGetDocumentInfoListCursor =
DocumentGetInfoListResponsesGetDocumentInfoListCursor;
Zeroentropy.Queries = Queries;
Zeroentropy.Parsers = Parsers;
export declare namespace Zeroentropy {
ZeroEntropy.Queries = Queries;
ZeroEntropy.Parsers = Parsers;
export declare namespace ZeroEntropy {
export type RequestOptions = Core.RequestOptions;

export import GetDocumentInfoListCursor = Pagination.GetDocumentInfoListCursor;
Expand Down Expand Up @@ -263,7 +263,7 @@ export declare namespace Zeroentropy {

export { toFile, fileFromPath } from './uploads';
export {
ZeroentropyError,
ZeroEntropyError,
APIError,
APIConnectionError,
APIConnectionTimeoutError,
Expand All @@ -278,4 +278,4 @@ export {
UnprocessableEntityError,
} from './error';

export default Zeroentropy;
export default ZeroEntropy;
6 changes: 3 additions & 3 deletions src/resource.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import type { Zeroentropy } from './index';
import type { ZeroEntropy } from './index';

export class APIResource {
protected _client: Zeroentropy;
protected _client: ZeroEntropy;

constructor(client: Zeroentropy) {
constructor(client: ZeroEntropy) {
this._client = client;
}
}
6 changes: 3 additions & 3 deletions tests/api-resources/collections.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import Zeroentropy from 'zeroentropy';
import ZeroEntropy from 'zeroentropy';
import { Response } from 'node-fetch';

const client = new Zeroentropy({
const client = new ZeroEntropy({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});
Expand Down Expand Up @@ -53,7 +53,7 @@ describe('resource collections', () => {
test('getList: request options and params are passed correctly', async () => {
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
await expect(client.collections.getList({}, { path: '/_stainless_unknown_path' })).rejects.toThrow(
Zeroentropy.NotFoundError,
ZeroEntropy.NotFoundError,
);
});
});
4 changes: 2 additions & 2 deletions tests/api-resources/documents.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import Zeroentropy from 'zeroentropy';
import ZeroEntropy from 'zeroentropy';
import { Response } from 'node-fetch';

const client = new Zeroentropy({
const client = new ZeroEntropy({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});
Expand Down
Loading