Migration Guide
Migrate from direct API calls to the type-safe SDK
This guide helps you migrate from direct API calls to the Commerce Engine TypeScript SDK, highlighting the benefits and providing step-by-step migration patterns.
Why Migrate to the SDK?
Automatic Token Management
No more manual token refresh logic - handled automatically by the SDK
100% Type Safety
Complete TypeScript support with IntelliSense and compile-time error checking
Simplified Error Handling
Consistent error patterns with typed error responses across all endpoints
Built-in Best Practices
Authentication flows, caching, and performance optimizations included out of the box
Migration Steps
Install the SDK
Replace your manual fetch calls with the SDK:
Initialize the Client
Replace your API configuration with SDK initialization:
Update API Calls
Replace manual fetch calls with type-safe SDK methods:
Update Authentication
Replace manual authentication with SDK auth methods:
Common Migration Patterns
Cart Management
Error Handling
Migration Checklist
Replace API Configuration
- Install SDK package
- Replace manual API config with SDK initialization
- Configure token storage (BrowserTokenStorage, CookieTokenStorage, etc.)
Update Authentication
- Replace manual token management with SDK auth methods
- Remove custom token refresh logic
- Update login/logout flows to use SDK methods
Migrate API Calls
- Replace fetch calls with SDK client methods
- Add TypeScript types to replace
any
types - Update error handling to use SDK error patterns
Test & Optimize
- Test all authentication flows
- Verify token management across browser tabs
- Enable debug mode for development
- Add performance monitoring
Benefits After Migration
Development Experience
Development Experience
- IntelliSense: Complete autocomplete for all API methods and parameters
- Type Safety: Compile-time error checking prevents runtime issues
- Better Debugging: Built-in logging and error tracking
- Reduced Boilerplate: No more manual token management code
Authentication & Security
Authentication & Security
- Automatic Token Refresh: No more expired token errors
- Secure Storage: Built-in secure token storage options
- Cross-tab Sync: Token updates sync across browser tabs
- Session Management: Handles anonymous-to-authenticated transitions
Performance & Reliability
Performance & Reliability
- Request Optimization: Built-in connection pooling and optimization
- Error Recovery: Automatic retry logic for failed requests
- Caching Support: Built-in caching middleware support
- Production Ready: Battle-tested in production environments
Need Help?
If you encounter issues during migration:
- Enable Debug Mode: Set
debug: true
in SDK configuration - Check Documentation: Review API Reference for endpoint details
- Follow Patterns: Reference Storefront Guides for business logic
- Type Safety: Use TypeScript for better development experience
The SDK is designed to be a drop-in replacement for direct API calls while providing significant improvements in developer experience, type safety, and reliability.