docs-dispatcher-sdk
v0.11.0
Published
Typescript lib to consume docs-dispatcher.io API services
Readme
DocsDispatcher JS Client
Official JavaScript/TypeScript SDK for the DocsDispatcher API.
Features
- 📧 Email Dispatch - Send templated emails
- 📄 File Generation - Generate PDFs, DOCX, XLSX, and more
- 📱 SMS Dispatch - Send SMS messages
- 📮 Postal Dispatch - Send physical mail
- ✍️ E-Signature - Electronic signature workflows
- 🧾 Invoice Generation - Create invoices, quotes, and credit notes (v0.7.0+)
- 🔐 JWT Authentication - Modern Bearer token auth (v0.7.0+)
- 📦 Upload & Targets - Upload to Zoho CRM, Universal targets
- 🎯 TypeScript - Full type safety and IntelliSense support
Installation
yarn add docs-dispatcher-sdkor
npm install docs-dispatcher-sdkQuick Start
Basic Authentication
import DocsDispatcher from 'docs-dispatcher-sdk'
// Simple setup with username/password
const dd = DocsDispatcher.create({
username: 'your-username',
password: 'your-password'
})
// Check API health
await dd.healthCheck()Bearer Token Authentication (Recommended)
import DocsDispatcher, { BearerAuth } from 'docs-dispatcher-sdk'
import axios from 'axios'
const auth = new BearerAuth('your-jwt-token')
const http = new DocsDispatcher.Http.AxiosAdapter(axios)
const dd = new DocsDispatcher(auth, http)Usage Examples
Send an Email
import { MailDispatcher } from 'docs-dispatcher-sdk'
const email = new DocsDispatcher.Service.MailDispatcher({
from: '[email protected]',
to: ['[email protected]'],
subject: 'Hello from DocsDispatcher',
templateName: 'welcome-email',
data: {
username: 'John Doe',
activationLink: 'https://example.com/activate'
}
})
await dd.withBaseService(email).dispatch()Generate a PDF Invoice
import {
InvoiceDocumentType,
CustomerType,
DiscountType
} from 'docs-dispatcher-sdk'
// Build customer
const customer = new DocsDispatcher.Builder.InvoiceCustomerBuilder()
.asCompany('Acme Corporation')
.withEmail('[email protected]')
.withBillingAddress({
street1: '123 Business Ave',
city: 'New York',
zipCode: '10001',
country: 'US'
})
.withVatNumber('US123456789')
.build()
// Build invoice items
const items = [
new DocsDispatcher.Builder.InvoiceItemBuilder('Consulting Services', 150.00)
.withQuantity(10)
.withTaxPercent(20)
.withDiscount(DiscountType.PERCENTAGE, 10, '10% volume discount')
.build(),
new DocsDispatcher.Builder.InvoiceItemBuilder('Support Plan', 500.00)
.withTaxPercent(20)
.build()
]
// Create invoice
const invoice = new DocsDispatcher.Service.InvoiceDispatcher({
customer,
items,
documentType: InvoiceDocumentType.INVOICE,
issueDate: '2025-01-15',
provider: 'ipaidthat', // or 'qonto', 'stripe'
sendByEmail: true,
paymentTerms: 30,
notes: 'Thank you for your business!',
discount: {
type: DiscountType.ABSOLUTE,
value: 50,
description: 'Early payment discount'
}
})
// Set result format to PDF
invoice.setResultFormat(DocsDispatcher.RETURN_FORMATS.PDF)
// Dispatch invoice
const response = await dd.withBaseService(invoice).dispatch()Send an SMS
const sms = new DocsDispatcher.Service.SMSDispatcher({
to: '+1234567890',
smsContent: 'Your verification code is: 123456',
provider: 'SMS_FACTOR'
})
await dd.withBaseService(sms).dispatch()Generate a Document from Template
const file = new DocsDispatcher.Service.FileDispatcher()
.setTemplateName('contract-template')
.setResultFileName('contract-signed.pdf')
.setData({
clientName: 'John Doe',
contractDate: '2025-01-15',
amount: '$10,000'
})
.setResultFormat(DocsDispatcher.RETURN_FORMATS.PDF)
await dd.withBaseService(file).dispatch()E-Signature Workflow
const esign = new DocsDispatcher.Service.ESignDispatcher({
documentName: 'Service Agreement',
signatureType: 'ADVANCED', // or 'SIMPLE', 'QUALIFIED'
signers: [
{
firstname: 'John',
lastname: 'Doe',
email: '[email protected]',
phoneNumber: '+1234567890'
}
]
})
.setTemplateName('agreement-template')
.setData({ agreementDate: '2025-01-15' })
await dd.withBaseService(esign).dispatch()Upload to CRM Target
import { TargetTypes } from 'docs-dispatcher-sdk'
const file = new DocsDispatcher.Service.FileDispatcher()
.setTemplateName('report-template')
.setData({ reportMonth: 'January' })
.addTarget({
id: 'crm-contact-id',
type: 'contact',
target: TargetTypes.ZohoCrm
})
await dd.withBaseService(file).dispatch()Advanced Features
Customer Type Examples
Individual Customer
const individual = new DocsDispatcher.Builder.InvoiceCustomerBuilder()
.asIndividual('John', 'Doe')
.withEmail('[email protected]')
.withBillingAddress(address)
.withDisplayName('John Doe')
.build()Company Customer
const company = new DocsDispatcher.Builder.InvoiceCustomerBuilder()
.asCompany('Tech Solutions Inc')
.withEmail('[email protected]')
.withRegistrationNumber('123456789')
.withVatNumber('US123456789')
.withBillingAddress(address)
.build()Freelance Customer
const freelance = new DocsDispatcher.Builder.InvoiceCustomerBuilder()
.asFreelance('Jane', 'Smith')
.withEmail('[email protected]')
.withBusinessName('Jane Smith Consulting')
.withRegistrationNumber('987654321')
.withVatNumber('FR987654321')
.withBillingAddress(address)
.build()Document Types
InvoiceDocumentType.INVOICE- Standard invoiceInvoiceDocumentType.E_INVOICE- Electronic invoiceInvoiceDocumentType.QUOTE- Quote/EstimateInvoiceDocumentType.CREDIT- Credit note
Validation
The SDK includes built-in validation:
const errors: ValidationError[] = []
const isValid = invoice.validate(errors)
if (!isValid) {
console.error('Validation errors:', errors)
// errors = [{ path: ['customer', 'email'], message: 'Customer email is required' }]
}Documentation
API Compatibility
- API v3.6.2+: Full support (BearerAuth, InvoiceDispatcher, Universal targets)
- API v3.6.1: Partial support (BasicAuth, legacy features)
- API v3.5.x: BasicAuth only, InvoiceDispatcher not available
Development
Onboarding
create new .env file from .env.dist to execute tests
Publishing new version
yarn version --new-version x.y.z- rebase main on this tag
- trigger pipeline on main
