@chariot-giving/typescript-sdk

中文文档
2.0.0-a0发布于 2025/03/05TypeScriptCommonJS近 30 天下载 1874

fern shield [![npm shi

原始使用文档
文档目录12 节
  1. Installation
  2. Usage
  3. Request And Response Types
  4. Exception Handling
  5. Automatic Pagination
  6. Advanced
  7. Retries
  8. Timeouts
  9. Aborting Requests
  10. Runtime Compatibility
  11. Customizing Fetch Client
  12. Contributing

Chariot TypeScript Library

fern shield npm shield

The Chariot TypeScript library provides convenient access to the Chariot API from TypeScript.

Installation

npm i -s @chariot-giving/typescript-sdk

Usage

Instantiate and use the client with the following:

import { ChariotClient } from "@chariot-giving/typescript-sdk";

const client = new ChariotClient({ token: "YOUR_TOKEN" });
await client.nonprofits.create({
    user: {
        email: "[email protected]",
    },
    ein: "043567500",
});

Request And Response Types

The SDK exports all request and response types as TypeScript interfaces. Simply import them with the following namespace:

import { Chariot } from "@chariot-giving/typescript-sdk";

const request: Chariot.NonprofitsCreateRequest = {
    ...
};

Exception Handling

When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error will be thrown.

import { ChariotError } from "@chariot-giving/typescript-sdk";

try {
    await client.nonprofits.create(...);
} catch (err) {
    if (err instanceof ChariotError) {
        console.log(err.statusCode);
        console.log(err.message);
        console.log(err.body);
    }
}

Automatic Pagination

List endpoints are paginated. The SDK provides an iterator so that you can simply loop over the items:

const result = await client.events.list();
for await (const event of result) {
    console.log(event);
}

You can also iterate page-by-page:

let page = await client.events.list();
for (const event of page.data) {
    console.log(event);
}

or manually:

while (page.hasNextPage()) {
    page = page.getNextPage();
    // ...
}

Advanced

Retries

The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retriable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).

A request is deemed retriable when any of the following HTTP status codes is returned:

  • 408 (Timeout)
  • 429 (Too Many Requests)
  • 5XX (Internal Server Errors)

Use the maxRetries request option to configure this behavior.

const response = await client.nonprofits.create(..., {
    maxRetries: 0 // override maxRetries at the request level
});

Timeouts

The SDK defaults to a 60 second timeout. Use the timeoutInSeconds option to configure this behavior.

const response = await client.nonprofits.create(..., {
    timeoutInSeconds: 30 // override timeout to 30s
});

Aborting Requests

The SDK allows users to abort requests at any point by passing in an abort signal.

const controller = new AbortController();
const response = await client.nonprofits.create(..., {
    abortSignal: controller.signal
});
controller.abort(); // aborts the request

Runtime Compatibility

The SDK defaults to node-fetch but will use the global fetch client if present. The SDK works in the following runtimes:

  • Node.js 18+
  • Vercel
  • Cloudflare Workers
  • Deno v1.25+
  • Bun 1.0+
  • React Native

Customizing Fetch Client

The SDK provides a way for your to customize the underlying HTTP client / Fetch function. If you're running in an unsupported environment, this provides a way for you to break glass and ensure the SDK works.

import { ChariotClient } from "@chariot-giving/typescript-sdk";

const client = new ChariotClient({
    ...
    fetcher: // provide your implementation here
});

Contributing

While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!

版本与发布记录

@chariot-giving/typescript-sdk 共发布 6 个版本,首次发布于 2024/08/09;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.0-a0latest2025/03/051.7 年前
1.1.02024/09/072 年前
1.0.02024/08/172 年前
0.0.1-alpha9alpha2024/08/172 年前
0.0.1-alpha82024/08/172 年前
0.0.42024/08/092 年前

关于 @chariot-giving/typescript-sdk 的常见问题

@chariot-giving/typescript-sdk 是什么?

[![npm shi

如何安装 @chariot-giving/typescript-sdk?

在项目目录运行 npm install @chariot-giving/typescript-sdk,或使用 pnpm add / yarn add / bun add。

@chariot-giving/typescript-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@chariot-giving/typescript-sdk 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@chariot-giving/typescript-sdk 可以商用吗?

@chariot-giving/typescript-sdk 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@chariot-giving/typescript-sdk 的下载量有多少?

根据 npm 官方下载统计,@chariot-giving/typescript-sdk 在 2026/10/10 – 2026/11/08 这 30 天内被下载 1,874 次,日均约 62 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@chariot-giving/typescript-sdk 还在维护吗?

最新版本 2.0.0-a0 发布于 2025/03/05(1.7 年前);至今共发布 6 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/08/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。