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.
All types are automatically generated from the OpenAPI specification, ensuring theyβre always in sync with the API:
Copy
// Import types from the SDK's auto-generated definitionsimport type { GetProductDetailContent, GetCartContent, GetOrderDetailContent, GetUserDetailContent, ApiResult} from '@commercengine/storefront-sdk';
// Import specific types for custom implementationsimport type { GetProductDetailContent, GetCartContent, GetOrderDetailContent, GetUserDetailContent, ApiResult, ListProductsQuery, CreateCartBody} from '@commercengine/storefront-sdk';// Use in your applicationinterface AppState { currentUser: GetUserDetailContent | null; cart: GetCartContent | null; products: GetProductDetailContent[];}
// Full type safety and IntelliSense with OpenAPI-generated typesconst result = await client.catalog.getProduct('product-id');if (result.data) { // β TypeScript knows exact structure from OpenAPI schema const product = result.data.content; 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}
Always import and use the generated types from the SDK:
Copy
// β Use generated typesimport type { GetProductDetailContent } 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.content; // 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 responses. The examples above use the real type names and property structures from the Commerce Engine API.