@finteqhub/sdk-js

中文文档
0.17.0发布于 2026/09/24TypeScriptCommonJS零依赖近 30 天下载 2600

SDK for interacting with the processing API

原始使用文档
文档目录10 节
  1. Retries and error diagnostics
  2. SDK identification header
  3. API
  4. processing.getSession()
  5. processing.submitForm(data)
  6. Usage
  7. Submit only
  8. Render the form from session data
  9. Releasing
  10. Beta releases

processing-sdk

Use new Processing(options: ProcessingOptions) to create an instance of the Processing object. The Processing object is your entrypoint to the processing SDK.

interface ProcessingOptions {
  apiUrl: string;
  fingerprintVisitorId: string;
  sessionId: string;
  isSecure?: boolean; // default false
  retryOptions?: RetryOptions; // default {}
}

const processing = new Processing({
  apiUrl: 'api-url',
  fingerprintVisitorId: 'fingerprint-visitor-id',
  sessionId: 'session-id',
});

The constructor validates its options and throws a TypeError when they are not an object, when they contain an unknown key (for example a misspelled issecure), when apiUrl, fingerprintVisitorId or sessionId is missing, empty or not a string, when isSecure is not a boolean, or when retryOptions is malformed (see Retries and error diagnostics).

Retries and error diagnostics

Failed HTTP requests are retried automatically with exponential backoff (100ms → 200ms → 500ms → 1000ms → 2000ms; every retry after the fifth waits 2000ms). Retries can be configured via the optional retryOptions constructor option:

interface RetryOptions {
  retryCount?: number; // number of retries after the initial attempt, default 5; 0 disables retries
  retryStatusCode?: (statusCode: number) => boolean; // default: statusCode < 200 || statusCode === 408 || statusCode >= 500
}

const processing = new Processing({
  apiUrl: 'api-url',
  fingerprintVisitorId: 'fingerprint-visitor-id',
  sessionId: 'session-id',
  retryOptions: { retryCount: 3 },
});

To disable retries entirely, pass retryCount: 0 — every request is then sent exactly once, as in 0.11.0. Error diagnostics (RequestError, the console.error dump) are still collected:

const processing = new Processing({
  apiUrl: 'api-url',
  fingerprintVisitorId: 'fingerprint-visitor-id',
  sessionId: 'session-id',
  retryOptions: { retryCount: 0 },
});

The constructor throws a TypeError when retryOptions is not an object, retryCount is not a non-negative integer, or retryStatusCode is not a function.

Network errors (the browser could not reach the server at all, e.g. TypeError: Failed to fetch, or the connection dropped while the response body was being read) are always retried too.

Every retry attempt is reported with console.warn. When a request finally fails, the SDK logs console.error (sdk-js: request failed: <message>) with a full diagnostic dump and rejects with a RequestError whose diagnostics field carries the same payload — include it in your error reporting. diagnostics.kind tells the failure class apart:

  • "network" — the browser never got a complete response (e.g. TypeError: Failed to fetch, or the body could not be read); diagnostics.error describes the thrown error, diagnostics.response.status is present when headers had arrived before the failure, message is request to <url> failed after N attempt(s): ...;
  • "http_error" — an error response (non-200 status, or an error field in the body); message is the error text from the response body (or unexpected response status <code> when the body has none), diagnostics.response.status carries the HTTP status and diagnostics.response.error the error text from the body;
  • "invalid_json" — the response body is not valid JSON; both diagnostics.error (the parse error; its message follows the same policy as the body — sanitized for non-200, omitted for 200 responses) and diagnostics.response are set.

Every diagnostics payload also includes:

  • sdkVersion;
  • request: url, method, x-request-id, session id, and per-attempt log attempts: [{ durationMs, status?, error? }] — attempt durations help tell an instant failure (DNS/connection refused) from a hang (timeout/handshake);
  • response.body for non-200 responses — truncated to 500 chars with long digit runs masked (***); the body of a 200 response is never included since it may carry session credentials; the request body is never included anywhere;
  • response.error — the error field of the response body, for any status (including a 200 response with an error field); it is a business error text, so it is neither truncated nor masked;
  • environment: navigator.onLine, document.visibilityState, navigator.connection (effectiveType/rtt/downlink, Chromium only), timestamp.

