@ferscloud/fers-calculation-web

中文文档
0.2.83发布于 2026/11/03SEE LICENSE IN LICENSETypeScriptES Module零依赖近 30 天下载 2539

Structural analysis FEM solver for beams, frames and trusses, compiled from Rust to WebAssembly. Runs in the browser or in Node with no server round-trip. Includes Eurocode EN 1993-1-1 steel checks.

原始使用文档
文档目录17 节
  1. Installation
  2. Bundler setup (browser build)
  3. Quick start — free tier (non-commercial, up to 100 members)
  4. Response shape
  5. Authenticated tier — Pro (up to 10 000 members)
  6. How it works
  7. 1. Get an API key
  8. 2. Backend: fetch a solve token
  9. 3. Frontend: call the solver with the token
  10. Tier comparison
  11. Several cores: solving in parts
  12. Security note
  13. TypeScript types
  14. Deflected shape (optional)
  15. Attribution
  16. Licence
  17. Links

@ferscloud/fers-calculation

The engine of FERS: structural finite-element analysis (3D frames, trusses, plates, Eurocode 3 checks) for engineers and AI agents, compiled from Rust to WebAssembly. It runs entirely in the browser or in Node.js — no server round-trip per calculation.

This README covers both published packages: @ferscloud/fers-calculation (Node.js / server-side, --target nodejs) and @ferscloud/fers-calculation-web (browser / bundler, --target bundler). The API is identical; only installation and bundler setup differ.

Installation

# Browser apps (Vite, Next.js, webpack):
npm install @ferscloud/fers-calculation-web
# Node.js / server-side:
npm install @ferscloud/fers-calculation

Bundler setup (browser build)

@ferscloud/fers-calculation-web is a WASM ES module that initialises via top-level await. Most bundlers need a one-time config:

Vite

npm i -D vite-plugin-wasm
// vite.config.ts
import wasm from "vite-plugin-wasm";

// The package initialises with a top-level await, so the build target has to
// be one that supports it. `esnext` needs no second plugin.
export default {
  plugins: [wasm()],
  build: { target: "esnext" },
};

esnext keeps the top-level await in the output, which needs Chrome, Edge or Firefox 89+, or Safari 15+. If you still have vite-plugin-top-level-await in your config from an earlier version of this README, drop it — recent @swc/core releases make it fail at vite build.

Next.js / webpack

// next.config.js
module.exports = {
  transpilePackages: ["@ferscloud/fers-calculation-web"],
  webpack(config) {
    config.experiments = { ...config.experiments, asyncWebAssembly: true };
    config.output.environment = { ...config.output.environment, asyncFunction: true };
    return config;
  },
};

The solver is synchronous and CPU-bound; for large models run it inside a Web Worker so the UI thread stays responsive. The Node.js package (@ferscloud/fers-calculation) needs no bundler config.

Quick start — free tier (non-commercial, up to 100 members)

import { calculate_from_json } from "@ferscloud/fers-calculation";

// No init() call needed — the nodejs and bundler builds initialise the
// WASM module automatically on import.
const res = JSON.parse(calculate_from_json(JSON.stringify(myModel)));
if (res.ok) {
  const data = res.result; // displacements, member_results, unity_checks, …
} else {
  console.error(res.error.code, res.error.message);
}

No API key required. Works for any model with up to 100 members.

Response shape

Every solver call returns a JSON envelope, so you JSON.parse once and branch on ok — you never have to sniff whether the returned string "looks like" an error:

// success
{ "ok": true,  "result": { /* the full result document */ } }
// failure (invalid model, over the member limit, malformed JSON, …)
{ "ok": false, "error": { "code": "LimitExceeded",
                          "message": "Number of members (250) exceeds allowed maximum of 100" } }

error.code is one of InvalidJson, LimitExceeded, SolveError, InternalPanic, InternalSerialization. The return value is always valid JSON.

Authenticated tier — Pro (up to 10 000 members)

