@crvouga/mockingbird-service-fullscript

中文文档
3.11.0发布于 2026/11/11MITTypeScriptES Module构建来源已验证近 30 天下载 3190

Stateful emulator of the Fullscript lab-ordering API: per-practitioner OAuth, clinic, session grants, forward-only lab orders with results, lab-order events, expiring result PDFs, and Fullscript-Signature webhooks.

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

@crvouga/mockingbird-service-fullscript

Local emulators. Real API contracts. Part of Mockingbird.

Stateful emulator of the Fullscript lab-ordering API for test suites: per-practitioner OAuth (consent redirect, authorization_code and rotating refresh_token grants, revoke), the clinic, embeddable session grants, lab orders with tests and results, lab-order events, expiring result PDFs, and Fullscript-Signature webhooks with the challenge acknowledgement our receiver implements. Lab orders move forward only, through exactly Fullscript's states, when a test says so.

  • Operation coverage: SUPPORT.md
  • The contract (openapi.yaml) is hand-authored from the EMR consumer (fullscript-api-client.ts, fullscript-event-model.ts, fullscript-webhook-signature.ts, routers/v1/fullscript/webhook-controller.ts, fullscript-result-storage.ts).

Install

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

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

Usage

With FEATURE_FULLSCRIPT_LABS_ENABLED=true, point FULLSCRIPT_API_URL at the emulator and FULLSCRIPT_OAUTH_AUTHORIZE_URL at its /oauth/authorize; set FULLSCRIPT_WEBHOOK_SECRET and FULLSCRIPT_WEBHOOK_CHALLENGE_KEY and pass the same values as --webhook-secret / --webhook-challenge. The EMR validates these URLs as https and downloads result PDFs only over https from allowlisted hosts (by default fullscript.com, fullscript.io and FULLSCRIPT_API_URL's host, which is where the emulator serves them), so front the emulator with TLS or set --results-base-url.

npx mockingbird-fullscript serve --port 8819 \
  --webhook-url http://127.0.0.1:4000/v1/fullscript/webhooks \
  --webhook-secret "$FULLSCRIPT_WEBHOOK_SECRET" --webhook-challenge "$FULLSCRIPT_WEBHOOK_CHALLENGE_KEY"
import { createServer } from "@crvouga/mockingbird-service-fullscript/server"

// Test setup: the emulator, a lab order moved to results, and the code an OAuth redirect delivers.
const server = await createServer({
  webhooks: { url: "http://127.0.0.1:4000/v1/fullscript/webhooks", secret: "whsec", challenge: "chal" },
})
const admin = (path: string, body: unknown) =>
  fetch(`${server.url}/__admin${path}`, {
    method: "POST",
    headers: { "content-type": "application/json" },
    body: JSON.stringify(body),
  })
const order = (await (await admin("/lab-orders", { patientId: "fs_pat_1", treatmentPlanId: "tp_1" })).json()) as { id: string }
await admin(`/lab-orders/${order.id}/transition`, { to: "purchased" }) // order.placed + lab_order.updated
await admin(`/lab-orders/${order.id}/transition`, { to: "results_ready" }) // results + PDF URLs
const { code } = (await (await admin("/oauth/codes", { clientId: "emr-client" })).json()) as { code: string }

// Application code: FULLSCRIPT_API_URL is server.url. Exchange the code, then read the order.
const apiUrl = server.url
const token = await fetch(`${apiUrl}/api/oauth/token`, {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({
    grant_type: "authorization_code",
    client_id: "emr-client",
    client_secret: "emr-secret",
    code,
  }),
})
const { oauth } = (await token.json()) as { oauth: { access_token: string } }
const read = await fetch(`${apiUrl}/api/clinic/labs/orders/${order.id}`, {
  headers: { authorization: `Bearer ${oauth.access_token}` },
})
const { order: labOrder } = (await read.json()) as { order: { state: string } }
// labOrder.state is "results_ready"; labOrder.results[].pdf_url are served by the emulator.
await server.close()

Routes

RouteBehaviour
GET /oauth/authorizeAuto-consents as practitioner_id (default prac_mock_1) and redirects to redirect_uri?code=…&state=….
POST /api/oauth/tokenJSON {grant_type, client_id, client_secret, code | refresh_token, redirect_uri} → {oauth: {access_token, token_type: "Bearer", expires_in: 7200, refresh_token, scope, created_at, resource_owner: {id, type, clinic_id}}}. Codes are single-use, expire in 10 minutes and must match the redirect URI; refresh tokens rotate (a spent one is invalid_grant). Errors: 400 {error: "invalid_grant" | "invalid_request"}, 401 invalid_client.
POST /api/oauth/revoke{client_id, client_secret, token} → 200 {}; the token stops working.
GET /api/clinic{clinic: {id, name}} of the token's practitioner.
POST /api/clinic/embeddable/session_grants201 {secret_token, expires_at}.
GET /api/clinic/labs/orders?patient_id=&page[number]=&page[size]= → {orders: [{id, state, treatment_plan_id, …}], meta: {current_page, next_page, …}}.
GET /api/clinic/labs/orders/{id}{order: {…, collection_method, tests, results: [{id, name, state, pdf_url}], latest_aggregated_result: {id, artifact_id, pdf_url, status}}}.
GET /api/events/lab_orders?order_by=DESC|ASC&page[number]=&page[size]= → the clinic's lab_order.updated events.
GET /api/events/{id}{event: {id, type, clinic_id, created_at, data}}.
GET /results/{artifact}?expires&signatureThe result PDF (application/pdf, a real one-page PDF) until the URL expires (15 minutes), then 403.

API errors are {errors: [{code, message}]} (401 unauthorized / invalid_token / token_expired, 404 not_found); our client reads the code.

States (forward only, jumps allowed): not_purchased → purchased → schedule_appointment → upcoming_appointment → processing → partial_results (first test's result) → results_ready (every result + an aggregated result) → interpretation_shared → results_amended (a new aggregated artifact).

Webhooks

Each move emits lab_order.updated (data.lab_order: {id, state, treatment_plan_id, patient_id}), and the move out of not_purchased also emits order.placed (data: {id, treatment_plan_ids, patient_id, line_items: [{type: "labs"}]}). Deliveries post {event_payload: {event}} with Fullscript-Signature: t=<unix>,v1=<hex HMAC-SHA256(secret, "<t>." + body)> (wall-clock t). With a challenge key, a delivery counts only when the receiver answers {challenge: <key>} (otherwise it is recorded as 502 and retried). POST /__admin/webhooks/verify sends Fullscript's empty-body registration ping and reports whether each endpoint echoed the challenge. GET /__admin/webhooks, …/events, …/replay, …/flush as usual.

Admin (beyond the standard contract)

RouteEffect
POST /__admin/lab-orders{patientId, id?, clinicId?, treatmentPlanId?, name?, collectionMethod?, tests?: [names]} → a not_purchased order.
POST /__admin/lab-orders/:id/transition{to: <state>}; backwards or same-state is 409.
GET /__admin/lab-orders, GET /__admin/eventsThe namespace's orders and events.
POST /__admin/oauth/codes{practitionerId?, clientId?, redirectUri?} → {code} without the browser redirect.
POST /__admin/practitioners{id, clinicId, type?, clinicName?}.
POST /__admin/webhooks/verifyThe registration ping (see Webhooks).
GET/PUT /__admin/settings{clients?, accessTokenTtlSeconds?, codeTtlSeconds?, pdfUrlTtlSeconds?, resultsBaseUrl?}.

Fault presets (POST /__admin/faults {"preset": "<name>", "count"?: n}): token_expired, invalid_grant, rate_limited, server_error, events_schema_drift, pdf_not_pdf, pdf_redirect, pdf_expired, connection_drop, slow, webhook_duplicate, webhook_reorder, webhook_drop.

Namespaces

A /__admin/ns/<name>/ suffix on FULLSCRIPT_API_URL (our client resolves relative api/… paths, so the prefix survives, and PDF URLs keep it), x-mockingbird-namespace, or by OAuth client for API calls (PUT /__admin/credentials {"credentials": {"<FULLSCRIPT_CLIENT_ID>": "<ns>"}}; tokens carry the client they were issued to). Token requests carry the client only in their body, so they need the prefix or the header.

Deliberately not modelled

  • Catalog, treatment plans, patients, dispensary orders and every non-lab endpoint; the embedded widget itself (session grants are opaque tokens).
  • Lab result values (only PDFs), requisitions and appointment booking.
  • Real consent screens: /oauth/authorize approves immediately.

API

ExportKindDescription
FullscriptAPIclassThe in-process emulator: fetch(request), reset(), issueCode(practitionerId, clientId, redirectUri), createOrder(input), transition(orderId, state), seedOrder(seed), labOrders(), eventsList(). Options: sqlite, now, namespace, publicNamespace, settings, orders, onEvent.
createRuntimefunctionThe emulator with the full service contract (health, admin, namespaces, credentials, presets, webhooks). Options: webhooks: {url, secret, challenge?, retryDelaysMs?, fetch?}, settings, orders, clock, seed, adminKey, onLog, sqlite.
FULLSCRIPT_PRESETSobjectEvery named fault preset.
FULLSCRIPT_NAMESPACEstringThe service name, "fullscript".
SIGNATURE_HEADERstringFullscript-Signature.
LAB_ORDER_STATES, isLabOrderStatevaluesThe forward-only state order.
DEFAULT_CLINIC, DEFAULT_PRACTITIONERobjectsThe seeded clinic and practitioner.
RESULT_PDFbytesThe PDF every result URL serves.
issueAccessTokenfunctionMint a self-verifying access token (for tests and parity).
tokenCredentialfunctionThe OAuth client a bearer token was issued to (how credentials map to namespaces).
envelope, publicEventfunctionsAn event's webhook body and API shape.
apiErrors, oauthErrorfunctionsBuild Fullscript's API and OAuth error responses.
document, operationIds, supportedOperationIdsvaluesThe OpenAPI contract and its operation ids.
createServer, serveTarget, DEFAULT_PORT (./server)NodeServe over node:http; the serve CLI target (--webhook-url, --webhook-secret, --webhook-challenge, --client, --results-base-url); port 8819.

Part of mockingbird.

版本与发布记录

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

版本发布日期距今
3.11.0latest2026/11/11今天
3.10.92026/11/037 天前
3.10.82026/11/038 天前
3.10.72026/11/038 天前
3.10.62026/11/038 天前
3.10.52026/11/038 天前

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

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

Stateful emulator of the Fullscript lab-ordering API: per-practitioner OAuth, clinic, session grants, forward-only lab orders with results, lab-order events, expiring result PDFs, and Fullscript-Signature webhooks.

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

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

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

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

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

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

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

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

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

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

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

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