# Zap Studio

> Type-safe, framework-agnostic and composable TypeScript libraries for the web.

## When to use Zap Studio

Zap Studio is a set of small, type-safe, framework-agnostic TypeScript packages
for the infrastructure code every app needs: HTTP calls, retries, authorization
checks, validation, logging, webhooks. Reach for a package here instead of
hand-rolling the same logic per project. Install one with
`npm install @zap-studio/<name>`, or `deno add jsr:@zap-studio/<name>`.

Every runtime package ships standard ESM and targets Node.js 18+, Bun 1.0+,
Deno 1.42+, Cloudflare Workers, and evergreen browsers.

- **@zap-studio/cache** — Zero-dependency in-memory key-value cache with pluggable eviction policies (LRU, LFU, MRU, MFU, FIFO), capacity limits, and optional TTL.
- **@zap-studio/env** — A runtime and framework-agnostic, Standard Schema-based environment variable validator.
- **@zap-studio/fetch** — A type-safe, tree-shakeable fetch wrapper for HTTP requests with runtime schema validation.
- **@zap-studio/logger** — A lean, tree-shakeable logging abstraction with a console implementation.
- **@zap-studio/monads** — Result/Option types and Rust-style functional combinators for explicit, type-safe error handling.
- **@zap-studio/oxfmt** — Zap Studio's oxfmt preset: sorted imports, sorted package.json, and an optional Tailwind CSS class-sorting extension.
- **@zap-studio/oxlint** — Zap Studio's oxlint preset: exclusive, single-owner rule sets — pick exactly the presets your project needs, nothing implied.
- **@zap-studio/permit** — A type-safe, declarative, tree-shakeable authorization library for TypeScript with Standard Schema support.
- **@zap-studio/react-hooks** — Small, focused, tree-shakeable React hooks — one hook, one subpath, no forced bundle.
- **@zap-studio/retry** — Composable, tree-shakeable retry policies for resilient async operations.
- **@zap-studio/store** — Small, framework-agnostic state container with auto-tracked derived values and optional built-in persist.
- **@zap-studio/validation** — Tree-shakeable Standard Schema utilities and ValidationError helpers.
- **@zap-studio/webhooks** — A lightweight, type-safe, tree-shakeable webhook router with Standard Schema validation, signature verification, and lifecycle hooks.
- **@zap-studio/webmcp** — A framework-agnostic, SSR-safe wrapper around the native WebMCP document.modelContext API, with a batch tool registry for exposing JavaScript tools to AI agents.

## Docs

