@shophost/client
v2.0.76
Published
`@shophost/client` is the generated TypeScript client for the ShopHost API.
Maintainers
Readme
@shophost/client
@shophost/client is the generated TypeScript client for the ShopHost API.
It wraps the generated OpenAPI SDK with a small runtime that normalizes request shapes and responses.
Installation
pnpm add @shophost/clientUsage
Create a client pointed at the public app origin:
import { initClient } from "@shophost/client";
const shophost = initClient({
baseUrl: "http://localhost:3000",
credentials: "include",
throwOnUnknownStatus: true,
});Fetch products:
const response = await shophost.product.getProducts({
params: {
organizationId: "org_123",
},
query: {
page: 1,
limit: 20,
locale: "en",
},
});
if (response.status === 200) {
console.log(response.body.list);
}Create a temporary upload record:
const response = await shophost.file.createTemporaryFile({
body: {
filename: "hero.jpg",
mimeType: "image/jpeg",
size: 1024,
},
});Client Options
baseUrlPublic origin of the app exposing ShopHost routes. The client appends/api.baseHeadersDefault headers sent with every request.credentialsForward cookies for auth-aware calls.fetchCustom fetch implementation.throwOnUnknownStatusThrow when the API returns a status code that is not documented in OpenAPI.
Regenerate
pnpm exec nx run client:generateLicense
MIT
