@faiber/faiber-reservation

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

Bookable services, providers, provider-service assignments, work schedules, generated and available slots, and reservations.

原始使用文档
文档目录7 节
  1. Install
  2. Configure
  3. Complete capability
  4. Authentication and authorization
  5. Inputs, queries, responses, and transport
  6. Errors and cancellation
  7. Capacity, time and retained history

@faiber/faiber-reservation

Bookable services, providers, provider-service assignments, work schedules, generated and available slots, and reservations.

Install

npm install @faiber/faiber-reservation

Configure

import { FaiberClient, MemoryTokenProvider } from "@faiber/sdk-core";
import { ReservationApi } from "@faiber/faiber-reservation";

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

const slots = await api.availableSlots({
  provider_id: 42,
  service_id: 8,
  date: "2026-07-22",
});
await api.setSchedules(42, {
  schedules: [{ day_of_week: "monday", start_time: "09:00", end_time: "12:00" }],
});
const generated = await api.generateSlots({
  provider_id: 42, service_id: 8,
  from_date: "2026-11-02", to_date: "2026-11-02",
});
console.log(generated.data.data); // number of newly generated rows
const booking = await api.reservations.create({
  time_slot_id: 73,
  user_id: "00000000-0000-4000-8000-000000000042", // actual IDP customer UUID
  notes: "Consultation",
});
await api.reservations.delete(booking.data.data.id); // cancel; data:null

Complete capability

This package exposes 30 source-mounted operations from the reservations 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
integration1GET
provider8DELETE, GET, PATCH, POST
reservation5DELETE, GET, PATCH, POST
reservation-service5DELETE, GET, PATCH, POST
router3GET
time-slot5DELETE, GET, PATCH, POST
work-schedule2GET, PUT

Provider, service, slot and reservation IDs are local numbers; customer and linked provider user_id values are IDP UUID strings. Booking creation takes time_slot_id, user_id and optional notes; it derives provider/service from the existing slot. Provider capacity defaults to 1 and active flags use is_active.

Catalog/provider/booking lists return {status,message,data:{data:[...],meta:{page,page_size,total_items,total_pages}}}. Availability, schedules and assigned services return unpaged arrays in data. Booking list/show/update currently return starts_at:null; read its slot for the interval. Creation includes the slot start time. Null/omitted patch text fields preserve their existing values.

Schedules use weekday names, start_time/end_time in HH:MM, and optional is_active. Setting schedules replaces the entire set; an empty array clears it. Appointment timestamps are RFC3339 and date filters are UTC YYYY-MM-DD. Local calendar conversion belongs in application presentation code.

Authentication and authorization

Use a TokenProvider to forward the signed-in user's Bearer token, or enable withCredentials for secure HttpOnly cookie sessions. The mounted service middleware requires a trusted non-nil current user, organization context and matching resource/action or accepted reservation manage grant for management operations. Health, OpenAPI, availability and Flow metadata GETs are public. Each operation documents its accepted grants. 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. Nested pagination uses keys such as page[number] and page[size] where required by the service. 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.

Capacity, time and retained history

Providers have capacity1..1000 (default1), shared across overlapping appointments for all their service offerings. Generation creates distinct single-claim slot IDs; do not merge them by timestamp or use is_reserved updates to make/release bookings. operations.providerCapacityReportGet(providerId, {"page[number]":1,"page[size]":20}) returns a locked snapshot with capacity, current/future peak, observed time and paged legacy conflict windows. It does not reserve admission; booking checks capacity again.

Dates in availability/generation are strict UTC YYYY-MM-DD; appointment timestamps are RFC3339. Pagination uses bracketed keys and defaults1/20 with page size1..100. Invalid bounds/statuses/dates fail; generations are bounded, atomic and repeatable.

Cancellation uses DELETE but retains booking history and returns {status,message,data:null}. Repeated cancellation succeeds without releasing a newer booking of the same slot. Provider/service/slot deletion can return409 to protect claims or history. Unit-valued association/deletion receipts also carry data:null. Read the booking afterward when its updated state is needed. Public availability excludes legacy user-held slots.

Management calls require a trusted non-nil current user and organization header, plus the source's matching resource/action or accepted reservation manage grant. A role label alone does not authorize an action. Instances rely on their trusted single-project routing boundary; clients must not invent organization identity. Customer UUID existence and project membership require the canonical IDP lookup; these local SDK tests do not establish live gateway or cross-service identity binding.

版本与发布记录

@faiber/faiber-reservation 共发布 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-reservation 的常见问题

@faiber/faiber-reservation 是什么?

Bookable services, providers, provider-service assignments, work schedules, generated and available slots, and reservations.

如何安装 @faiber/faiber-reservation?

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

@faiber/faiber-reservation 支持 TypeScript 吗?

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

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

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

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

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

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

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

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

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