@dsr4ai/miva-bdn-sdk
v0.0.6
Published
MivaBDN SDK provides an easy way to embed the **Miva BDN iframe** in a web application.
Readme
MivaBDN SDK
MivaBDN SDK provides an easy way to embed the Miva BDN iframe in a web application.
Installation
npm install @dsr4ai/miva-bdn-sdkGetting Started
Using with ES Modules
To get started with ES Modules, simply import the module and use it in your code:
import MivaBDN from '@dsr4ai/miva-bdn-sdk';Using with UMD Modules
Alternatively, if you're using UMD modules, include the script in your HTML file:
<script src="https://unpkg.com/@dsr4ai/miva-bdn-sdk/dist/index.umd.js"></script>After importing, you can initialize and use the SDK as follows:
const mivaBDN = new MivaBDN({
appId: 'your-app-id', // your Miva BDN app ID
target: '#app', // container selector
debug: true, // optional debug mode
locale: 'ja', // optional locale
});
// Initializes the iframe and starts message listening
mivaBDN.init();
// Removes the iframe and event listeners when no longer needed
// mivaBDN.destroy();Manual Integration
For manual integration, refer to the implementation in src/manual.js.
Usage
Loading a Single Book
You can load a single book in the Miva BDN iframe by specifying the path and sourceId when initializing the MivaBDN instance.
const mivaBDN = new MivaBDN({
appId: 'your-app-id', // your Miva BDN app ID
target: '#app', // container selector
debug: true, // optional debug mode
locale: 'ja', // optional locale
path: '/library', // Path inside the iframe to load the book
sourceId: 'source-id', // ID of the book to load
});
// Initializes the iframe and starts message listening
mivaBDN.init();API
new MivaBDN(options: MivaBDNOptions)
Creates a new MivaBDN instance that manages the iframe.
Options
Property | Type | Description
--- | --- | ---
appId | string | Unique application identifier.
baseUrl | string | Base URL of the Miva BDN loaded in the iframe.
debug | boolean | Enables verbose logging.
onConfirmed | (data: unknown, instance: MivaBDN) => void | Called when the iframe signals a confirmed event.
onReady | (data: unknown, instance: MivaBDN) => void | Called when the iframe signals a ready event.
path | string | The relative path to be appended to baseUrl when constructing the iframe URL. Should not include protocol or hostname.
locale | string | Locale passed to the Miva application.
sourceId | string \| string[] | The identifier(s) provided to the Miva application as content source metadata. Can be a single ID string or an array for multiple sources.
sourceScope | SourceScope | Controls which source scopes are loaded by the Miva application. Options: public, private, all.
target | HTMLElement \| string | DOM element or CSS selector where the iframe is mounted.
Methods
init(): void
Initializes the iframe and starts message listening.destroy(): void
Removes the iframe and event listeners when no longer needed.
Error Handling
All critical errors, such as missing required options or invalid targets, are thrown as instances of MivaBDNError.
Security
The SDK verifies the origin of all incoming messages to ensure only messages from the trusted iframe are processed. Messages from untrusted sources are ignored.
License
MIT
