@crvouga/mockingbird-service-wholescripts

中文文档
3.10.4发布于 2026/11/03MITTypeScriptES Module构建来源已验证近 30 天下载 1.5万

Stateful emulator of the Wholescripts supplement fulfilment API: product and private-label catalogs, order submit, status polling and cancel, with admin status transitions.

原始使用文档
文档目录8 节
  1. Install
  2. Usage
  3. Routes
  4. Admin (beyond the standard contract)
  5. Namespaces
  6. Corpus and seed data
  7. Deliberately not modelled
  8. API

@crvouga/mockingbird-service-wholescripts

Local emulators. Real API contracts. Part of Mockingbird.

Stateful emulator of the Wholescripts supplement fulfilment API for test suites: the product catalog, the private-label (MedPax) catalog, order submit, status polling and cancel. Orders move only when a test says so (an admin transition or an auto-advance path on the emulator clock). Wholescripts sends no webhooks, so the app sees each change on its next status poll.

  • Operation coverage: SUPPORT.md
  • The vendor publishes no spec. The contract (openapi.yaml) is hand-authored from our consumers' zod schemas (backend and EMR wholescripts.types.ts) and the supplement scheduler's Python client.

Install

npm install -D @crvouga/mockingbird-service-wholescripts

ESM only. Node >= 22 or Bun >= 1.2. No native dependencies. Serve it with npx mockingbird-wholescripts serve, createServer from ./server (Node), or createRuntime with any Fetch server.

Usage

Point WHOLESCRIPTS_API_URL at the emulator. It is read by the backend (global-services/services/wholescripts), the EMR (services/wholescripts) and the supplement scheduler (supplement_management). Any non-empty WHOLESCRIPTS_USERNAME / WHOLESCRIPTS_PASSWORD pair is accepted unless you pin one with --username/--password.

npx mockingbird-wholescripts serve --port 8803 --auto-advance "2000:Processing,Complete"
import { createServer } from "@crvouga/mockingbird-service-wholescripts/server"

// Test setup: a local Wholescripts.
const server = await createServer()
const baseUrl = server.url // the app's WHOLESCRIPTS_API_URL

// Application code: the order it submits to Wholescripts.
const headers = { authorization: `Basic ${btoa("acme:secret")}`, "content-type": "application/json" }
const response = await fetch(`${baseUrl}/api/Orders/Submit`, {
  method: "POST",
  headers,
  body: JSON.stringify({
    ShippingAddress: { FName: "Ada", LName: "L", Address1: "1 Main St", City: "Phoenix", State: "AZ", Zip: "85004" },
    Items: [{ Sku: "SKU001", Quantity: 1 }],
    ShippingMethod: "Ground",
  }),
})
const submitted = (await response.json()) as { orderNumber: string }

// Test control: ship it the way the vendor would.
await fetch(`${baseUrl}/__admin/orders/${submitted.orderNumber}/transition`, {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({ to: "Complete", trackingNumber: "1Z999", carrier: "UPS" }),
})

// Application code: its next status poll sees the shipment.
await fetch(`${baseUrl}/api/Orders/Status?ordernum=${submitted.orderNumber}`, { headers })

await server.close()

Routes

RouteBehaviour
GET /api/Orders/PrivateLabelProductList{privateLabelProducts: [], medPaxPills: [{sku, genericName, privateLabelName, quantity}], privateLabelCartons: [{sku, name, cartonImage, quantity}]}.
GET /api/Orders/ProductListProduct rows (productName, sku, medPaxSku, categories, prices, quantity, defaultDosing, optional medPaxDetails). instockonly=true keeps quantity > 0 (the EMR), search matches name/SKU/brand/categories (the supplement scheduler), limit caps.
POST /api/Orders/Submit{ShippingAddress, Notes?, Items: [{Sku, Quantity, MedPaxName?, MedPaxPills?: [{Sku, Quantity, ItemTime}]}], ShippingMethod} → {orderNumber, success: true, msg}. A contract violation or an unknown SKU (product, MedPax, pill or carton SKU) is still 200 with success: false and the reason in msg, which is what both consumers read.
GET /api/Orders/Status?ordernum=[{orderNumber, orderDate, salesOrder, status, tracking: [{trackingNumber, carrier, trackingUrl}], message, subTotal, shipMethod, shipCharge, discount, tax, serviceFee, orderTotal}]; [] for an unknown order. Totals are priced from the catalog (MedPax SKUs at their medPaxDetails price) plus 9.95 shipping (0 for "free" methods).
POST /api/Orders/Cancel{OrderNumber} → {success, msg}. Succeeds while Pending/Processing with no tracking; otherwise success: false. Unknown order: 404.

Missing or wrong Basic credentials answer 401 {"Message": "Authorization has been denied for this request."}.

Statuses are Pending (new), Processing, Complete, Cancelled, Error, or any string a test sets. How our consumers read them: the scheduler maps Pending/Processing to placed (or shipped once tracking exists), Complete to shipped (carrier hand-off, not delivery), anything containing cancel/error to cancelled/failed, and everything else to unknown. The backend and EMR do not map statuses.

Admin (beyond the standard contract)