- [Getting Started](https://www.zapstudio.dev/docs): Type-safe, framework-agnostic TypeScript packages for HTTP calls, retries, auth, validation, logging, and webhooks — install one and make your first typed call.
- [Installation](https://www.zapstudio.dev/docs/installation): Install any Zap Studio package from npm or JSR, pick the peer dependencies you need, and import only the code you use.
- [Runtimes](https://www.zapstudio.dev/docs/runtimes): The runtimes every Zap Studio package supports, the shared baseline, and the four packages that ask for more.
- [Composition](https://www.zapstudio.dev/docs/composition): Working recipes that put several Zap Studio packages on one request — retries around a validated call, a cached read, a verified webhook behind a permission check.
- [Principles](https://www.zapstudio.dev/docs/principles): The four rules every Zap Studio package follows, the problems they answer, and where Zap Studio stops.

## Packages

### cache

- [cache](https://www.zapstudio.dev/docs/cache): Zero-dependency in-memory key-value cache with pluggable eviction policies, capacity limits, and optional TTL.
- [Getting Started](https://www.zapstudio.dev/docs/cache/getting-started): Install @zap-studio/cache and build your first cache step by step.
- [Eviction Policies](https://www.zapstudio.dev/docs/cache/eviction-policies): The built-in lru(), lfu(), mru(), mfu(), and fifo() eviction policies, and how to swap between them.
- [Capacity and Eviction](https://www.zapstudio.dev/docs/cache/capacity-and-eviction): createCache evicts one entry, chosen by the configured policy, right before an insert that would exceed capacity.
- [TTL](https://www.zapstudio.dev/docs/cache/ttl): Optional and lazy time-to-live, checked on get/has/peek, no background sweep timer.
- [onEvict](https://www.zapstudio.dev/docs/cache/on-evict): Fires on capacity or TTL eviction — not on manual delete() or clear().
- [peek](https://www.zapstudio.dev/docs/cache/peek): Reads a value without affecting eviction order — useful for inspection or metrics without disturbing LRU/LFU/MRU/MFU state.
- [Custom Policies](https://www.zapstudio.dev/docs/cache/custom-policies): EvictionPolicy<K> is a public interface — implement your own algorithm as a plain object, no subclassing.
- [Iteration](https://www.zapstudio.dev/docs/cache/iteration): keys(), values(), entries(), and [Symbol.iterator]() walk live entries in insertion order without affecting eviction state.

### env

- [env](https://www.zapstudio.dev/docs/env): A runtime and framework-agnostic environment variable validator, built on Standard Schema.
- [Getting Started](https://www.zapstudio.dev/docs/env/getting-started): Install @zap-studio/env and validate your first env schema in a few lines.
- [server / client / shared](https://www.zapstudio.dev/docs/env/server-client-shared): The three buckets a schema can declare, the clientPrefix rule, and the runtime access guard that keeps server secrets out of client bundles.
- [extends](https://www.zapstudio.dev/docs/env/extends): Compose reusable EnvironmentSchema definitions across packages, with reference-equality conflict detection.
- [Presets](https://www.zapstudio.dev/docs/env/presets): Ready-made EnvironmentSchema objects for env vars that hosting platforms set automatically.
- [generateEnvironmentExample](https://www.zapstudio.dev/docs/env/generate-env-example): Schema-driven .env.example generation — no dev server, safe to run in CI and commit.
- [Errors](https://www.zapstudio.dev/docs/env/errors): EnvironmentError for setup mistakes, EnvironmentValidationError for failed validation, and EnvironmentAccessError for client-side reads of server-only keys.
- [Advanced Options](https://www.zapstudio.dev/docs/env/advanced-options): skipValidation for partial build steps, emptyStringAsUndefined for blank vars, and runtimeEnvStrict for pre-assembled env objects.
- [OpenTelemetry](https://www.zapstudio.dev/docs/env/opentelemetry): Every createEnvironment validation pass surfaced as an env.validate span through @opentelemetry/api.

### fetch

- [fetch](https://www.zapstudio.dev/docs/fetch): A type-safe fetch wrapper that validates JSON responses at runtime with any Standard Schema validator.
- [Getting Started](https://www.zapstudio.dev/docs/fetch/getting-started): Install @zap-studio/fetch and make your first validated request.
- [Raw Fetch Mode](https://www.zapstudio.dev/docs/fetch/raw-fetch-mode): Use $fetch without a schema for a native Response, behaving like global fetch.
- [Validated Fetch Mode](https://www.zapstudio.dev/docs/fetch/validated-fetch-mode): Use $fetch with a Standard Schema to parse and validate the JSON response, with the return type inferred from the schema.
- [API Methods](https://www.zapstudio.dev/docs/fetch/api-methods): Make schema-validated GET, POST, PUT, PATCH, and DELETE requests with the api method helpers.
- [createFetch](https://www.zapstudio.dev/docs/fetch/create-fetch): Create configured fetch clients with a shared base URL, headers, query params, and error defaults.
- [JSON Convenience](https://www.zapstudio.dev/docs/fetch/json-convenience): Use the json option to send a serialized JSON request body without manual stringification or headers.
- [Validation](https://www.zapstudio.dev/docs/fetch/validation): Validate response bodies with Zod, Valibot, ArkType, or any other Standard Schema-compatible validator.
- [Error Handling](https://www.zapstudio.dev/docs/fetch/errors): Catch FetchError and ValidationError, and handle parsing, abort, and network failures from fetch calls.
- [Logging](https://www.zapstudio.dev/docs/fetch/logging): Observe requests, responses, and validation failures with an optional logger.
- [OpenTelemetry](https://www.zapstudio.dev/docs/fetch/opentelemetry): Native distributed tracing through @opentelemetry/api, with zero setup when no SDK is registered.

### logger

- [logger](https://www.zapstudio.dev/docs/logger): A lean logging abstraction with a console implementation.
- [Getting Started](https://www.zapstudio.dev/docs/logger/getting-started): Install @zap-studio/logger and control log verbosity with ConsoleLogger.
- [Output Formats](https://www.zapstudio.dev/docs/logger/formats): Pick a built-in output format for ConsoleLogger, or write your own.
- [Runtime Compatibility](https://www.zapstudio.dev/docs/logger/runtime-compatibility): How @zap-studio/logger adapts automatically to Node, Bun, Deno, browsers, and Cloudflare Workers.
- [OpenTelemetry](https://www.zapstudio.dev/docs/logger/opentelemetry): Automatic trace-log correlation through @opentelemetry/api, with zero setup when no SDK is registered.

### monads

- [monads](https://www.zapstudio.dev/docs/monads): Result/Option types and Rust-style functional combinators for explicit, type-safe error handling.
- [Getting Started](https://www.zapstudio.dev/docs/monads/getting-started): Install @zap-studio/monads and handle your first fallible operation with Result.
- [Result](https://www.zapstudio.dev/docs/monads/result): Result<T, E> constructors, guards, and combinators for explicit, type-safe error handling.
- [ResultAsync](https://www.zapstudio.dev/docs/monads/result-async): A thenable wrapper around Promise<Result<T, E>> for chaining async operations that can fail.
- [Option](https://www.zapstudio.dev/docs/monads/option): Option<T> constructors, guards, and combinators for explicit, type-safe null handling.
- [Pipe](https://www.zapstudio.dev/docs/monads/pipe): Left-to-right function composition for the standalone Result/Option combinators.

### oxfmt

- [oxfmt](https://www.zapstudio.dev/docs/oxfmt): A decided oxfmt preset for sorted imports, sorted package.json, and optional Tailwind CSS class sorting.
- [Getting Started](https://www.zapstudio.dev/docs/oxfmt/getting-started): Install @zap-studio/oxfmt and configure the base or Tailwind preset.
- [Presets](https://www.zapstudio.dev/docs/oxfmt/presets): The base preset's import group order and package.json sorting, and what the tailwind preset adds.

### oxlint

- [oxlint](https://www.zapstudio.dev/docs/oxlint): Exclusive, single-owner oxlint presets — pick exactly the plugins and framework rules your project needs, nothing implied.
- [Getting Started](https://www.zapstudio.dev/docs/oxlint/getting-started): Install @zap-studio/oxlint, extend a preset, and override a single rule without forking it.
- [Presets](https://www.zapstudio.dev/docs/oxlint/presets): What each preset owns — one plugin or framework integration per preset, nothing implied by another.
- [Plugins](https://www.zapstudio.dev/docs/oxlint/plugins): Where every rule in every preset comes from — the upstream plugin or spec it's ported or wrapped from, and where to read why a rule is off.
- [Anti-Slop Plugin](https://www.zapstudio.dev/docs/oxlint/anti-slop): The bundled anti-slop plugin — original rules for patterns that don't fit any upstream ESLint plugin.

### permit

- [permit](https://www.zapstudio.dev/docs/permit): A type-safe, declarative authorization library for TypeScript with Standard Schema validation and composable conditions.
- [Getting Started](https://www.zapstudio.dev/docs/permit/getting-started): Define resources, actions, context, and rules to build your first authorization policy with permit.
- [Declarative Policies](https://www.zapstudio.dev/docs/permit/declarative-policies): Through createPolicy(...) with allow(), deny(), and when(condition) — define authorization rules in permit.
- [Standard Schema Support](https://www.zapstudio.dev/docs/permit/standard-schema): permit resources work with any Standard Schema-compatible validation library — Zod, Valibot, ArkType, or your own.
- [Role-Based Access Control](https://www.zapstudio.dev/docs/permit/roles): Implement RBAC with role hierarchies and multi-role support using hasRole() in permit.
- [Conditions](https://www.zapstudio.dev/docs/permit/conditions): Build complex authorization rules using and(), or(), not(), and has() condition combinators in permit.
- [Merging Policies](https://www.zapstudio.dev/docs/permit/merging-policies): Combine multiple policies with AND or OR strategies in permit.
- [Scaling Policies](https://www.zapstudio.dev/docs/permit/scaling-policies): Split a policy with many resources and actions across files while keeping one type-safe source of truth.
- [Error Handling](https://www.zapstudio.dev/docs/permit/errors): PolicyError for invalid configuration or evaluation failures in permit.
- [Logging](https://www.zapstudio.dev/docs/permit/logging): Observe allow and deny decisions with an optional logger.
- [OpenTelemetry](https://www.zapstudio.dev/docs/permit/opentelemetry): Authorization checks surfaced as spans and a decision counter through @opentelemetry/api.

### react-hooks

- [react-hooks](https://www.zapstudio.dev/docs/react-hooks): Small, focused, tree-shakeable React hooks — one hook, one subpath, no forced bundle.
- [Getting Started](https://www.zapstudio.dev/docs/react-hooks/getting-started): Install @zap-studio/react-hooks.
- [Sensors](https://www.zapstudio.dev/docs/react-hooks/sensors): Viewport, network, device, and permission state — SSR-safe reads of the browser environment around your component.
- [DOM / Element Interaction](https://www.zapstudio.dev/docs/react-hooks/dom): Ref'd-element observers, drag-and-drop, and browser chrome APIs — click-outside, intersection/resize/mutation observers, fullscreen, popovers, and more.
- [Input](https://www.zapstudio.dev/docs/react-hooks/input): Keyboard shortcuts, gamepads, pointer lock, and user-activation state.
- [Media](https://www.zapstudio.dev/docs/react-hooks/media): Camera, microphone, screen capture, recording, and speech hooks.
- [History & Navigation](https://www.zapstudio.dev/docs/react-hooks/navigation): Track back/forward navigation, classify how the current page was reached, and block in-app route transitions via the Navigation API.
- [Network](https://www.zapstudio.dev/docs/react-hooks/network): Connection state for WebSocket, Server-Sent Events, and WebTransport, with automatic teardown on unmount or URL change.
- [PWA](https://www.zapstudio.dev/docs/react-hooks/pwa): Installability, Service Worker update state, app badges, and standalone-display detection for progressive web apps.
- [Commerce](https://www.zapstudio.dev/docs/react-hooks/commerce): Show the browser/OS's native payment sheet via the Payment Request API.
- [Lifecycle](https://www.zapstudio.dev/docs/react-hooks/lifecycle): Mount/unmount effects, declarative timers, async state, and scheduling primitives.
- [State](https://www.zapstudio.dev/docs/react-hooks/state): Local, persisted, cross-tab, and cross-window state hooks — from a plain toggle to IndexedDB, cookies, and postMessage.
- [Debug / Observability](https://www.zapstudio.dev/docs/react-hooks/debug): Render diagnostics — render count, render reason, why-did-you-update, and Fiber access.

### retry

- [retry](https://www.zapstudio.dev/docs/retry): Composable retry policies with a built-in runner, structured terminal errors, and AbortSignal cancellation.
- [Getting Started](https://www.zapstudio.dev/docs/retry/getting-started): Install @zap-studio/retry and build your first retry policy step by step.
- [fixedDelay](https://www.zapstudio.dev/docs/retry/fixed-delay): Retry with a constant delay between attempts until max attempts is reached.
- [linearBackoff](https://www.zapstudio.dev/docs/retry/linear-backoff): Retry with linearly growing delays, capped at an upper bound.
- [exponentialBackoff](https://www.zapstudio.dev/docs/retry/exponential-backoff): Retry with exponentially growing delays, capped at an upper bound.
- [Shared Runner](https://www.zapstudio.dev/docs/retry/running-policies): A shared runner via runRetryPolicy with attempt-aware callbacks and custom sleep injection.
- [Non-throw Mode](https://www.zapstudio.dev/docs/retry/non-throw-mode): Set throwOnExhausted false to receive a RetryRunResult instead of a thrown error.
- [Cancellation](https://www.zapstudio.dev/docs/retry/abort-signal): Cancellation through AbortSignal, checked before, between, and during retries.
- [Jitter](https://www.zapstudio.dev/docs/retry/jitter): Randomize exponentialBackoff/linearBackoff delays to avoid synchronized retries against a shared upstream.
- [Custom Policies](https://www.zapstudio.dev/docs/retry/custom-policies): Custom policies as plain objects implementing RetryPolicy and its next(...) function.
- [Structured Errors](https://www.zapstudio.dev/docs/retry/errors): RetryError on exhaustion, AbortError on cancellation — both structured terminal errors.
- [Logging](https://www.zapstudio.dev/docs/retry/logging): Observe retry decisions, exhaustion, and cancellation with an optional logger.
- [OpenTelemetry](https://www.zapstudio.dev/docs/retry/opentelemetry): Retry decisions surfaced as span events and a counter metric through @opentelemetry/api.

### store

- [store](https://www.zapstudio.dev/docs/store): A small, framework-agnostic state container with auto-tracked derived values and optional built-in persist.
- [Getting Started](https://www.zapstudio.dev/docs/store/getting-started): Install @zap-studio/store and build your first store step by step.
- [set](https://www.zapstudio.dev/docs/store/set): set only takes an updater function, and the result is always shallow-merged into state.
- [derive](https://www.zapstudio.dev/docs/store/derive): An auto-tracked, cached computed value built from one or more stores.
- [Persist](https://www.zapstudio.dev/docs/store/persist): Simple, built-in persistence through any localStorage-shaped storage — no separate package, no migration system.
- [React](https://www.zapstudio.dev/docs/store/react): useStore — a single hook that subscribes a component to a createStore or derive instance.

### validation

- [validation](https://www.zapstudio.dev/docs/validation): Standard Schema utilities and ValidationError helpers for one consistent validation flow across schema libraries.
- [Getting Started](https://www.zapstudio.dev/docs/validation/getting-started): Install @zap-studio/validation and validate your first payload in a few lines.
- [Async Validation](https://www.zapstudio.dev/docs/validation/async-validation): Validate values asynchronously with standardValidate, which works with sync and async schemas.
- [Synchronous Validation](https://www.zapstudio.dev/docs/validation/synchronous-validation): Validate values synchronously with standardValidateSync, for schemas known to validate synchronously.
- [Create Validators](https://www.zapstudio.dev/docs/validation/create-validators): Build reusable validation functions with createStandardValidator and createStandardValidatorSync.
- [Errors](https://www.zapstudio.dev/docs/validation/errors): Optional throwing behavior via throwOnError, backed by a shared ValidationError class.
- [Runtime Schema Detection](https://www.zapstudio.dev/docs/validation/runtime-schema-detection): Detect Standard Schema values at runtime with isStandardSchema.

### webhooks

- [webhooks](https://www.zapstudio.dev/docs/webhooks): Schema-first, type-safe webhook routing built on the standard Web API Request and Response primitives, with runtime-agnostic signature verification support.
- [Getting Started](https://www.zapstudio.dev/docs/webhooks/getting-started): Install @zap-studio/webhooks and build your first schema-validated webhook router step by step.
- [Web API Native](https://www.zapstudio.dev/docs/webhooks/web-api-native): handle(request) returns a Response, so the router plugs directly into Bun, Deno, Cloudflare Workers, Next.js, Hono, and any other fetch-compatible runtime.
- [Type-Safe Routing](https://www.zapstudio.dev/docs/webhooks/type-safe-routing): Handler payload types are inferred from the route schema.
- [Standard Schema](https://www.zapstudio.dev/docs/webhooks/standard-schema): Bring Zod, Valibot, ArkType, or any Standard Schema-compatible library.
- [Verification](https://www.zapstudio.dev/docs/webhooks/verification): Verify webhook authenticity with createHmacVerifier or a custom verify function — built-in HMAC verification with constant-time comparison, runtime-agnostic via the Web Crypto API.
- [Lifecycle Hooks](https://www.zapstudio.dev/docs/webhooks/lifecycle-hooks): Use before, after, and onError hooks for logging, metrics, and centralized error handling.
- [Logging](https://www.zapstudio.dev/docs/webhooks/logging): Observe delivery attempts, dispatch, verification failures, and unmatched routes with an optional logger.
- [OpenTelemetry](https://www.zapstudio.dev/docs/webhooks/opentelemetry): Native distributed tracing through @opentelemetry/api, with zero setup when no SDK is registered.

### webmcp

- [webmcp](https://www.zapstudio.dev/docs/webmcp): A framework-agnostic, SSR-safe wrapper around the native WebMCP document.modelContext API, with a batch tool registry for exposing JavaScript tools to AI agents.
- [Getting Started](https://www.zapstudio.dev/docs/webmcp/getting-started): Install @zap-studio/webmcp and register your first tool step by step.
- [Tool Registry](https://www.zapstudio.dev/docs/webmcp/registry): createToolRegistry batches a group of tools behind one mount/unmount pair.
- [Errors](https://www.zapstudio.dev/docs/webmcp/errors): WebMCPNotSupportedError and hasWebMCPSupport, for handling browsers that don't support WebMCP yet.
- [React](https://www.zapstudio.dev/docs/webmcp/react): useWebMCPTool — a hook that registers a tool with the native WebMCP API for the lifetime of a component.

## Agent resources

- [llms-full.txt](https://www.zapstudio.dev/llms-full.txt): The full Markdown of every page in one file.
- [Page Markdown](https://www.zapstudio.dev/index.md): Append `.md` to any page URL to fetch that page as raw Markdown.
- [JSON API](https://www.zapstudio.dev/api/docs/pages.json): Page index of the JSON docs API; each entry links the page's JSON and Markdown forms. Described by the OpenAPI document at https://www.zapstudio.dev/openapi.json.
- [Agent skills](https://www.zapstudio.dev/.well-known/agent-skills/index.json): Agent Skills discovery index of the skills this site publishes.
- [API catalog](https://www.zapstudio.dev/.well-known/api-catalog): RFC 9727 linkset of the APIs documented here.
- [AI catalog](https://www.zapstudio.dev/.well-known/ai-catalog.json): ARD manifest of the agent-facing resources on this site (MCP server, skills, APIs).
- [agent-readability.json](https://www.zapstudio.dev/agent-readability.json): Manifest of every agent-facing artifact on this site.
- [Sitemap](https://www.zapstudio.dev/sitemap.xml): Every indexable page URL with its last-modified date.
