@blueink360/blueink-embed-js
v1.2.2
Published
Embedded eSignatures with BlueInk
Downloads
223
Readme
BlueInk Embed JS Library
A Javascript library to create embedded signing sessions with the BlueInk API.
Installation
From NPM:
npm install @blueink360/blueink-embed-js
Or if you prefer yarn:
yarn add @blueink360/blueink-embed-js
From CDN:
<script src="https://cdn.jsdelivr.net/npm/@blueink360/blueink-embed-js/dist/blueink-embed.min.js"></script>
If including this library directly with a script tag, the BlueInkEmbed
class will be added to the global namespace.
Usage
To use the library, you will need a public API key from your BlueInk account. If you do not have a BlueInk account, you can create one here. You can send unlimited test Bundles for free while developing your eSignature integration.
Quickstart
import BlueInkEmbed from 'blueink-embed-js';
const embedUrl = 'EMBED-URL-RETURNED-BY-THE-SERVER';
const embed = new BlueInkEmbed('YOUR-PUBLIC-API-KEY');
// Mount the embedded signing iFrame in a div with ID 'iframe-container'
embed.mount(embedUrl, '#iframe-container');
// Optionally, unmount the signing iFrame when done
embed.unmount();
Fuller Example, with Error and Event Handling
This example shows fetching the embedUrl from the server via axios, and handling errors.
import BlueInkEmbed from 'blueink-embed-js';
const exampleRequestData = {
signerName: 'Frank Ricard',
signerEmail: '[email protected]'
};
// This assumes that your server-side App can receive requests
// at /get-embed-url and will create a new Bundle and return
// an embedded signing URL. See the BlueInk API docs for examples.
axios.post('/get-embed-url', exampleRequestData)
.then(response => {
try {
const embedUrl = response.data.embedUrl;
const embed = new BlueInkEmbed('YOUR-BLUEINK-PUBLIC-API-KEY');
// Setup event listeners to respond to events emitted
// by the embedded signing iFrame
embed.on(BlueInkEmbed.EVENT.COMPLETE, () => {
console.log('signing complete!');
});
embed.on(BlueInkEmbed.EVENT.ERROR, (eventData) => {
console.log('Signing error occurred.');
console.log(eventData.message);
});
embed.mount(embedUrl, '#iframe-container');
} catch(error) {
// An error could be thrown if the public API key is invalid,
// or if no element was found with id 'iframe-container'
console.log(error.message);
}
})
.catch(error => {
// This catch block would handle if the /get-embed-url
// request returned a 5XX or 4XX error.
const message = error.response.data.error || error.message;
console.log(message);
});
More Resources
Getting Help / Contributing
If you have a BlueInk Account and need help integrating this library into your API project, please contact our support team from your BlueInk account dashboard.
If you find issues in this codebase, or have any suggestions for improvement please create an issue here on github.
We welcome contributions and will consider any pull requests.
If you are making modifications to the library, or running the project,
locally the following commands should come in handy. We use yarn internally,
but all of the commands below should work with there npm
equivalents.
# Run the tests
$ yarn test
$ yarn test:coverage
# Build a production, minified version of the library
$ yarn run build
# Build a development, unminified version of the library
$ yarn run build:dev
# Run webpack-dev-server, so that the library will be accessible
# at http://localhost:8080/blueink-embed.js
$ yarn run devserver
# Build the docs
$ yarn run build:docs
License
MIT