@crvouga/mockingbird-service-brevo

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

Stateful Brevo contact creation, external-id updates and email deletion emulator.

原始使用文档
文档目录6 节
  1. Install
  2. Usage
  3. Routes
  4. Controls and verification
  5. Deliberately not modelled
  6. API

@crvouga/mockingbird-service-brevo

Local emulators. Real API contracts. Part of Mockingbird.

WIP Brevo v3 contact lifecycle, based on the official contact reference. No messages are sent.

Install

bun add @crvouga/mockingbird-service-brevo

Usage

import { BrevoClient } from "@getbrevo/brevo"
import { createRuntime } from "@crvouga/mockingbird-service-brevo"

// The Brevo SDK your application already uses. Only its fetch changes: requests reach the
// emulator in this process instead of api.brevo.com.
const emulator = createRuntime()
const brevo = new BrevoClient({
  apiKey: "mock_brevo_key",
  fetch: ((url: RequestInfo | URL, init?: RequestInit) =>
    emulator.fetch(new Request(url, init))) as typeof fetch,
})

const created = await brevo.contacts.createContact({
  email: "[email protected]",
  ext_id: "mock-contact",
  listIds: [1],
  updateEnabled: false,
})
console.log(created) // { id: 1 }

Run mockingbird-brevo serve --port 12124 for a separate application process and set the SDK's baseUrl to http://localhost:12124/v3 (@getbrevo/brevo; a raw HTTP client replaces its https://api.brevo.com origin). The consumer must make that base URL injectable (the vendor does not define a standard environment variable). Use the synthetic api-key: mock_brevo_key, or configure apiKeys in createRuntime.

Routes

  • POST /v3/contacts: creates a contact with a numeric id (201). Duplicate email or external id with updateEnabled: false returns 400 duplicate_parameter without mutation. updateEnabled: true updates the existing contact (204).
  • PUT /v3/contacts/{identifier}?identifierType=ext_id: updates attributes, including attributes.EMAIL, without changing the contact's numeric id or existing list memberships (204). listIds adds memberships; unlinkListIds removes them.
  • DELETE /v3/contacts/{encoded-email}?identifierType=email_id: deletes that contact (204).
  • GET /v3/contacts/{identifier}: reads the contact. Explicit identifierType supports email_id, contact_id, and ext_id; the default recognizes an email or numeric id.

Missing contacts return 404 document_not_found. Invalid identifiers, malformed bodies, invalid emails and conflicting updates return 400; missing or invalid API keys return 401. Errors use {code, message}. There are no webhooks for this surface.

Controls and verification

Pass synthetic contacts to seed the emulator; reset restores those fixtures. Shared admin routes include /__admin/state/contacts for inspection/seeding, /__admin/reset, Timeline checkpoints, /__admin/clock, /__admin/requests and /__admin/faults. Requests are journaled as metadata, never contact bodies or API keys. Set adminPrefix to relocate this tree.

Namespace carriers are x-mockingbird-namespace, /__admin/ns/{namespace}, or API keys mapped through PUT /__admin/credentials. Each namespace has independent contacts and ids. Fault presets: unauthorized, rate_limited (429 with Retry-After), server_error (503), and connection_drop. Generic fault rules also support deterministic latency.

Acceptance tests exercise the raw-fetch requests from issue #280, namespace/reset behavior, faults and served HTTP. Property tests cover every operation and detect deliberate divergence. bun scripts/parity.ts needs BREVO_API_KEY and safely compares the missing-contact envelope; it does not create, update or delete real contacts. Live write parity has not been verified.

Deliberately not modelled

Email/SMS sending, campaigns, lists management, bulk import/export, SMS/WhatsApp identifiers, forceMerge, attribute-definition catalogs, contact statistics and account-level quotas. Only email and external-id creation are supported. No real customer fixtures or outbound events.

API

  • BrevoAPI: in-process FetchAPI with fetch, reset, contacts and counters collections.
  • BREVO_NAMESPACE: service name (brevo).
  • createRuntime: shared admin, namespace, clock, fault and journal surface; accepts apiKeys and contacts in addition to shared runtime options.
  • BREVO_PRESETS: named fault presets.
  • document, operationIds, supportedOperationIds: generated OpenAPI contract metadata.
  • createServer, serveTarget, DEFAULT_PORT from ./server: Node HTTP server and CLI target (default port 12124).

Public types include Contact, BrevoAPIOptions, OperationId and SupportedOperationId.

版本与发布记录

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

版本发布日期距今
1.11.0latest2026/11/11今天
1.10.92026/11/038 天前
1.10.82026/11/038 天前
1.10.72026/11/038 天前
1.10.62026/11/038 天前
1.10.52026/11/038 天前

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

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

Stateful Brevo contact creation, external-id updates and email deletion emulator.

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

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

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

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

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

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

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

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

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

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

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

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