@sudobility/cravings_client
v0.0.13
Published
Client library for Starter API with TanStack Query hooks
Maintainers
Readme
@sudobility/cravings_client
API client SDK for Cravings with TanStack Query hooks.
Installation
bun add @sudobility/cravings_clientPeer dependencies: react (>=18), @tanstack/react-query (>=5), @sudobility/types.
Usage
import { CravingsClient } from "@sudobility/cravings_client";
import { useHistories, useHistoriesTotal } from "@sudobility/cravings_client/hooks";
// HTTP client (dependency-injected NetworkClient)
const client = new CravingsClient({ baseUrl, networkClient });
// React hooks
const { data, createHistory, updateHistory, deleteHistory } = useHistories(config);
const { data: total } = useHistoriesTotal(config);API
CravingsClient
HTTP client class constructed with { baseUrl, networkClient }. Uses dependency injection via the NetworkClient interface -- no direct fetch calls.
Hooks
useHistories(config)-- query + mutations for user histories with automatic cache invalidationuseHistoriesTotal(config)-- query for global total (public endpoint)
Utilities
createAuthHeaders(token)-- build Authorization headerbuildUrl(base, path)-- construct API URLshandleApiError(error)-- standardized error handlingQUERY_KEYS-- type-safe cache key factory for TanStack Query
Development
bun run build # Build ESM
bun test # Run Vitest tests
bun run typecheck # TypeScript check
bun run lint # ESLint
bun run verify # All checks + build (use before commit)Related Packages
- cravings_types -- Shared type definitions
- cravings_api -- Backend server this client communicates with
- cravings_lib -- Business logic layer that wraps this client
- cravings_app -- Web frontend
- cravings_app_rn -- React Native mobile app
License
BUSL-1.1
