@emilgroup/document-uploader
v0.0.9
Published
TypeScript NPM Module to upload document to EMIL Document Service
Downloads
10
Readme
Document Uploader
This is a Node.js module that provides functionality for uploading documents to an insurance service. It uses the DocumentUploader class to handle authentication and document uploading.
Installation
Installation To use this module, you need to have Node.js installed on your machine. Once you have that set up, you can install the module using npm:
npm install @emilgroup/document-uploader
Usage
To use the DocumentUploader class, you need to create a new instance with your login credentials and the environment you want to use (Environment.Test for testing or Environment.Production for production):
const uploader = new DocumentUploader('[email protected]', 'password', Environment.Test);
You also need to provide a file to upload. This example uses the fs module to read the file and get its size:
const file = fs.createReadStream('test.pdf');
const size = fs.statSync('test.pdf').size;
Finally, you can upload the document by calling the uploadDocument method:
(async () => {
const document = await uploader.uploadDocument(
{
templateSlug: 'upload',
entityType: 'Document',
description: 'Customer document',
requester: 'insuranceservice',
filename: 'test.pdf',
},
file,
size,
);
})();
Expected response: Optionally is possible to pass extra params to the payload, The field productSlug used to upload documents per product, super useful if we have multiple products:
{
productSlug: 'homeowner',
}
The field entityId used to upload documents that's belong to example (claims, policies, accounts, etc...) entity:
{
entityId: 20
}
The field policyCode is optional to indicate if the document belongs to a policy:
{
policyCode: `pol_Dl5TVWMLhjM7B9`
}
This method takes an object with metadata about the document (including a template slug, entity type, description, and filename), the file itself as a readable stream, and the file size.
License
This module is licensed under the MIT License. See the LICENSE file for more information.