@borga/node

中文文档
0.10.1发布于 2026/11/06MITTypeScriptESM + CJS零依赖近 30 天下载 1900

Borga Node.js client library — typed access to the Borga API.

原始使用文档
文档目录7 节
  1. Installation
  2. Usage
  3. Embedded checkout
  4. Usage events (metered billing)
  5. Webhooks
  6. Behavior
  7. Documentation

@borga/node

Official Node.js client for the Borga API: card payments, bank invoices (krafa), subscriptions and metered billing for the Icelandic market.

Installation

npm install @borga/node

Requires Node.js 18 or newer.

Usage

Authenticate with a secret API key (sk_test_… or sk_live_…) from the Borga dashboard under Developers. The key identifies your merchant, so no other header is needed.

import { Borga } from "@borga/node";

const borga = new Borga({ apiKey: process.env.BORGA_SECRET_KEY! });

// Create a hosted checkout session and redirect the payer to session.url
const session = await borga.paymentSessions.create({
  amount: 24180, // whole krónur: 24.180 kr.
  currency: "ISK",
  return_url: "https://example.is/order/complete",
  cancel_url: "https://example.is/cart",
  external_reference: "order_1042",
});

An app acting for a merchant through a Borga OAuth grant passes the access token instead: new Borga({ accessToken }). Pass one credential, not both; defaultHeaders adds headers to every request but cannot set Authorization. The grant's scopes decide which calls succeed.

Embedded checkout

const session = await borga.paymentSessions.create({
  amount: 24180,
  currency: "ISK",
  mode: "embedded",
  origin: "https://example.is",
});

// Hand session.id and session.client_secret to the browser and open the
// modal with borga.js:  new Borga(pk).checkout.open({ sessionId, clientSecret })

Usage events (metered billing)

await borga.usageEvents.create({
  event_name: "api_call",
  customer: "cus_…",
  idempotency_key: "req_…",
  metadata: { units: 1 },
});

Webhooks

import { verifyWebhookSignature } from "@borga/node";

const event = verifyWebhookSignature({
  body: rawRequestBody, // the raw string or Buffer, not the parsed JSON
  signature: req.headers["borga-signature"],
  secret: process.env.BORGA_WEBHOOK_SECRET!,
});

switch (event.type) {
  case "payment.succeeded":
    // event.data is narrowed to the Payment object
    break;
  case "invoice.payment_failed":
    // event.data.attempt, event.data.reason
    break;
}

Behavior

  • POST requests get an auto-generated Idempotency-Key, so retries are safe. Pass your own with { idempotencyKey } to make retries across processes safe too.
  • 5xx, 429 and network errors are retried with exponential backoff (3 retries by default).
  • API errors throw BorgaError with type, code, status, param, requestId and the parsed body.

Documentation

Guides and the full API reference live at docs.borga.is. Every code sample there is typechecked against this package.

版本与发布记录

@borga/node 共发布 15 个版本,首次发布于 2026/09/08;过去 12 个月发布了 15 个版本。

版本发布日期距今
0.10.1latest2026/11/062 天前
0.10.02026/11/062 天前
0.9.02026/11/062 天前
0.8.02026/11/062 天前
0.7.12026/11/035 天前
0.7.02026/11/035 天前

关于 @borga/node 的常见问题

@borga/node 是什么?

Borga Node.js client library — typed access to the Borga API.

如何安装 @borga/node?

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

@borga/node 支持 TypeScript 吗?

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

@borga/node 支持 ESM 还是 CommonJS?

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

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

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

@borga/node 可以商用吗?

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

@borga/node 的下载量有多少?

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

@borga/node 还在维护吗?

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