@crvouga/mockingbird-service-s3

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

Stateful S3 emulator that answers exactly as MinIO does: every bucket, object, multipart, versioning, object-lock, policy and auth API, verified against recorded MinIO transcripts.

原始使用文档
文档目录9 节
  1. Install
  2. Usage
  3. Supported operations
  4. Authentication modes
  5. Where it departs from MinIO
  6. The oracle
  7. Admin and deterministic controls
  8. Deliberately not modelled
  9. API

@crvouga/mockingbird-service-s3

Local emulators. Real API contracts. Part of Mockingbird.

Stateful S3 emulator that answers exactly as MinIO does, so it drops in for MinIO, Amazon S3 and other S3-compatible storage in tests. Every behavior is pinned by a differential oracle: 370 scripted scenarios (about 3,800 HTTP exchanges) were recorded against MinIO RELEASE.2025-10-15T17-29-55Z, and bun test replays each one against the emulator and requires the same status, headers and XML byte for byte.

Install

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

ESM only. Node 22+ or Bun 1.2+.

Usage

Point the SDK endpoint at the emulator and enable path-style addressing. Fixture credentials are validated for presigned requests; the default pair is fixture / fixture.

import { CreateBucketCommand, GetObjectCommand, PutObjectCommand, S3Client } from "@aws-sdk/client-s3"
import { createServer } from "@crvouga/mockingbird-service-s3/server"

// Test setup: start the emulator and point the SDK's endpoint at it.
const server = await createServer()
const s3 = new S3Client({
  endpoint: server.url,
  region: "us-east-1",
  forcePathStyle: true,
  credentials: { accessKeyId: "fixture", secretAccessKey: "fixture" },
})

// Application code: the S3 SDK calls it already makes.
await s3.send(new CreateBucketCommand({ Bucket: "fixtures" }))
await s3.send(
  new PutObjectCommand({ Bucket: "fixtures", Key: "result.bin", Body: new Uint8Array([0, 255]) }),
)
const object = await s3.send(new GetObjectCommand({ Bucket: "fixtures", Key: "result.bin" }))
console.log(await object.Body?.transformToByteArray()) // Uint8Array(2) [ 0, 255 ]

await server.close()

Set an application's S3 endpoint environment variable to the server URL and its region to us-east-1.

Supported operations

