@bondsports/online-booking

中文文档
1.0.0发布于 2026/06/08TypeScriptCommonJS近 30 天下载 3553

Bond Sports online booking package

原始使用文档
文档目录7 节
  1. Installation
  2. Usage
  3. resolveBookingSettings
  4. validateBookingSlots
  5. Error handling
  6. API
  7. Scripts

@bondsports/online-booking

Validation and settings-resolution utilities for online booking flows.

The package answers two questions:

  1. What booking settings apply to this user right now? — resolveBookingSettings merges the default product-category settings with the most favorable overrides from the user's active memberships.
  2. Are the slots the user wants to book actually allowed? — validateBookingSlots checks the requested slots (combined with the user's already-booked slots) against the resolved settings and returns a typed validation result.

Installation

npm install @bondsports/online-booking

Usage

resolveBookingSettings

Pick the effective IBookingSettings for a user. If the user has no active memberships (or none of them override the category settings), the default is returned. Otherwise the lowest minimumBookingNotice and the highest advanceBookingWindow across matching membership overrides win.

import { resolveBookingSettings } from '@bondsports/online-booking';

const settings = resolveBookingSettings(productCategory.onlineBookingSettings, user.activeMemberships);
  • productCategory.onlineBookingSettings — TProductCategoryOnlineBookingSettings ({ default, memberships })
  • user.activeMemberships — { membershipId: number }[] (optional; pass undefined or [] for guests)

validateBookingSlots

Validate a list of requested time slots against the resolved settings.

import { validateBookingSlots } from '@bondsports/online-booking';

const result = validateBookingSlots(requestedSlots, userBookedSlots, settings, facilityTimezone);

if (!result.success) {
    // result.error is a ValidationError with a stable `code` (see ONLINE_BOOKING_ERRORS)
    throw result.error;
}

The validator:

  • merges requested slots with the user's existing bookings (clamped to the booking window),
  • enforces maxBookingHours per calendar day (in the facility timezone),
  • enforces maxSequentialBookings on each continuous block,
  • enforces minimumBookingNotice and advanceBookingWindow against "now".

Error handling

All failures return { success: false, error } where error is a ValidationError subclass carrying a stable code from ONLINE_BOOKING_ERRORS:

Error classCodeMeaning
InvalidTimesErrorINVALID_TIMESStart date is not strictly before end date
MinimumNoticeErrorMINIMUM_NOTICE_DATEStart date is before now + minimumBookingNotice
AdvanceBookingErrorADVANCE_BOOKING_DATEStart date extends beyond now + advanceBookingWindow
MaxSequentialHoursErrorMAX_SEQUENTIAL_HOURSA contiguous block exceeds maxSequentialBookings
MaxBookingHoursErrorMAX_BOOKING_HOURSTotal booked duration on a day exceeds maxBookingHours
import { ONLINE_BOOKING_ERRORS, ValidationError } from '@bondsports/online-booking';

if (!result.success && result.error.code === ONLINE_BOOKING_ERRORS.MINIMUM_NOTICE_DATE) {
    // show "book at least N hours in advance" message
}

API

import {
    validateBookingSlots,
    resolveBookingSettings,
    ONLINE_BOOKING_ERRORS,
    ValidationError,
    InvalidTimesError,
    MinimumNoticeError,
    AdvanceBookingError,
    MaxSequentialHoursError,
    MaxBookingHoursError,
    IBookingValidation,
    IBookingSettings,
    IMembershipBookingSettings,
    TProductCategoryOnlineBookingSettings,
} from '@bondsports/online-booking';

Scripts

npm run build      # compile to ./dist
npm test           # run jest
npm run lint       # eslint + prettier check
npm run lint:fix   # autofix

版本与发布记录

@bondsports/online-booking 共发布 6 个版本,首次发布于 2026/05/10;过去 12 个月发布了 6 个版本。

版本发布日期距今
1.0.0latest2026/06/085 个月前
0.0.2-beta-1squad-c2026/05/205 个月前
0.0.2-beta2026/05/195 个月前
0.0.22026/05/185 个月前
0.0.1-beta2026/05/125 个月前
0.0.12026/05/105 个月前

关于 @bondsports/online-booking 的常见问题

@bondsports/online-booking 是什么?

Bond Sports online booking package

如何安装 @bondsports/online-booking?

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

@bondsports/online-booking 支持 TypeScript 吗?

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

@bondsports/online-booking 支持 ESM 还是 CommonJS?

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

@bondsports/online-booking 可以商用吗?

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

@bondsports/online-booking 的下载量有多少?

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

@bondsports/online-booking 还在维护吗?

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