100% type-safe SDK with IntelliSense, compile-time checking, and OpenAPI-generated types
The SDK provides 100% type safety with auto-generated types from OpenAPI specifications, complete IntelliSense support, and compile-time error prevention.
Request-only schemas — export the Input name only (e.g. AnalyticsEventInput)
Copy
// Response data — use the base nameconst address: CustomerAddress = response.data.address;// Request body — use the Input suffixconst newAddress: CustomerAddressInput = { street: "123 Main St", city: "New York", // ...};const { data, error } = await sdk.customer.createAddress(newAddress);
You can also use the endpoint-level Body types (e.g. UpdateFulfillmentPreferenceBody) to type the full request body shape passed to an SDK method.
// Response types — for reading API dataimport type { GetProductDetailContent, GetCartContent, GetOrderDetailContent, GetUserDetailContent, ApiResult, ListProductsQuery, CreateCartBody} from '@commercengine/storefront-sdk';// Input types — for request bodiesimport type { CustomerAddressInput, FulfillmentPreferenceInput,} from '@commercengine/storefront-sdk';// Readable / Writable utility types — escape hatches for advanced useimport type { Readable, Writable } from '@commercengine/storefront-sdk';// Use in your applicationinterface AppState { currentUser: GetUserDetailContent | null; cart: GetCartContent | null; products: GetProductDetailContent[];}
The SDK re-exports Readable and Writable utility types for advanced use cases where the generated exports don’t cover your needs:
Copy
import type { Readable, Writable } from '@commercengine/storefront-sdk';import type { components } from '@commercengine/storefront-sdk';// Manually create a response typetype MyResponseType = Readable<components['schemas']['SomeSchema']>;// Manually create a request body typetype MyRequestType = Writable<components['schemas']['SomeSchema']>;
In most cases you won’t need Readable or Writable directly — the generated base-name and Input exports cover standard usage. These are provided as escape hatches.
// Full type safety and IntelliSense with OpenAPI-generated typesconst result = await client.catalog.getProductDetail({ product_id_or_slug: 'product-id' });if (result.data) { // ✅ TypeScript knows exact structure from OpenAPI schema const product = result.data.product; console.log(product.name); // ✅ Known to be string console.log(product.id); // ✅ Known to be string console.log(product.is_active); // ✅ Known to be boolean} else if (result.error) { // ✅ Typed error handling console.error(result.error.message); // ✅ Known error structure}
Copy
// No type safety - all runtime errorsconst response = await fetch('/catalog/products/product-id');const data = await response.json();if (response.ok) { // ❌ No type information - could fail at runtime console.log(data.content.name); // Could be undefined console.log(data.content.price); // Property name might be wrong console.log(data.content.active); // Could be different property name} else { // ❌ Unknown error structure console.error(data.message); // Could be different property name}
Always import and use the generated types from the SDK:
Copy
// ✅ Use generated types for responsesimport type { GetProductDetailContent } from '@commercengine/storefront-sdk';// ✅ Use Input types for request bodiesimport type { CustomerAddressInput } from '@commercengine/storefront-sdk';// ❌ Avoid creating custom interfaces that duplicate API schemasinterface CustomProduct { id: string; name: string; // ... this will get out of sync with API}
Handle API Responses Properly
Always check for both success and error conditions:
Copy
const result = await client.catalog.listProducts();if (result.data) { // Handle success case const products = result.data.products; // Process products...} else if (result.error) { // Handle error case console.error('API Error:', result.error.message);} else { // Handle unexpected case console.error('Unexpected response structure');}
Find API usage errors during development, not production
Always Current Documentation
Types are auto-generated from OpenAPI spec and always up-to-date
Faster Development
IntelliSense speeds up development with accurate autocomplete
Confident Refactoring
Change APIs with confidence using IDE refactoring tools
All SDK types are automatically generated from the OpenAPI specification, ensuring they’re always accurate and up-to-date with the actual API. Response types use the base schema name (e.g. CustomerAddress), while request body types use the Input suffix (e.g. CustomerAddressInput). The Readable and Writable utility types are also available for advanced use cases.