Web SDK API Reference
Complete TypeScript API reference for @vlplay/sdk. [PLACEHOLDER] All methods are available on the singleton VLPlaySDK object after calling VLPlaySDK.init(). Async methods return Promise and should be awaited. The SDK is fully tree-shakeable when imported as ES modules.
[PLACEHOLDER] Type definitions are bundled with the package. IntelliSense support is available in VS Code, WebStorm, and any TypeScript-aware editor without additional configuration.
VLPlaySDK
init(config: VLPlayConfig): Promise<void>
Initialize the SDK. Must be called before any other method.
await VLPlaySDK.init({
appId: string; // required
clientSecret: string; // required
env?: 'production' | 'sandbox'; // default: 'production'
debug?: boolean; // default: false
locale?: string; // default: 'en'
});
version: string
Returns the SDK version string (e.g., "1.0.0").
isInitialized: boolean
Returns true if init() has been called successfully.
auth
auth.login(): Promise<AuthResult>
Opens the VLPlay login popup.
interface AuthResult {
success: boolean;
user: VLPlayUser;
token: { accessToken: string; expiresAt: number };
}
auth.logout(): Promise<void>
Logs out the current user and clears the session.
auth.currentUser: VLPlayUser | null
Returns the currently authenticated user, or null if not logged in.
auth.onAuthStateChanged(callback: (user: VLPlayUser | null) => void): () => void
Subscribe to auth state changes. Returns an unsubscribe function.
iap
iap.getProducts(ids: string[]): Promise<VLPlayProduct[]>
Fetch product details for the given product IDs.
iap.purchase(options: { productId: string }): Promise<PurchaseResult>
Initiate a purchase. Resolves after server-side verification.
interface PurchaseResult {
success: boolean;
transactionId: string;
productId: string;
}
analytics
analytics.track(event: string, properties?: Record<string, unknown>): void
Track a custom analytics event.
analytics.setUserProperties(properties: Record<string, unknown>): void
Set persistent user properties sent with every event.
support
support.show(): void
Open the VLPlay support overlay.
support.showNewTicket(options?: { subject?: string; category?: string }): void
Open the new ticket form with optional pre-filled fields.
support.getUnreadCount(): Promise<number>
Returns the number of unread support messages.