@faiber/faiber-modules

中文文档
2.8.0发布于 2026/11/14TypeScriptES Module近 30 天下载 3874

Products, variants, carts, orders, inventory, editorial posts and pages, taxonomy, SEO, generic comments and reactions, access rules, pricing, and samples.

原始使用文档
文档目录9 节
  1. Install
  2. Configure
  3. Complete capability
  4. Authentication and authorization
  5. Inputs, queries, responses, and transport
  6. Errors and cancellation
  7. Storefront checkout and public forms
  8. Hosted catalog search
  9. Editorial management, media and agent proposals

@faiber/faiber-modules

Products, variants, carts, orders, inventory, editorial posts and pages, taxonomy, SEO, generic comments and reactions, access rules, pricing, and samples.

Install

npm install @faiber/faiber-modules

Configure

import { FaiberClient, MemoryTokenProvider } from "@faiber/sdk-core";
import { ModulesApi } from "@faiber/faiber-modules";

const tokens = new MemoryTokenProvider();
const client = new FaiberClient("modules", {
  domains: { modules: process.env.FAIBER_MODULES_URL! },
  tokenProvider: tokens,
  axios: { timeout: 15_000, withCredentials: true },
});
const api = new ModulesApi(client);

const products = await api.products.list({
  page_number: 1,
  page_size: 24,
});
const posts = await api.posts.list();

Complete capability

This package exposes 179 registered operations from the content and commerce modules service. Common workflows have concise methods on api; every registered backend route is also available as a named function on api.operations. Generated operation input, query, response, path, verb, and permission contracts are exported from operations.types.

AreaOperationsHTTP methods
access4DELETE, GET, POST, PUT
audit-log1GET
author6DELETE, GET, PATCH, POST, PUT
blog6DELETE, GET, PATCH, POST, PUT
cart2GET, PUT
category9DELETE, GET, PATCH, POST, PUT
comment8DELETE, GET, PATCH, POST, PUT
content9DELETE, GET, PATCH, POST, PUT
content-transfer4GET, PUT
integration1GET
inventory12DELETE, GET, PATCH, POST, PUT
management-api17GET, POST, PUT
media3GET, POST
order12DELETE, GET, PATCH, POST, PUT
podcast8DELETE, GET, PATCH, POST
product13DELETE, GET, PATCH, POST, PUT
reaction3DELETE, GET, POST
request13DELETE, GET, PATCH, POST, PUT
router6GET, POST
search1GET
seo-content9DELETE, GET, PATCH, POST, PUT
service-pricing6DELETE, GET, PATCH, POST, PUT
session1GET
stock-movement2GET, POST
tag9DELETE, GET, PATCH, POST, PUT
user-sample14DELETE, GET, PATCH, POST, PUT

Categories, tags, comments, reactions, SEO, content attachments, pricing, access, and commerce operations are available under api.operations. Community feeds and social posts are provided by @faiber/faiber-social.

Authentication and authorization

Use a TokenProvider to forward the signed-in user's Bearer token, or enable withCredentials for secure HttpOnly cookie sessions. Permission requirements copied from service route guards are included in each operation's JSDoc. The SDK does not embed API keys, credentials, localhost URLs, sandbox hosts, or production hosts.

Inputs, queries, responses, and transport

All methods return the complete Axios response, including status, headers, and request IDs. Request bodies and query objects are named exported interfaces. Modules pagination uses page_number and page_size, normally defaulting to 1 and 10, with size clamped to 1–100. Collection envelopes retain names such as products, orders, posts and stock_movements. Serialized optional fields are nullable. Standard Axios request options, headers, timeouts, adapters, interceptors, and AbortSignal cancellation are supported as the final argument.

Generic REST resources are capability-guarded. Calling a legacy method that the service does not register throws UnsupportedOperationError before sending a request instead of producing a backend 405.

Errors and cancellation

try {
  await api.client.get("/health", undefined, { signal: AbortSignal.timeout(5_000) });
} catch (error) {
  // Axios errors retain response.status and the service error body.
}

Use @faiber/faiber-ts-sdk when one application needs multiple Faiber services with one configuration.

Storefront checkout and public forms

