@resypress/theme-sdk
v0.1.3
Published
SDK for building ResyPress themes - reusable components, API services, and utilities
Maintainers
Readme
@resypress/theme-sdk
SDK for building ResyPress themes - reusable components, API services, and utilities.
Open Source
This project is open source and available under the MIT License.
Installation
npm install @resypress/theme-sdkQuick Start
Initialize the SDK
The SDK automatically detects configuration from multiple sources. You can initialize it with minimal or no configuration:
import { init } from '@resypress/theme-sdk';
// Option 1: Auto-detect from domain (recommended for production)
// The SDK will automatically detect account from the current domain
await init();
// Option 2: Override specific values
await init({
accountID: '123',
apiBaseUrl: 'https://api.resypress.com/api',
locale: 'en',
});
// Option 3: Use environment variables in development
// In your theme project, create a .env file with:
// VITE_RESYPRESS_ACCOUNT_ID=123
// VITE_RESYPRESS_API_BASE_URL=http://localhost:8080/api
// VITE_RESYPRESS_LOCALE=en
// Then pass them to init():
await init({
accountID: import.meta.env.VITE_RESYPRESS_ACCOUNT_ID,
apiBaseUrl: import.meta.env.VITE_RESYPRESS_API_BASE_URL || '/api',
locale: import.meta.env.VITE_RESYPRESS_LOCALE || 'en',
});Configuration Priority
The SDK uses the following priority order (highest to lowest):
- Explicit init() options - Values passed directly to
init() - localStorage overrides - For runtime testing (useful for development)
RESYPRESS_ACCOUNT_IDRESYPRESS_API_BASE_URLRESYPRESS_LOCALE
- window.RESYPRESS__CONFIG - Injected config object (from config.json or server-side)
- Domain auto-detection - Automatically detects account from current hostname
- Uses the FULL domain name (e.g.,
example.comorwww.example.com) - Matches backend's WebsiteDomain lookup behavior (looks up by full domain_value)
- Skips localhost and IP addresses
- Uses the FULL domain name (e.g.,
- Default values - Fallback defaults (
/apifor base URL,enfor locale)
Environment Variables in Development
For development, you can use environment variables in your theme project's .env file:
VITE_RESYPRESS_ACCOUNT_ID=123
VITE_RESYPRESS_API_BASE_URL=http://localhost:8080/api
VITE_RESYPRESS_LOCALE=enThen pass them to init():
await init({
accountID: import.meta.env.VITE_RESYPRESS_ACCOUNT_ID,
apiBaseUrl: import.meta.env.VITE_RESYPRESS_API_BASE_URL || '/api',
locale: import.meta.env.VITE_RESYPRESS_LOCALE || 'en',
});Note: The SDK cannot directly access your project's import.meta.env at runtime, so you need to pass environment variables explicitly to init().
Use API Services
import { apiClient } from '@resypress/theme-sdk';
// Make API calls
const properties = await apiClient('/public/{accountID}/properties');Use Utilities
import { getText } from '@resypress/theme-sdk';
// Handle multilingual strings
const name = getText(property.name, 'en'); // Returns 'en' version or fallbackFeatures
- ✅ Core Configuration - Initialize and manage SDK configuration
- ✅ API Client - Type-safe API client with error handling
- ✅ i18n Utilities - Multilingual string handling
- 🚧 React Components - Coming soon
- 🚧 React Hooks - Coming soon
- 🚧 Additional Services - Coming soon
Documentation
Full documentation is available in THEME_SDK.md.
Development
# Install dependencies
npm install
# Build the library
npm run build
# Type check
npm run type-check
# Watch mode
npm run devContributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
License
This project is licensed under the MIT License - see the LICENSE file for details.