Pro limits are unlocked by passing a short-lived signed token issued by the FERS Cloud server. The token is verified inside the WASM using an Ed25519 public key baked into the binary — it cannot be forged.

How it works

Your server  →  POST https://ferscloud.com/api/solver/token  →  signed 30-min token
                (X-API-Key: <your-api-key>)

Browser  →  calculate_from_json_with_token(model, token)  →  Pro limits unlocked

1. Get an API key

Log in at ferscloud.com, go to Profile → API Keys, and create a key. Store it as an environment variable on your server — never in browser code.

2. Backend: fetch a solve token

Your server fetches and caches the token. Example for a Next.js API route:

// pages/api/solve-token.ts
const FERS_API_KEY = process.env.FERS_API_KEY!;

let cached: { token: string; expiresAt: number } | null = null;

export default async function handler(req, res) {
  const now = Date.now();

  // Re-use if more than 5 minutes remain
  if (cached && cached.expiresAt - now > 5 * 60 * 1000) {
    return res.json({ token: cached.token });
  }

  const resp = await fetch("https://ferscloud.com/api/solver/token", {
    method: "POST",
    headers: { "X-API-Key": FERS_API_KEY },
  });

  if (!resp.ok) return res.status(502).json({ error: "Token fetch failed" });

  const { token, expiresAt } = await resp.json();
  cached = { token, expiresAt: new Date(expiresAt).getTime() };
  return res.json({ token });
}

Same pattern works for Express, Deno, Bun, Cloudflare Workers, or any server-side runtime.

3. Frontend: call the solver with the token

import { calculate_from_json_with_token } from "@ferscloud/fers-calculation";

const { token } = await fetch("/api/solve-token").then(r => r.json());

const res = JSON.parse(calculate_from_json_with_token(JSON.stringify(myModel), token));
if (!res.ok) throw new Error(`${res.error.code}: ${res.error.message}`);
const data = res.result;

If the token is missing, expired, or invalid, the solver falls back to the free 100-member limit — it never throws (a genuine solve failure comes back as { ok: false, error }, not an exception).

Tier comparison

FeatureFreeProEnterprise
UseNon-commercialCommercial and non-commercialCommercial and non-commercial, by agreement
Max members10010 0001 000 000
WASM functioncalculate_from_jsoncalculate_from_json_with_tokencalculate_from_json_with_token
Requires tokenNoYesYes
Token TTL—30 minutes30 minutes

An Enterprise token is a Pro token that also carries "plan":"enterprise"; engines before 0.2.78 read it as Pro. In the browser, memory runs out long before 1 000 000 members: the WASM build has 4 GB and one thread.

Several cores: solving in parts

One WASM instance solves on one thread. To spread a model's load combinations over several workers (Web Workers in a browser, worker_threads in Node), give every worker the same model string and its own part, and merge what they return:

// worker.js: one per core
import { calculate_part_from_json } from "@ferscloud/fers-calculation-web";

self.onmessage = ({ data: { model, index, count } }) => {
  self.postMessage(calculate_part_from_json(model, index, count));
};
// main thread
import { merge_parts_from_json } from "@ferscloud/fers-calculation-web";

const model = JSON.stringify(myModel); // one string, the same bytes everywhere
const count = workers.length;
const parts = await Promise.all(
  workers.map((worker, index) => solveIn(worker, { model, index, count })) // resolves with the worker's string
);
const res = JSON.parse(merge_parts_from_json(model, parts)); // what calculate_from_json returns
  • The merged envelope is byte for byte what calculate_from_json returns for the same model. If a part failed, the merge returns that part's error envelope, the one a single solve would have stopped on.
  • Pass the parts unopened and in index order. The merge reads them itself; parsing them in JavaScript only costs time.
  • Only the combinations are divided. Every part reads the whole model and, whenever one solve would, solves the load cases, so each combination starts where it would in one solve; part 0 also reports the load cases and runs the modal, buckling and seismic analyses. Combinations that share a name always fall in the same part.
  • Each worker holds its own copy of the model and of its solve, so memory grows with the number of workers.
  • With a solve token, use calculate_part_from_json_with_token(model, token, index, count) in the workers and merge_parts_from_json_with_token(model, token, parts) to merge.