RouteEffect
POST /__admin/orders/:orderNumber/transition{to, trackingNumber?, carrier?, trackingUrl?, message?}. A tracking number is appended to tracking; Complete without one generates a UPS number. Processing/Complete set salesOrder.
GET /__admin/ordersThe namespace's orders (SKUs and quantities only).
GET/PUT /__admin/catalogRead or replace {products, medPaxPills, privateLabelCartons} for the namespace.
GET/PUT /__admin/settings{accounts?: [{username, password}], autoAdvance?: {afterMs, path} | null}.
POST /__admin/tickApply every auto-advance step that is due on the emulator clock (the served emulator ticks every 100 ms).

Fault presets (POST /__admin/faults {"preset": "<name>", "count"?: n}; GET /__admin/faults/presets): submit_rejected (200 success: false), submit_timeout (the order is placed, then the connection drops: the scheduler's "order may have been placed" branch), status_empty ([]), status_schema_drift (rows the backend's zod rejects, so it returns null), server_error (500, which the scheduler retries), unauthorized (401).

Namespaces

x-mockingbird-namespace, a /__admin/ns/<name> prefix on WHOLESCRIPTS_API_URL, or by Basic username: PUT /__admin/credentials {"credentials": {"<WHOLESCRIPTS_USERNAME>": "<namespace>"}}.

Corpus and seed data

The default catalog is the rows our consumers' own tests use (the consumer app's wholescripts-service.test.ts), with their repeated medPaxSkus made unique, plus the scheduler's MedPax box 000000000200095263 and medPaxDetails rows the scheduler's catalog sync reads. Protein Powder (PP001) is out of stock. No sandbox recording exists; load recorded rows with serve --catalog <file>, the catalog option, or PUT /__admin/catalog.

serve --catalog rows.json lays a JSON file onto the default catalog for every namespace, and a reset returns to it (unlike PUT /__admin/catalog, which replaces the catalog until the next reset). The file is {products?, medPaxPills?, privateLabelCartons?}, or a bare array of products. A row needs its sku (and a product its productName); every other string defaults to "" and every number to 0, so give quantity for a product that should survive instockonly=true. By default (--catalog-mode merge) a row whose SKU the default already has replaces it in place, any other is appended, and a list the file leaves out is kept. --catalog-mode replace makes the file the whole catalog (a list it leaves out is empty). In a fleet, set options: {"catalog": "rows.json", "catalog-mode": "replace"}. The catalog option of createRuntime still takes a whole Catalog.

Deliberately not modelled

  • Webhooks: Wholescripts has none; status is polled.
  • Real fulfilment timing, partial shipments and returns: nothing moves unless a test or autoAdvance moves it.
  • Shipping address and recipient are validated but never stored or echoed back (PHI).
  • Real tax, discounts, service fees and carrier rates: tax/discount/fee are 0, shipping is flat.
  • Payment authorization: a failed payment is only reachable through submit_rejected or an Error transition.

API

ExportKindDescription
WholescriptsAPIclassThe in-process emulator: fetch(request), reset(), transition(orderNumber, {to, …}), tick(), orders(). Options: sqlite, now, namespace, catalog, settings.
createRuntimefunctionThe emulator with the full service contract (health, admin, namespaces, credentials, presets). Options: catalog, settings, tickMs, clock, seed, adminKey, onLog.
WHOLESCRIPTS_PRESETSobjectEvery named fault preset.
WHOLESCRIPTS_NAMESPACEstringThe service name, "wholescripts".
basicUsernamefunctionThe Basic username a request carries (how credentials map to namespaces).
canonicalStatusfunctionThe canonical casing of a transition target (complete → Complete).
DEFAULT_CATALOGobjectThe default {products, medPaxPills, privateLabelCartons}.
parseCatalogDocument, mergeCatalogfunctionsCheck a --catalog document (filling omitted fields) and lay it onto a catalog by SKU.
MEDPAX_BOX_SKUstringThe supplement scheduler's MedPax box SKU, 000000000200095263.
document, operationIds, supportedOperationIdsvaluesThe vendored OpenAPI contract and its operation ids.
createServer, serveTarget, DEFAULT_PORT (./server)NodeServe over node:http (auto-advance ticks every 100 ms); the serve CLI target; port 8803.

Part of mockingbird.

版本与发布记录

@crvouga/mockingbird-service-wholescripts 共发布 37 个版本,首次发布于 2026/09/23;过去 12 个月发布了 37 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.10.4latest2026/11/038 天前
3.10.32026/11/038 天前
3.10.22026/11/038 天前
3.10.12026/11/038 天前
3.10.02026/10/2417 天前
3.9.02026/10/2220 天前

关于 @crvouga/mockingbird-service-wholescripts 的常见问题

@crvouga/mockingbird-service-wholescripts 是什么?

Stateful emulator of the Wholescripts supplement fulfilment API: product and private-label catalogs, order submit, status polling and cancel, with admin status transitions.

如何安装 @crvouga/mockingbird-service-wholescripts?

在项目目录运行 npm install @crvouga/mockingbird-service-wholescripts,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 mockingbird-wholescripts,可以用 npx mockingbird-wholescripts 直接运行。

@crvouga/mockingbird-service-wholescripts 支持 TypeScript 吗?

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

@crvouga/mockingbird-service-wholescripts 支持 ESM 还是 CommonJS?

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

@crvouga/mockingbird-service-wholescripts 可以商用吗?

@crvouga/mockingbird-service-wholescripts 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@crvouga/mockingbird-service-wholescripts 的下载量有多少?

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

@crvouga/mockingbird-service-wholescripts 还在维护吗?

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