@esrating/embed-js
v0.1.0
Published
ESRating embed widget — drop-in insurance quoting iframe SDK for partner sites.
Downloads
27
Maintainers
Readme
@esrating/embed-js
Drop-in JavaScript SDK for embedding ESRating insurance quoting into any website. ~30 KB gzipped, no runtime dependencies, works as a <script> tag or via npm install.
Installation
npm install @esrating/embed-jsOr via the CDN:
<script src="https://embed.esrating.com/v1/embed.umd.js"></script>Quick start
<div id="esr"></div>
<script>
ESRating.mount('#esr', {
publishableKey: 'pk_live_xxx',
fetchSessionUrl: async () => {
const res = await fetch('/api/start-insurance-session', { method: 'POST' });
const data = await res.json();
return data.session_url;
},
onBound: (policy) => {
window.location.href = `/policy/${policy.number}`;
},
});
</script>Your backend mints a session URL by calling POST /v1/embed/sessions with your sk_* key:
// In your server (Node example)
import { Stripe } from 'stripe';
app.post('/api/start-insurance-session', async (req, res) => {
const result = await fetch('https://api.esrating.com/v1/embed/sessions', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.ESRATING_SK_LIVE}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
user_id: req.user.id,
email: req.user.email,
metadata: { partnerOrderId: req.user.orderId },
}),
});
res.json(await result.json());
});API
See MountOptions in dist/index.d.ts for the full type. Key options:
sessionUrl— pre-minted session URL (alternative tofetchSessionUrl)publishableKey—pk_*for analytics/theming hintsfetchSessionUrl— async callback returning a session URLview—'quote' | 'policy' | 'endorsement' | 'dashboard'chrome—'hidden' | 'minimal' | 'full'theme—'light' | 'dark' | 'auto'prefill— pre-fill the quote form withRecord<string, unknown>onReady,onQuote,onBound,onPayment,onSignature,onError,onAbandoned
The returned MountedWidget exposes iframe, reload(), destroy(), navigate(view), and getCurrentHeight().
License
Apache-2.0. See esrating.com/docs for the full embedding contract.