const quote = await api.operations.orderQuotePost({
  id: checkoutId,
  items: [{ variant_id: variantId, quantity: 1 }],
  shipping: { fullName: "Test Buyer", phone: "+989000000000", city: "Rasht", address: "Delivery address", postalCode: "1234567890" },
}, { headers: { Origin: websiteOrigin } });
await api.operations.orderPayPost(checkoutId, { max_total: quote.data.total }, { headers: { Origin: websiteOrigin } });

These owner-scoped operations use /api/v1/shop/checkout/* and return raw ShopCheckout records. Shipping uses camelCase; checkout amounts are integer IRR. Reuse the checkout UUID on retries and retain the configured website Origin for quote, pay and cancel. The server owns prices and rejects stale accepted totals.

operations.routerListGet({page:1}) lists published storefront products, 100 per page with hasMore. requestSubmitPost retains administrative request-log behavior; the separate public-form operation submits an idempotent submission_id to website_contact, website_newsletter, or website_waitlist. Public forms validate email and field bounds, reject honeypot content and return 429 when rate limited. Website defaults provisioning requires modules:request:create.

Wildcard file paths use raw nonempty segments and preserve directory separators. Do not pre-encode paths or include dot traversal, percent escapes, query/fragment syntax or backslashes; invalid paths fail locally before transport.

const categories = await api.categories.list({ search: "Hardware", page_number: 1, page_size: 20 });
const tags = await api.tags.list({ search: "release" });
const seo = await api.seo.list({ search: "/products/" });
console.log(categories.data.data.search, categories.data.data.total_items);

The same query and response are available on api.operations.categoryListCategoriesGet, tagListTagsGet, and seoContentListSeoContentsGet. Categories and tags match their name; SEO matches title or URL. Matching is a case-insensitive literal substring: %, _, and backslash are ordinary characters. The server trims whitespace and echoes the normalized search, or null for blank/omitted search. Inputs over 128 Unicode characters or containing NUL return HTTP 400. Blank/omitted search keeps the existing catalog and count. Pages start at 1; page size is clamped to 1–100 (default 10), ordered by UUID ascending. Deleted rows are excluded; search adds no status, tenant, or permission semantics. Full Axios status, headers, errors, cancellation, and the existing configured authorization are retained.

Editorial management, media and agent proposals

Published content lookup returns a raw ContentDocument. Management content/settings updates, publish and restore require If-Match with the current ETag; convenience methods accept the ETag explicitly. Missing preconditions return 428 and stale revisions 412. Content reads/writes require content:read/content:write, publishing requires content:publish, and settings use settings:read/settings:write.

runAgent returns SSE text and accepts a stable idempotency key; the generated operation accepts the key in options.headers. Agent models/runs require agent:run, proposal reads agent:audit, and approvals/rejections agent:apply (risky approvals also require agent:approve-risky). Preserve error events as well as HTTP failures. Media downloads return bytes; uploads use multipart kind and file, with image/video limits enforced by the service.

SKU, cart items, editor documents, SEO sections, audit metadata, request form data and agent context/diffs remain arbitrary JSON because the backend stores serde_json::Value. Their surrounding records and collection envelopes are concrete exported types. Orders require authenticated owners or an admin role; the service computes prices from active variants and enforces stock/payment transitions.

版本与发布记录

@faiber/faiber-modules 共发布 66 个版本,首次发布于 2026/07/18;过去 12 个月发布了 66 个版本。

版本发布日期距今
2.8.0latest2026/11/14今天
2.7.02026/11/059 天前
2.6.02026/11/049 天前
2.5.02026/11/049 天前
2.4.02026/11/0310 天前
2.3.02026/11/0211 天前

关于 @faiber/faiber-modules 的常见问题

@faiber/faiber-modules 是什么?

Products, variants, carts, orders, inventory, editorial posts and pages, taxonomy, SEO, generic comments and reactions, access rules, pricing, and samples.

如何安装 @faiber/faiber-modules?

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

@faiber/faiber-modules 支持 TypeScript 吗?

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

@faiber/faiber-modules 支持 ESM 还是 CommonJS?

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

@faiber/faiber-modules 可以商用吗?

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

@faiber/faiber-modules 的下载量有多少?

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

@faiber/faiber-modules 还在维护吗?

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