Diagnostics are collected regardless of whether retries are enabled.

SDK identification header

Every request the SDK makes carries an extra header:

x-pgw-sdk: sdk-js/<version>

The value contains the SDK name and version (kept in sync with package.json by a test) — for example sdk-js/0.11.0. The backend uses this header to identify traffic coming from the official SDK integration — for example to notify affected merchants when a security fix is released. It does not affect authentication or request routing.

The header is added automatically to every request and cannot be disabled.

API

processing.getSession()

Use processing.getSession to get session information (payment methods, credential fields, operation amount and currency, init credentials) for rendering the form. It is optional: submitForm does not depend on it and can be called right after constructing the instance.

processing
  .getSession()
  .then(result => console.log(result))
  .catch(error => console.warn(error));

processing.submitForm(data)

Use processing.submitForm to submit transaction. When called, processing.submitForm will attempt to complete any required actions to process the transaction. This method returns promise which resolves with response ({ "type": "redirect", "redirectUrl": string}) or error that describes the failure.

processing
  .submitForm(data)
  .then(result => console.log(result))
  .catch(error => console.warn(error));

Usage

Submit only

The minimal flow is to construct the instance and call submitForm — no other request is needed before it. Use it when your own UI already knows what to collect from the customer (for example, the payment method and its credential fields are fixed on your side):

import { Processing } from "@finteqhub/sdk-js";
import FingerprintJS from "@fingerprintjs/fingerprintjs";

const fp = await FingerprintJS.load();
const result = await fp.get();

const processing = new Processing({ apiUrl, fingerprintVisitorId: result.visitorId, sessionId });

const data = {/** collect data from form **/}

processing
  .submitForm(data)
  .then(result => console.log(result))
  .catch(error => console.warn(error));

Render the form from session data

Call getSession first when the form itself is built from the session: available payment methods, their credential fields, the operation amount and currency. submitForm does not use the result — it only drives your UI:

const processing = new Processing({ apiUrl, fingerprintVisitorId: result.visitorId, sessionId });

const session = await processing.getSession();

const data = {/** collect data from form rendered from session **/}

processing
  .submitForm(data)
  .then(result => console.log(result))
  .catch(error => console.warn(error));

Releasing

On every version bump update both package.json version and SDK_VERSION in src/version.ts — they must stay in sync so the x-pgw-sdk header reports the right version. src/version.test.ts fails CI if they drift (node scripts/sync-version.js updates src/version.ts from package.json). Describe the release in CHANGELOG.md, including migration notes for breaking changes.

Beta releases

To try changes before bumping the version, run the publish-beta workflow (GitHub → Actions → publish-beta → Run workflow, pick your branch). It publishes <current version>-beta.<run number> to npm under the beta dist-tag — latest and the version in the repo stay untouched. Install it with:

npm i @finteqhub/sdk-js@beta

or pin the exact version printed in the workflow summary.

版本与发布记录

@finteqhub/sdk-js 共发布 34 个版本,首次发布于 2022/10/04;过去 12 个月发布了 18 个版本。

版本发布日期距今
0.17.0latest2026/09/241 个月前
0.17.0-beta.1beta2026/09/241 个月前
0.16.02026/09/221 个月前
0.16.0-beta.22026/09/221 个月前
0.16.0-beta.12026/09/221 个月前
0.15.02026/09/181 个月前

关于 @finteqhub/sdk-js 的常见问题

@finteqhub/sdk-js 是什么?

SDK for interacting with the processing API

如何安装 @finteqhub/sdk-js?

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

@finteqhub/sdk-js 支持 TypeScript 吗?

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

@finteqhub/sdk-js 支持 ESM 还是 CommonJS?

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

@finteqhub/sdk-js 可以商用吗?

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

@finteqhub/sdk-js 的下载量有多少?

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

@finteqhub/sdk-js 还在维护吗?

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