@amos.com/node

中文文档
0.1.78发布于 2026/11/07MITTypeScriptESM + CJS近 30 天下载 4174

Node.js client for the Amos Pay API.

原始使用文档
文档目录8 节
  1. Installation
  2. Quick start
  3. Sandbox mode
  4. Custom base URL or fetch
  5. Middleware (e.g. fresh idempotency keys)
  6. API surface
  7. Types
  8. Versioning

Amos

A typed Node.js client for the Amos Pay API, generated from the OpenAPI spec with openapi-typescript and powered by openapi-fetch.

Docs: the full Amos API reference lives at docs.amos.com. This package is the typed Node.js binding for that API.

Installation

npm install @amos.com/node

Quick start

import {
  createPayApiClient,
  AMOS_API_BASE_URL_PRODUCTION,
  AMOS_API_VERSION,
} from "@amos.com/node";

const pay = createPayApiClient({
  baseUrl: AMOS_API_BASE_URL_PRODUCTION,
  headers: {
    "X-Api-Key": process.env.AMOS_API_KEY!,
    "X-Api-Version": AMOS_API_VERSION,
  },
});

const { data, error } = await pay.POST("/customers", {
  body: { customer: { email: "[email protected]" } },
});

if (error) {
  console.error(error);
} else {
  console.log(data);
}

Sandbox mode

Swap the base URL constant:

import {
  createPayApiClient,
  AMOS_API_BASE_URL_SANDBOX,
  AMOS_API_VERSION,
} from "@amos.com/node";

const pay = createPayApiClient({
  baseUrl: AMOS_API_BASE_URL_SANDBOX,
  headers: {
    "X-Api-Key": process.env.AMOS_API_KEY!,
    "X-Api-Version": AMOS_API_VERSION,
  },
});

Custom base URL or fetch

createPayApiClient accepts any of openapi-fetch's ClientOptions, so you can point at a proxy or supply your own fetch:

const pay = createPayApiClient({
  baseUrl: "https://my-proxy.example.com",
  fetch: customFetchImpl,
  headers: {
    "X-Api-Key": process.env.AMOS_API_KEY!,
    "X-Api-Version": AMOS_API_VERSION,
    "X-Trace-Id": "abc123",
  },
});

Middleware (e.g. fresh idempotency keys)

import type { Middleware } from "@amos.com/node";

const idempotencyKey: Middleware = {
  async onRequest({ request }) {
    if (request.method === "POST") {
      request.headers.set("Idempotency-Key", crypto.randomUUID());
    }
    return request;
  },
};

pay.use(idempotencyKey);

API surface

import {
  createPayApiClient,
  AMOS_API_BASE_URL_PRODUCTION,
  AMOS_API_BASE_URL_SANDBOX,
  AMOS_API_VERSION,
} from "@amos.com/node";
import type { PayApiClient, ClientOptions, Middleware } from "@amos.com/node";
  • createPayApiClient(options) — returns a typed openapi-fetch client. Exposes the full openapi-fetch interface: GET, POST, PUT, DELETE, OPTIONS, HEAD, PATCH, TRACE, use, eject.
  • AMOS_API_BASE_URL_PRODUCTION / AMOS_API_BASE_URL_SANDBOX — base URLs for the two environments.
  • AMOS_API_VERSION — the wire-level X-Api-Version this build targets. Pass it as the X-Api-Version header on every request (most easily as a default in headers, as shown above).
  • PayApiClient — the type returned by createPayApiClient.
  • ClientOptions, Middleware — re-exported from openapi-fetch for convenience.

Types

All schema types are re-exported from the main entry. For example:

import type { components, paths, operations } from "@amos.com/node";

type Customer = components["schemas"]["Customer"];

Versioning

We follow SemVer for the npm package, with one extra rule: the major version tracks the wire-level X-Api-Version header.

npm rangeX-Api-Version it targets
@amos.com/[email protected]1
@amos.com/[email protected]2 (hypothetical)

So bumping AMOS_API_VERSION is always a major release, and consumers who pin to @amos.com/node@^1 know they will never be transparently upgraded onto a new wire contract.

The mental rule for bumps: "would a program that typechecked against the previous dist/index.d.ts still typecheck against the new one?" If no, it's a major.

Pre-1.0 caveat. While we're on 0.x, breaking changes can land in any 0.x release. Strict SemVer (and the API-version-tracks-major rule above) starts the day we cut 1.0.0. Pin to an exact 0.x.y if you need stability today.

版本与发布记录

@amos.com/node 共发布 77 个版本,首次发布于 2026/05/13;过去 12 个月发布了 77 个版本。

版本发布日期距今
0.1.78latest2026/11/07今天
0.1.772026/11/034 天前
0.1.762026/10/2612 天前
0.1.752026/10/2217 天前
0.1.742026/10/2018 天前
0.1.732026/10/1622 天前

关于 @amos.com/node 的常见问题

@amos.com/node 是什么?

Node.js client for the Amos Pay API.

如何安装 @amos.com/node?

在项目目录运行 npm install @amos.com/node,或使用 pnpm add / yarn add / bun add。

@amos.com/node 支持 TypeScript 吗?

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

@amos.com/node 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@amos.com/node 需要什么版本的 Node.js?

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

@amos.com/node 可以商用吗?

@amos.com/node 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@amos.com/node 的下载量有多少?

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

@amos.com/node 还在维护吗?

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