@clickwire/api-client
v2.5.0
Published
Clickwire API client
Readme
@clickwire/api-client
TypeScript client for our Laravel V2 API. Node 18+, server-side only — uses fetch and reads CLICKWIRE_API_URL + CLICKWIRE_TOKEN from the environment at request time (same vars as the monorepo / Next apps). No setup ceremony beyond having those set.
Use it
import { apiClient } from "@clickwire/api-client/v2";
const { data } = await apiClient.posts.list({ per_page: 20 });
const product = await apiClient.products.get("some-slug");Prefer @clickwire/api-client/v2 over the root export when you care which API version you’re on. Methods are grouped like the HTTP API (authors, posts, products, …). Types are prefixed V2* — use them for query params and response shapes.
Optional: apiClient.configure({ locale: "nl" }) sets the global locale query param for V2. Most of the times the default locale for the Website will be sufficient.
Global query params
Configure query params once instead of repeating them on every call:
import { createV2ApiClient } from "@clickwire/api-client/v2";
const clickwire = createV2ApiClient({
// Semantic: this website doesn't carry these product types.
catalog: { excludeProductTypes: ["sneakers"] },
// Generic: default query params per endpoint, keyed by `<group>.<method>`.
defaultQuery: {
"products.list": { per_page: 8 },
"posts.list": { sticky: true },
},
});
// `exclude_product_types[]=sneakers&per_page=8` sent automatically:
await clickwire.products.list({ sort: "newest" });catalog.excludeProductTypes sends exclude_product_types[] on every catalog-surface endpoint (products.list, products.related, productAttributes.list, productAttributes.get): excluded products disappear from hits, facets, and related results, and attribute products_count / has_products reflect the scoped catalog.
Precedence per query key: per-call > defaultQuery > catalog > locale. Arrays replace (never merge), so passing exclude_product_types: [] on a single call lifts the global exclusion for that request. Member endpoints never receive defaults (per-user credentials).
Local testing
Include the package from local disk in your test client:
"dependencies": {
"@clickwire/api-client": "file:path/to/vp/packages/api-client",
},Every time you make a change to the api-client package locally you should build the package and then run npm install again in your test client.
Develop & publish
From packages/api-client:
npm run typecheck
npm run buildRelease
Make sure you are authenciated with NPM:
npm loginThen run:
npm run release -- <version>Replace <version> with either major, minor or patch or set your own x.x.x.
