@crvouga/mockingbird-service-vercel-blob

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

Stateful Vercel Blob emulator: binary uploads, public downloads, metadata, cursor listing and multipart commits.

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

@crvouga/mockingbird-service-vercel-blob

Local emulators. Real API contracts. Part of Mockingbird.

A wip portable Vercel Blob emulator verified with the unmodified @vercel/blob 2.8.0 SDK. Blobs, multipart uploads, pending parts and synthetic download grants use SQLite Collections, the shared clock, namespaces and Timeline. Fixtures contain synthetic data only.

Install

bun add @crvouga/mockingbird-service-vercel-blob

Usage

The example uses @vercel/[email protected]. It is an optional consumer dependency, not a runtime dependency of the emulator.

import { del, put } from "@vercel/blob"
import { createServer } from "@crvouga/mockingbird-service-vercel-blob/server"
import { DEFAULT_TOKEN } from "@crvouga/mockingbird-service-vercel-blob"

// Test setup: the emulator, and the two variables the Blob SDK reads.
const server = await createServer()
process.env.VERCEL_BLOB_API_URL = `${server.url}/api/blob`
process.env.BLOB_READ_WRITE_TOKEN = DEFAULT_TOKEN

// The app's own Blob calls, unchanged.
const blob = await put("fixture.txt", "fixture bytes", { access: "public", addRandomSuffix: false })
console.log(await (await fetch(blob.url)).text()) // "fixture bytes"
await del(blob.url)
await server.close()

The SDK's supported endpoint override is VERCEL_BLOB_API_URL (or NEXT_PUBLIC_VERCEL_BLOB_API_URL). An application's BLOB_STORE_BASE_URL must be mapped to that SDK override by the application. For namespace suite, use ${server.url}/__admin/ns/suite/api/blob, an x-mockingbird-namespace: suite header, or register the fixture token with PUT /__admin/credentials. Every namespace starts empty unless fixtures: [{ pathname, bytes: string | number[], contentType?, cacheControlMaxAge?, storeId? }] is supplied. tokens maps synthetic Bearer tokens to store IDs; the default DEFAULT_TOKEN (vercel_blob_rw_fixture_fixture) maps to fixture. Invalid or missing tokens return vendor 403 { error: { code: "forbidden", message: "Access denied" } }.

The SDK accepts strings, Buffer, Blob and streams. Its multipart helper does not accept a raw Uint8Array as a typed PutBody; wrap it in a Blob or Buffer. The emulator's HTTP upload handler preserves raw Uint8Array request bodies as well as strings and arbitrary binary bytes.

Routes and behavior

OperationSDK wire endpointBehavior
PutBlobPUT /api/blob/?pathname=…Raw bytes; public access, content type, cache TTL, optional random suffix, overwrite and ETag preconditions
ReadBlobStoreGET /api/blob?url=…head() metadata, size, ETag and upload timestamp
ReadBlobStoreGET /api/blob?prefix=…&limit=…&cursor=…&mode=…list() with lexical pathname ordering and expanded/folded folders
CopyBlobPUT /api/blob?pathname=…&fromUrl=…Same-store copy; destination content type inferred independently unless supplied
DeleteBlobsPOST /api/blob/delete{ urls: [...] }; accepts own returned URL or pathname; missing blobs are ignored
MultipartUploadPOST /api/blob/mpu?pathname=…x-mpu-action: create/upload/complete, SDK key/upload-ID/part-number headers
DownloadBlob / HeadDownloadGET /__admin/blobs/{id} / HEADSynthetic public byte transport; exact bytes, ETag, Content-Length/Type, cache and download disposition

put() and copy() return { pathname, url, downloadUrl, contentType, contentDisposition, etag }. The upload reply does not contain size; head() and list metadata contain it. A duplicate pathname without overwrite returns vendor 400 bad_request and leaves the existing bytes intact. Overwrite replaces the object atomically and preserves its URL. Conditional writes/deletes use x-if-match and return 412 precondition_failed on a stale ETag; copy checks its source ETag. Deletes validate all preconditions before any removal. No vendor request-ID deduplication is invented: normal duplicate-path rules apply to repeated puts. ETags use SHA-256, as in Vercel's published emulator; timestamps use the injected clock. Default cache TTL is 2,592,000 seconds.

Pagination defaults to 1,000 objects, sorts by pathname (so file10 precedes file2) and emits hasMore plus a cursor only when another page exists. Emulator cursors use the last pathname, following Vercel's emulator; their encoding is not a claim about production's opaque cursor format. Folded mode returns immediate folders separately from blob entries.