Security note

Keep your FERS_API_KEY server-side only. The solve token it fetches is safe to pass to the browser — it is short-lived and cryptographically signed. Only FERS Cloud can issue valid tokens; the browser WASM can only verify them.

TypeScript types

The browser package ships generated model types alongside the function signatures:

import type { FERS, ResultsBundle } from "@ferscloud/fers-calculation-web/fers-models";

FERS is the input model; ResultsBundle is the result payload of a successful envelope. Both are generated from the engine's OpenAPI schema, so they track the published version.

Deflected shape (optional)

Set include_member_deflected_shape in the model's analysis options to get a ready-to-plot, load-exact deflected shape per member — the member's global displacement sampled along its length — instead of reconstructing the curve yourself:

const model = {
  /* … model + load cases … */
  analysis: { /* … */ options: { /* … */ include_member_deflected_shape: true } },
};

const res = JSON.parse(calculate_from_json(JSON.stringify(model)));
const mr = res.result.results.loadcases["…"].member_results["1"];
// mr.member_displacements: [{ x_frac, displacement: [dx, dy, dz] }, …]
//   x_frac 0→1 along the member; displacement in the global input frame.

Off by default to keep the payload lean; omitted from member_results when not requested.

Attribution

Free-tier results carry an attribution object minted inside the solver. Premium results (solved with a valid solve token) do not, so the same code credits FERS on the free tier and white-labels on Pro:

import { fersAttributionHtml } from "@ferscloud/fers-calculation-web/badge";

// "" when the result came back from a Pro solve.
const credit = fersAttributionHtml(res);

getFersAttribution, fersAttributionText and createFersBadge are also exported. All of them accept the envelope, the parsed model or the results bundle, and all return nothing for a Pro result or an error envelope.

On 0.2.61 this subpath resolved only under a bundler; plain Node ESM needed /badge.js. From 0.2.62 the package ships an exports map and both forms work everywhere.

Using the free tier in a non-commercial application? Please display the credit.

Licence

From 0.2.70 the engine is licensed under the PolyForm Strict License 1.0.0 (see LICENSE). It is free for any noncommercial purpose: study, teaching, research, hobby projects, and use by schools, charities and public bodies. Models of more than 100 members need a Pro solve token.

Commercial use, at any model size, needs a paid FERS Cloud plan, which includes the commercial licence. The licence does not allow modifying or redistributing the package.

版本与发布记录

@ferscloud/fers-calculation-web 共发布 97 个版本,首次发布于 2026/03/12;过去 12 个月发布了 97 个版本。

版本发布日期距今
0.2.83latest2026/11/0311 天前
0.2.822026/11/0311 天前
0.2.812026/11/0311 天前
0.2.802026/11/0212 天前
0.2.792026/11/0113 天前
0.2.782026/11/0113 天前

关于 @ferscloud/fers-calculation-web 的常见问题

@ferscloud/fers-calculation-web 是什么?

Structural analysis FEM solver for beams, frames and trusses, compiled from Rust to WebAssembly. Runs in the browser or in Node with no server round-trip. Includes Eurocode EN 1993-1-1 steel checks.

如何安装 @ferscloud/fers-calculation-web?

在项目目录运行 npm install @ferscloud/fers-calculation-web,或使用 pnpm add / yarn add / bun add。

@ferscloud/fers-calculation-web 支持 TypeScript 吗?

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

@ferscloud/fers-calculation-web 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@ferscloud/fers-calculation-web 可以商用吗?

@ferscloud/fers-calculation-web 使用 SEE LICENSE IN LICENSE 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@ferscloud/fers-calculation-web 的下载量有多少?

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

@ferscloud/fers-calculation-web 还在维护吗?

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