import { RevstackClient } from '@revstackhq/browser';
const client = new RevstackClient({
publicKey: 'pk_live_...',
getToken: async () => localStorage.getItem('auth_token'),
});
// Initialize on page load
await client.init();
// Show loading state while initializing
if (!client.isReady) {
document.getElementById('app').innerHTML = '<div>Loading...</div>';
} else if (client.hasAccess('premium-feature')) {
renderPremiumUI();
} else {
renderFreeUI();
}
// Handle checkout
document.getElementById('upgrade-btn').addEventListener('click', async () => {
await client.startCheckout({
planId: 'plan_premium',
successUrl: window.location.origin + '/success',
cancelUrl: window.location.origin + '/pricing',
});
});
// Handle billing portal
document.getElementById('manage-btn').addEventListener('click', async () => {
await client.openBillingPortal({
returnUrl: window.location.href,
});
});
// Listen for entitlement changes
client.subscribe(() => {
console.log('Entitlements updated');
if (client.hasAccess('new-feature')) {
showNewFeatureNotification();
}
});