Multipart staging never publishes a partial object. Re-uploading a part number replaces that pending part. Completion verifies part ETags, ascending unique numbers, total size, and the documented minimum 5 MiB/equal sizes for all parts except the last, then publishes atomically. An identical completion replay returns the existing upload result. maxBlobBytes defaults to 20 MiB and can be configured: this is an explicit local resource bound, not a production quota.

Public URLs use the configured publicOrigin or the origin of the upload request. They contain an explicit namespace query and point inside the reserved internal byte transport tree. They work through plain fetch over the served listener or in-process emulator.fetch. With a custom adminPrefix, the byte URLs and every control route relocate together. A Timeline branch caller must also forward x-mockingbird-branch when fetching its public URL. Conditional public reads support If-None-Match / 304. This local URL transport is a stand-in, not a Vercel CDN hostname. The SDK's get() validates the production hostname, so use plain fetch for local downloads.

Controls and failures

All service controls live beside the shared /__admin/health, /__admin/state, /__admin/clock, /__admin/reset, /__admin/requests, fault engine and Timeline controls. adminKey uses the shared x-mockingbird-admin-key guard when configured. The journal records metadata and touched IDs, never upload bodies.

ControlPurpose
GET /__admin/store/blobsBlob metadata, excluding bytes
POST /__admin/store/blobsSeed { pathname, bytes: string | number[], contentType?, cacheControlMaxAge?, storeId? }
GET /__admin/store/blobs/:id/bytesExplicit fixture byte read
GET /__admin/store/uploadsPending/completed upload and part metadata, excluding bytes
POST /__admin/store/originSet { origin } for subsequent uploads and fixture seeds
POST /__admin/store/downloadsCreate a synthetic { blobId, expiresInMs } download grant
POST /__admin/store/downloads/:id/expireExpire a grant immediately

Synthetic grant URLs expire on the shared clock and return 403 after expiry; ordinary public URLs remain public. These controls do not model a production signing protocol. Presets: conflict, rate_limited (429 / Retry-After), truncated_upload, partial_multipart, server_error and network_reset. Each fires once. Activate partial_multipart after creating an upload and before sending the part to fail; earlier parts remain available for retry.

API

The portable root exports VercelBlobAPI, createRuntime, document, supportedOperationIds, VERCEL_BLOB_NAMESPACE, VERCEL_BLOB_PRESETS, DEFAULT_TOKEN, DEFAULT_STORE_ID and DEFAULT_CACHE_MAX_AGE, plus the fixture/record/upload/grant/runtime option types. VercelBlobAPI exposes fetch, reset, state, metadata, seed, ensureSeeded, app and sqlite. createRuntime adds the shared MockSurface clock, fault engine, journal, credential registry, state, namespaces and Timeline controls. The Node ./server entry exports createServer, DEFAULT_PORT (8812), serveTarget and server types; mockingbird-vercel-blob serve starts a listener.

Oracle and verification

The contract follows Vercel's SDK documentation, the published official SDK 2.8.0, and Vercel's official emulator Blob routes at e4cd051. The emulator supplies wire/error/list evidence; it explicitly does not implement multipart, which is verified here with the real SDK and the SDK documentation's multipart rules.

bun test runs SDK, binary acceptance, all parity-enabled JSON operation walks, a divergent instance check, namespace/reset/clock/Timeline and catalog preset tests. The served SDK tests run put → public GET → overwrite → del and manual/automatic multipart against this package, without modifying the SDK or contacting Vercel. Two-part acceptance verifies that failed parts leave earlier parts intact and that only validated completion makes the object visible. bun run parity is cold and read-only: VERCEL_BLOB_API_URL and VERCEL_BLOB_READ_WRITE_TOKEN must name an empty test store. Missing credentials or a nonempty/inaccessible store exit 2, never a passing live result.

Deliberately not modelled

Private stores and their authorization, client upload token signing, production CDN/domain routing, SDK get() production-host validation bypass, range requests, image optimization, provider quotas, cross-store copies, real billing and dashboards, production opaque cursor encoding and undocumented request-ID deduplication are not modelled. Grants are synthetic clock controls. This package never contacts Vercel during normal operation; only the explicit credentialed, read-only parity command does so.

版本与发布记录

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

版本发布日期距今
1.12.0latest2026/11/131 天前
1.11.12026/11/122 天前
1.11.02026/11/122 天前
1.10.02026/11/113 天前
1.9.42026/11/0311 天前
1.9.32026/11/0311 天前

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

@crvouga/mockingbird-service-vercel-blob 是什么?

Stateful Vercel Blob emulator: binary uploads, public downloads, metadata, cursor listing and multipart commits.

如何安装 @crvouga/mockingbird-service-vercel-blob?

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

@crvouga/mockingbird-service-vercel-blob 支持 TypeScript 吗?

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

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

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

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

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

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

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

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

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