Skip to main content
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 and performance optimizations included out of the box

Migration Steps

1

Install the SDK

Replace your manual fetch calls with the SDK:
2

Initialize the Client

Replace your API configuration with SDK initialization:
3

Update API Calls

Replace manual fetch calls with type-safe SDK methods:
4

Update Authentication

Replace manual authentication with SDK auth methods:

Common Migration Patterns

Cart Management

Error Handling

Migration Checklist

1

Replace API Configuration

  • Install SDK package
  • Replace manual API config with SDK initialization
  • Configure token storage (BrowserTokenStorage, CookieTokenStorage, etc.)
2

Update Authentication

  • Replace manual token management with SDK auth methods
  • Remove custom token refresh logic
  • Update login/logout flows to use SDK methods
3

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
4

Test & Optimize

  • Test all authentication flows
  • Verify token management across browser tabs
  • Enable debug mode for development
  • Add performance monitoring

Benefits After Migration

  • 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
  • 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
  • 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:
  1. Enable Debug Mode: Set debug: true in SDK configuration
  2. Check Documentation: Review API Reference for endpoint details
  3. Follow Patterns: Reference Storefront Guides for business logic
  4. 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.