@chift/chift-nodejs

中文文档
1.0.35发布于 2026/09/01Apache License 2.0TypeScriptCommonJS近 30 天下载 9万

The Chift NodeJS library provides convenient access to the Chift API from applications written in the NodeJS language (Javascript/Typescript).

原始使用文档
文档目录12 节
  1. Documentation
  2. Requirements
  3. Installation
  4. Example
  5. Features
  6. Idempotency with Client Request ID
  7. Raw Data Access
  8. Development
  9. Regenerate the OpenAPI schema
  10. Schema sync workflow
  11. Module layout
  12. Add routes

Chift Node.js Library

npm version Build Coverage Status code style: prettier

The Chift NodeJS library provides convenient access to the Chift API from applications written in the NodeJS language (Javascript/Typescript).

Documentation

See the API docs.

Requirements

Node 18 or higher.

Installation

Install the package with:

npm install @chift/chift-nodejs
# or
yarn add @chift/chift-nodejs

Example

const chift = require('@chift/chift-nodejs');
const client = new chift.API({
    clientId: process.env.CHIFT_TESTING_CLIENTID,
    clientSecret: process.env.CHIFT_TESTING_CLIENTSECRET,
    accountId: process.env.CHIFT_TESTING_ACCOUNTID,
});
const consumers = await client.Consumers.getConsumers();
// my first consumer has a POS connection
const locations = await consumers[0].pos.getLocations();

Features

Idempotency with Client Request ID

The SDK supports idempotency for create and update operations using the x-chift-client-requestid header. This helps prevent duplicate resource creation. See developer guide

// Create a client with idempotency
const client = await consumer.accounting.createClient({ name: 'Acme Corp' }, undefined, {
    clientRequestId: 'unique-request-id-123',
});

// Update a client with idempotency
const updatedClient = await consumer.accounting.updateClient(
    'client-id',
    { name: 'Acme Corporation' },
    undefined,
    { clientRequestId: 'unique-update-id-456' }
);

Raw Data Access

The SDK supports accessing raw data from the API using the rawData parameter:

// Get raw data from invoices
const rawInvoices = await consumer.accounting.getInvoicesByType(
    'customer_invoice',
    {},
    { rawData: true }
);

// Get raw data from orders
const rawOrders = await consumer.ecommerce.getOrders({}, { rawData: true });

Development

Regenerate the OpenAPI schema

npx openapi-typescript https://api.chift.eu/openapi.json -o src/types/public-api/schema.d.ts
npx prettier --write src/types/public-api/schema.d.ts

Compare the result with the existing file. If there are no changes, stop.

Schema sync workflow

After regenerating schema.d.ts, classify the diff before editing modules:

  • Module updates are needed when new endpoints are added, existing endpoints are removed or renamed, or schema types referenced in src/modules / test/ change.
  • A schema-only update is enough when changes are limited to types, enums, or fields that no module references, or are documentation/formatting-only.

npm run build passing does not prove module coverage is complete, but it also does not mean modules must always change. Inspect the schema diff and existing module coverage to decide.

When new public endpoints are added, expose them in the SDK. When only non-breaking schema refinements land and nothing in the modules references the changed symbols, skip module edits.

Finish with a patch version bump in package.json, a matching package-lock.json update (npm install --package-lock-only), a CHANGELOG.md entry (separate Modules and Schema subsections), and a successful npm run build.

Module layout

Inspect src/modules/ to learn the current structure. In general:

  • Vertical APIs (accounting, banking, ecommerce, invoicing, payment, pms, pos, custom) use a *Factory pattern and are exposed on consumer.<api>.
  • Consumer-scoped management APIs (connections, per-consumer syncs, datalayer) live in consumer.ts.
  • Sync-level APIs live in syncs.ts.
  • Other top-level APIs have matching files in src/modules/.

New top-level modules must also be wired in src/modules/api.ts (import, property, and constructor assignment) before they are exposed on client.<api>.

Follow existing methods in the target module. Copy exact paths from the schema paths section — do not guess URLs from operation names.

Add routes

The library handles pagination. If the route parameters in the schema contain page and size, use AutoPaginatedParams<T> for the route parameters in the module.

If the query parameter is optional in the schema, declare params as optional in the module. If it is required, make params required.

For example, in accounting.ts, the parameters['query'] for operations['accounting_get_analytic_plans'] should be replaced with AutoPaginatedParams<operations['accounting_get_analytic_plans']['parameters']['query']>.

Since query is optional, getAnalyticPlans should be declared as getAnalyticPlans(params?: GetAnalyticPlansParams).

Return types

Do not copy the OpenAPI response type blindly. The SDK runtime shape depends on how the method is wired:

  • Factory methods (*Factory, exposed on consumer.<api>) go through createApiFor → makeRequest. For paginated GET list endpoints, makeRequest fetches every page and returns a flat array of items. Type these as RequestData<Item[]> using the element type from the page schema (e.g. ContactItem[]), not ChiftPage_ContactItem_. Compare with sibling list methods in the same module such as getClients or getPayments.
  • Direct InternalAPI methods (consumer.ts, syncs.ts, …) call _internalApi directly and return the raw API response. Type them to match sibling methods in the same file.

Factory methods return RequestData<...> with method, url, and optionally params, body, rawData, or clientRequestId.

When adding a method for a new operation, add a corresponding entry in src/types/public-api/mappings.ts.

Integration tests in test/modules/ depend on live credentials and test-environment data. Fix type references there when the schema breaks compilation, but do not add or run integration tests as part of schema sync — failing tests are not a blocker.

For prior examples of schema sync PRs, look at recent commits that touch schema.d.ts and src/modules/.

版本与发布记录

@chift/chift-nodejs 共发布 35 个版本,首次发布于 2023/09/14;过去 12 个月发布了 8 个版本。

版本发布日期距今
1.0.35latest2026/09/012 个月前
1.0.342026/05/135 个月前
1.0.322026/03/177 个月前
1.0.312026/03/137 个月前
1.0.302026/03/127 个月前
1.0.292026/02/168 个月前

关于 @chift/chift-nodejs 的常见问题

@chift/chift-nodejs 是什么?

The Chift NodeJS library provides convenient access to the Chift API from applications written in the NodeJS language (Javascript/Typescript).

如何安装 @chift/chift-nodejs?

在项目目录运行 npm install @chift/chift-nodejs,或使用 pnpm add / yarn add / bun add。

@chift/chift-nodejs 支持 TypeScript 吗?

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

@chift/chift-nodejs 支持 ESM 还是 CommonJS?

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

@chift/chift-nodejs 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@chift/chift-nodejs 可以商用吗?

@chift/chift-nodejs 使用 Apache License 2.0 许可。声明的许可为 Apache License 2.0,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@chift/chift-nodejs 的下载量有多少?

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

@chift/chift-nodejs 还在维护吗?

最新版本 1.0.35 发布于 2026/09/01(2 个月前);至今共发布 35 个版本,其中过去 12 个月发布了 8 个;首次发布于 2023/09/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。