Everything MinIO's S3 router serves, with MinIO's precedence, validation order, error codes and messages (generated from MinIO's own error table):

  • Buckets: CreateBucket (location constraint, object-lock flag), HeadBucket, DeleteBucket (incl. x-minio-force-delete), ListBuckets, GetBucketLocation, Get/PutBucketVersioning (incl. MinIO's excluded prefixes), Get/Put/DeleteBucketPolicy and GetBucketPolicyStatus, Get/Put/DeleteBucketTagging, Get/Put/DeleteBucketLifecycle, Get/Put/DeleteBucketEncryption, Get/PutBucketNotification, Get/Put/DeleteBucketReplication, Get/PutObjectLockConfiguration, the ACL, website, accelerate, request-payment and logging stubs, and MinIO's ListenNotification and replication extensions.
  • Objects: PutObject, GetObject, HeadObject (system and user metadata, conditional reads and writes, every Range form, partNumber, response-* overrides, checksums CRC32/CRC32C/CRC64NVME/SHA1/SHA256 with x-amz-checksum-mode), CopyObject (metadata and tagging directives, copy-source conditionals, versions), DeleteObject and DeleteObjects (delete markers, null versions), Get/Put/DeleteObjectTagging, Get/PutObjectRetention, Get/PutObjectLegalHold, Get/PutObjectAcl, GetObjectAttributes, RestoreObject, SelectObjectContent (CSV and JSON input, basic SQL, event-stream framing), and browser POST uploads (POST policy, V4 and V2 form signatures).
  • Listing: ListObjects V1, V2 and metadata=true, ListObjectVersions, including MinIO's marker and truncation behavior.
  • Multipart: Create, UploadPart, UploadPartCopy, Complete, Abort, ListParts, ListMultipartUploads, with part checksums and the <md5>-N ETag.
  • Authentication: SigV4 header and presigned, streaming aws-chunked (signed chunks and signed or unsigned trailers), SigV2 header and presigned, request-time skew, and anonymous access through bucket policies.

GetObjectLambda and PutObjectExtract (snowball auto-extract) answer NotImplemented.

Authentication modes

  • authentication: "lenient" (default): unsigned requests act as the bucket owner and header signatures are not checked, so plain fetch works in tests. Presigned URLs are still verified against credentials (default fixture / fixture).
  • authentication: "strict": MinIO's authentication exactly. Every request must be signed by a key in credentials, and an anonymous request is allowed only where the bucket policy grants it. The oracle runs in this mode.

region (default us-east-1) is the signing region and the x-amz-bucket-region header.

Where it departs from MinIO

  • Bucket CORS: MinIO only stubs the bucket CORS API, so the emulator keeps Amazon S3's documented behavior. The stored CORSConfiguration is enforced: a preflight is answered by the first matching rule or refused with 403 AccessForbidden, and matching actual requests get Access-Control-* headers. This is not oracle-verified.
  • Virtual-hosted-style addressing: Host: <bucket>.<base host> names the bucket (base hosts default to localhost; set virtualHosts, or --virtual-host a,b, empty for path-style only).
  • Body size: createServer accepts up to 5 GiB per PUT or part (S3's limit; MinIO's is 5 TiB). createServer({ maxBodyBytes }) lowers it.
  • Listings always read live data, where MinIO serves later pages from a snapshot taken on the first page.

The oracle

oracle/ in the repository holds the harness, the scenarios and the recorded MinIO transcripts. bun oracle/run.ts replays them against a live MinIO, --record refreshes the transcripts; see oracle/README.md.

Admin and deterministic controls

  • GET/POST /__admin/objects inspects metadata or seeds an object; GET /__admin/objects/:bucket/:key downloads its bytes.
  • GET /__admin/uploads inspects active uploads and part metadata.
  • Preset faults are slow_down, access_denied, expired_token, and one-shot truncate_stream. Generic faults can fail or reset the next part request.
  • Advance the shared emulator clock through /__admin/clock to expire a presigned URL.
  • Object writes, copies, multipart completion, and deletes publish S3-shaped notifications. Configure HTTP sinks through runtime webhooks options or the shared webhook admin routes; delivery attempts and retries appear under /__admin/webhooks.

The shared runtime also provides health, reset, journal, metrics, timeline, and fault routes. Select isolated state with x-mockingbird-namespace, /__admin/ns/<name>, or a SigV4 access-key mapping.

Deliberately not modelled

SSE-C and SSE-KMS encryption (MinIO needs TLS and a KMS for them), IAM users and policies other than the root credentials and bucket policies, actually applying lifecycle rules or replicating, and real SQS delivery. SQS consumers can use the captured notification payload through a configured HTTP sink.

API

  • S3API, S3APIOptions: Fetch handler and configuration.
  • S3Notification, S3Object (ObjectVersion), S3SeedObject, BucketRecord, MultipartUpload, MultipartPart: notification, state, and fixture types.
  • createRuntime, S3Runtime, S3RuntimeOptions: full Mockingbird runtime and webhook hub.
  • S3_NAMESPACE, S3_PRESETS, accessKeyCredential: constants and fault controls.
  • S3_MAX_UPLOAD_BYTES: the default request body limit (5 GiB) for createServer.
  • document, operationIds, supportedOperationIds: generated OpenAPI metadata.
  • createServer, S3ServerOptions, DEFAULT_PORT, serveTarget from ./server: Node HTTP adapter and CLI integration.

Oracle: MinIO RELEASE.2025-10-15T17-29-55Z, with the Amazon S3 API Reference for bucket CORS.

版本与发布记录

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

版本发布日期距今
4.1.0latest2026/11/11今天
4.0.82026/11/064 天前
4.0.72026/11/065 天前
4.0.62026/11/038 天前
4.0.52026/11/038 天前
4.0.42026/11/038 天前

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

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

Stateful S3 emulator that answers exactly as MinIO does: every bucket, object, multipart, versioning, object-lock, policy and auth API, verified against recorded MinIO transcripts.

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

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

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

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

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

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

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

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

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

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

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

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