Node.js SDK
The @insigner/node SDK provides a typed client for the inSigner Cloud API with built-in error handling, automatic pagination, and TypeScript support.
Installation
Section titled “Installation”npm install @insigner/nodeQuick start
Section titled “Quick start”import { InSigner } from '@insigner/node';
const client = new InSigner({ apiKey: process.env.INSIGNER_API_KEY! // isk_...});
// Create and send a documentconst doc = await client.documents.create({ name: 'Sales Agreement Q3', signingType: 'sequential'});
// Upload PDFawait client.documents.upload(doc.id, { file: './sales-agreement.pdf'});
// Add signersawait client.documents.addSigner(doc.id, { name: 'Jane Smith', role: 'signer', order: 0});
// Add fieldsawait client.documents.addField(doc.id, { type: 'signature', label: 'Client Signature', page: 1, x: 100, y: 650, width: 200, height: 60});
// Send for signingawait client.documents.send(doc.id);Using fetch directly
Section titled “Using fetch directly”Until the SDK is released, use the REST API directly:
const INSIGNER_API = 'https://app.insigner.co/api/v1';const API_KEY = process.env.INSIGNER_API_KEY;
async function insignerFetch(path: string, options: RequestInit = {}) { const res = await fetch(`${INSIGNER_API}${path}`, { ...options, headers: { 'Authorization': `Bearer ${API_KEY}`, 'Content-Type': 'application/json', ...options.headers, }, });
if (!res.ok) { const error = await res.json(); throw new Error(`${error.title}: ${error.detail}`); }
if (res.status === 204) return null; return res.json();}
// Example: List documentsconst { data, meta } = await insignerFetch('/documents?limit=10');
// Example: Create a documentconst { data: doc } = await insignerFetch('/documents', { method: 'POST', body: JSON.stringify({ name: 'My Document' }),});Error handling
Section titled “Error handling”try { await client.documents.send('invalid-id');} catch (error) { if (error instanceof InSignerError) { console.error(`${error.status}: ${error.detail}`); // Handle specific error types if (error.type === 'https://docs.insigner.com/errors/not-found') { console.error('Document not found'); } }}Pagination
Section titled “Pagination”// Auto-paginate through all documentsfor await (const doc of client.documents.list({ status: 'completed' })) { console.log(doc.name);}
// Or get a single pageconst page = await client.documents.list({ limit: 10, cursor: 'cm5x9abc123'});console.log(page.data, page.meta);