Initialise SDK Required First
MBBridge.init({ appId: 'showcase-app', isDebug: false });
// Call once before any other method
// Synchronous β no need to await
SDK Rules
β’ Call
init() once before anything elseβ’
init() is synchronous β call other methods immediately afterβ’ All
on* listeners return an unsubscribe function β always call itβ’ Call
destroy() on unmount to remove all listenersβ’ All async calls timeout after 10 seconds β wrap in try/catch
β’ Never call
window.postMessage directlyβ’ Monetary values are strings β use
parseFloat() before arithmeticGet Current User
Returns the signed-in shell user's profile.
const user = await MBBridge.user.getUser();
// β { id, name, email, mobile?, role, ...}
Get Selected Company
Returns the company currently active in the shell.
const company = await MBBridge.company.getSelectedCompany();
// β { id, name, gstin?, ...}
Check Subscription
Returns whether the company has an active paid plan.
const isPaid = await MBBridge.subscription.isSubscribed();
// β true | false
Subscription Gate Pattern
Check subscription and show paywall if not subscribed.
const isPaid = await MBBridge.subscription.isSubscribed();
if (!isPaid) {
MBBridge.paywall.showPaywall();
const unsub = MBBridge.paywall.onPaymentSuccess(() => {
unsub();
// retry your feature
});
return;
}
// proceed with feature
Get Auth Token
Get the shell user's JWT for calling your own backend.
const token = await MBBridge.auth.getToken();
// β string (JWT)
// Use with your backend:
const res = await fetch('/api/data', {
headers: { Authorization: `Bearer ${token}` },
});
Get Paginated Items
Get Paginated Vouchers
Quick filter presets:
Unpaid Invoices
Overdue
Purchases YTD
Open Quotations
Expenses
Online Store Orders
Show Toast Notifications
The shell renders the toast β you do not need to build UI for it.
MBBridge.notification.showSuccess({ message: 'Saved!', duration: 3000 });
MBBridge.notification.showWarning({ message: 'Check your input.' });
MBBridge.notification.showError({ message: 'Something went wrong.' });
Paywall 5 Events
Trigger the shell's payment overlay and listen for lifecycle events.
onPaywallOpen
Overlay opened
onPaymentInit
User started payment
onPaymentSuccess
Payment succeeded
onPaymentFailed
Payment failed
onPaywallClosed
Overlay dismissed
MBBridge.paywall.showPaywall();
const unsubSuccess = MBBridge.paywall.onPaymentSuccess(() => {
unsubSuccess(); // always unsubscribe when done
});
const unsubFailed = MBBridge.paywall.onPaymentFailed(() => { unsubFailed(); });
const unsubClosed = MBBridge.paywall.onPaywallClosed(() => { unsubClosed(); });
Log Product Event Business
Log business/product events to Amplitude or CleverTap.
MBBridge.events.logProductEvent({
eventName: 'invoice_created',
platforms: ['amplitude', 'clevertap'], // optional, defaults to ['amplitude']
properties: { invoiceId: 'INV-001', amount: 5000, tags: ['gst', 'b2b'] },
});
Log Tech Event Infrastructure
Log technical/infra events (errors, performance, SDK lifecycle).
MBBridge.events.logTechEvent({
eventName: 'api_timeout',
properties: { feature: 'items', durationMs: 10000 },
});
emit() β Fire and Forget
Send a custom message to the shell with no response expected.
MBBridge.emit({ type: 'MBB_MY_CUSTOM_EVENT', payload: { foo: 'bar' } });
request() β Await Shell Response
Send a custom request and await the shell's typed response.
const res = await MBBridge.request({
type: 'MBB_MY_QUERY',
responseType: 'MBB_MY_QUERY_SUCCESS',
payload: { id: '123' },
timeoutMs: 5000,
});
console.log(res.data);
on() / off() β Subscribe to Shell Events
Listen for shell-initiated messages of a specific type.
Not listening
const unsub = MBBridge.on({
type: 'MBB_SOME_SHELL_EVENT',
callback: (msg) => console.log(msg.data),
});
// Later:
unsub(); // or MBBridge.off({ type, callback })
Activity Log
Clear
No activity yet.
Initialise the SDK to begin.
Initialise the SDK to begin.