CodeVetter
← All unpacks
CodeVetter · Repo Unpack evidence

unjs/ofetch

Scanned commit 1dbc37fd1c dated 2026-07-08 — last upstream commit. Generated by codevetter 1.15.0 on 2026-10-02.

github.com/unjs/ofetch ↗ · 32 files · 352 KB

ofetch A better fetch API. Works on node, browser, and workers.

Deep analysis by cli:codex via the codex CLI on 2026-10-02 (235s) — every claim below links to its cited source files. Source inspection; upstream code and tests were not executed.

Overview

ofetch is a TypeScript HTTP client library for applications using native fetch in Node.js, browsers, and workers. At commit 1dbc37fd1ceab832fc7c90cad81b1091c95ba563, its v2 alpha implementation adds response decoding, request serialization, lifecycle hooks, configurable retries, timeouts, and reusable defaults. Its central abstraction is a callable client with raw, native, and create variants; transport remains delegated to the host runtime or an injected fetch implementation.

System map

The system is a library consumed through an ESM package entrypoint. Seven source modules divide client creation, request execution, helpers, errors, and public types. State lives in factory closures and per-request contexts, while network behavior belongs to native or injected fetch. Build and CI configuration describe npm distribution and Node validation.

Feature catalog

The user-facing surface is an HTTP client API with typed options and results. Automatic serialization and decoding remove common fetch boilerplate. Factories and hooks support shared application behavior, while retry and timeout options control failures. Raw responses, streams, and transport dispatchers expose lower-level capabilities.

Data flow

Inputs enter as FetchRequest and FetchOptions, then become a mutable FetchContext. Resolution merges shared defaults with call-specific headers and query values before hooks and normalization. Fetch produces a Response whose body becomes _data, which hooks can inspect before return or rejection. Retries carry transformed context back through the same pipeline.

Behavior traces

Source reading followed initialization, a JSON POST, and HTTP failure with retry through their complete call chains. Additional branches cover custom clients, streaming, and transport rejection. The same raw function owns preprocessing, fetch, decoding, hooks, and status handling. These are static execution traces rather than observed runs.

Testing signals

Tests and CI were inspected, not executed; no passing result or measured coverage is established. The inspected Vitest suite primarily exercises native fetch against a local H3 server. Coverage spans serialization, decoding, headers, errors, hooks, retries, and timeout behavior, with some assertions narrower than their titles imply. This is a bounded inventory rather than exhaustive behavioral assurance.

Risk map

The main review hotspots are URL rewriting, retry replay, abort composition, and error exposure. Several observable boundaries bypass normalized FetchError handling. Documentation also contains compatibility descriptions that differ from this alpha implementation. The following are source observations or explicitly marked hypotheses, not confirmed vulnerabilities.

Extension points

Extension primarily happens through factories, typed options, and lifecycle hooks. Transport injection permits alternative fetch implementations without changing the request pipeline. Parsers and response mappings offer decoding customization, while dispatchers expose runtime-specific networking. Source-level helper tables define the narrower places where core behavior can be extended.

Contributor handoff

Start with the public factory and raw pipeline, then follow the helper or type implicated by the task. Preserve option precedence and lifecycle ordering, which affect every client call. Tests and CI were inspected, not executed; their existence supplies investigation targets rather than passing evidence. The report inspected 17 source/example/test files plus documentation and configuration, but remains bounded rather than exhaustive.

Languages

LanguageFilesShare of source
TypeScript1158%
JavaScript842%
JSON3docs/config
Markdown3docs/config
YAML2docs/config

Start reading here

Probable source entrypoint: src/index.ts — inferred from the directory tree and manifest, not the upstream docs.

Source roots

src/ (7 files)

Source layout — src/

PathFiles
src/base.ts1
src/error.ts1
src/fetch.ts1
src/index.ts1
src/types.ts1
src/utils.ts1
src/utils.url.ts1

Repository structure

Top-level pathFiles
examples/9
src/7
.github/3
test/2

Docs found: README.md

Package

package.json — ofetch v2.0.0-alpha.3, 12 declared dependencies.

@types/node@vitest/coverage-v8automdchangelogeneslinteslint-config-unjsh3obuildprettiertypescriptundicivitest

CI & config entrypoints

Structural health signals

Average score 8.9/10 across 10 analyzed source files; 1 hotspot surfaced.

These are deterministic review leads — size, churn, and structural signals — not proof of a bug in this project.

Recent history