@crvouga/mockingbird-service-unsplash

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

Deterministic Unsplash search and local synthetic image fixtures.

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

@crvouga/mockingbird-service-unsplash

Local emulators. Real API contracts. Part of Mockingbird.

WIP Unsplash v1 photo search with deterministic results and synthetic local image bytes.

Install

bun add @crvouga/mockingbird-service-unsplash

Usage

import { createApi } from "unsplash-js"
import { createServer } from "@crvouga/mockingbird-service-unsplash/server"

const server = await createServer()

// The Unsplash SDK your application already uses. Only its base URL changes.
const unsplash = createApi({ accessKey: "mock_unsplash_key", baseUrl: server.url })
const { data } = await unsplash.GET("/search/photos", {
  params: { query: { query: "mock", orientation: "landscape", per_page: 9, page: 1 } },
})
const image = await fetch(data?.results[0]?.urls.regular ?? "") // synthetic local image bytes

await server.close()

For a separate application process, run mockingbird-unsplash serve --port 12125. Set the SDK's baseUrl (or a raw-fetch client's search origin) to http://localhost:12125; no standard vendor base-URL environment variable exists. Accepts client_id=mock_unsplash_key or Authorization: Client-ID mock_unsplash_key. Configure other synthetic keys with accessKeys.

Routes and fixtures

  • GET /search/photos: exact case-insensitive matching against each fixture's queries. Filters orientation, returns total, total_pages, results, Link/X-Total/X-Per-Page headers, and stable insertion-order pages. Defaults: page 1, 10 per page; maximum 30. Unknown queries produce empty pages. Null alt text and missing/null author last names are preserved; attribution links come from fixtures.
  • GET /photos/{id}/download: returns {url} pointing at the local image and increments namespace-scoped download inspection state. No real analytics event is sent.
  • GET /__admin/blobs/{id}: returns fixture bytes with the configured image content type. This is a local transport stand-in, not an Unsplash vendor endpoint.

Pass photos: PhotoFixture[] to seed query matches, attribution, orientation and imageBase64/contentType. The default is one synthetic PNG for query mock, not a real photograph. Use only synthetic or owned bytes. URLs preserve the selected namespace and custom adminPrefix, so a browser can load them without copying the request's credentials.

Controls

The shared /__admin/state/photos and /__admin/state/downloads routes inspect/seed state. Reset restores constructor fixtures and clears download counts. Timeline, clock, request journal, latency and one-shot fault rules use the shared admin contract. Namespaces are selected by x-mockingbird-namespace, /__admin/ns/{name}, or mapped access keys via PUT /__admin/credentials. Query credentials are not put into the journal or pagination links; when following links, reapply authentication.

Presets: unauthorized (401), rate_limited (scripted 403 quota error), server_error (503), connection_drop. These are deterministic failure controls; quota accounting is not live. Generic faults can also script 429 and latency. There are no webhooks.

Acceptance tests cover all three requested behaviors, local bytes over HTTP, custom prefix/namespace image URLs, reset, faults and credential redaction. Property tests cover both parity-enabled JSON operations and detect divergence. bun scripts/parity.ts needs UNSPLASH_ACCESS_KEY and probes an empty metadata search only, without downloading images. Live-account parity has not been run.

Deliberately not modelled

Real search/indexing/ranking, arbitrary partial-text matching, production photo content, image resizing, additional search filters, user OAuth, editing/collections and actual quota accounting. Rate-limit headers on successful responses are fixed fixture values. Only the response fields consumed in issue #281 are modelled; this is not a full photo object.

API

  • UnsplashAPI: FetchAPI with fetch, reset, photos and downloads collections.
  • createRuntime: shared admin, namespace, clock, fault and journal runtime.
  • UNSPLASH_NAMESPACE: service name.
  • UNSPLASH_PRESETS: deterministic named fault controls.
  • DEFAULT_PHOTOS: synthetic initial fixture.
  • accessKey: reads Client-ID header or client_id query credentials.
  • document, operationIds, supportedOperationIds: generated contract metadata.
  • createServer, serveTarget, DEFAULT_PORT from ./server: Node server/CLI target (default port 12125).

Public types: PhotoFixture, UnsplashAPIOptions, OperationId, SupportedOperationId.

版本与发布记录

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

版本发布日期距今
1.11.1latest2026/11/121 天前
1.11.02026/11/122 天前
1.10.02026/11/113 天前
1.9.42026/11/0310 天前
1.9.32026/11/0311 天前
1.9.22026/11/0311 天前

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

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

Deterministic Unsplash search and local synthetic image fixtures.

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

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

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

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

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

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

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

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

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

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

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

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