@narrow-os/document-templates 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +177 -0
- package/dist/index.d.mts +558 -0
- package/dist/index.d.ts +558 -0
- package/dist/index.js +2482 -0
- package/dist/index.mjs +2410 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# @bizflow/document-templates
|
|
2
|
+
|
|
3
|
+
Universal, framework-agnostic document templates and HTML/PDF generators for **Invoices**, **Quotations**, **Retail POS Receipts**, and **Delivery Notes**.
|
|
4
|
+
|
|
5
|
+
Designed to run seamlessly across:
|
|
6
|
+
|
|
7
|
+
- **Node.js / NestJS** (for automated background emails, cron jobs, and Puppeteer PDF generation)
|
|
8
|
+
- **Next.js Server & Client** (App Router, Pages, SSR, API routes)
|
|
9
|
+
- **Browsers & POS Terminals** (Direct printing, thermal receipt printing, live canvas-free preview)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- 🎨 **10 Distinct A4 Design Presets**: `classic`, `modern`, `minimal`, `corporate`, `bold`, `elegant`, `tech`, `vibrant`, `compact`, and `mono`.
|
|
16
|
+
- 🧾 **10 Thermal Receipt Presets**: `classic`, `compact`, `wide`, `dense`, `sparse`, `boxed`, `lined`, `split`, `monobold`, and `elegant` (for 80mm & 58mm thermal receipt printers).
|
|
17
|
+
- 🇿🇦 **South African 15% VAT & Multi-Currency Ready**: Built-in compliant tax calculation, deposit breakdowns, installment terms, and banking payment instructions.
|
|
18
|
+
- âš¡ **Zero DOM Canvas Crashes**: Built-in vector SVG Code 128 barcode and QR code generators that run headlessly in pure Node.js without requiring `<canvas>` or native DOM bindings.
|
|
19
|
+
- 📦 **Framework Agnostic**: Pure TypeScript returning clean HTML strings ready for `puppeteer.page.setContent(html)` or `window.open().document.write(html)`.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
### Local Installation in Monorepo / Relative Path
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install ../packages/document-templates
|
|
29
|
+
# or from root
|
|
30
|
+
npm install ./packages/document-templates
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### When Published to npm
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install @bizflow/document-templates
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Quick Start
|
|
42
|
+
|
|
43
|
+
### 1. Generating an Invoice HTML
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import {
|
|
47
|
+
InvoiceReportGenerator,
|
|
48
|
+
generateInvoiceHTML,
|
|
49
|
+
} from "@bizflow/document-templates";
|
|
50
|
+
|
|
51
|
+
const invoiceHtml = await generateInvoiceHTML(
|
|
52
|
+
{
|
|
53
|
+
id: "inv-001",
|
|
54
|
+
invoiceNumber: "INV-2026-001",
|
|
55
|
+
issueDate: new Date(),
|
|
56
|
+
dueDate: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000),
|
|
57
|
+
status: "SENT",
|
|
58
|
+
client: {
|
|
59
|
+
name: "Acme Industrial Pty Ltd",
|
|
60
|
+
email: "accounts@acme.co.za",
|
|
61
|
+
address: "10 Industrial Way",
|
|
62
|
+
city: "Johannesburg",
|
|
63
|
+
province: "Gauteng",
|
|
64
|
+
taxNumber: "4990123456",
|
|
65
|
+
},
|
|
66
|
+
items: [
|
|
67
|
+
{
|
|
68
|
+
id: "item-1",
|
|
69
|
+
description: "Industrial Water Pump Installation",
|
|
70
|
+
quantity: 1,
|
|
71
|
+
unitPrice: 15000,
|
|
72
|
+
amount: 15000,
|
|
73
|
+
taxRate: 15,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
id: "item-2",
|
|
77
|
+
description: "Standard Fitting & Labor",
|
|
78
|
+
quantity: 4,
|
|
79
|
+
unitPrice: 850,
|
|
80
|
+
amount: 3400,
|
|
81
|
+
taxRate: 15,
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
templateId: "modern", // 'classic' | 'modern' | 'minimal' | 'corporate' | 'bold' | 'elegant' | 'tech' | 'vibrant' | 'compact' | 'mono'
|
|
87
|
+
companyInfo: {
|
|
88
|
+
companyName: "NECS Engineers Pty Ltd",
|
|
89
|
+
taxId: "4001234567",
|
|
90
|
+
address: "45 Technology Park",
|
|
91
|
+
city: "Pretoria",
|
|
92
|
+
phone: "+27 12 345 6789",
|
|
93
|
+
email: "billing@necs.co.za",
|
|
94
|
+
bankName: "First National Bank",
|
|
95
|
+
bankAccount: "62000012345",
|
|
96
|
+
},
|
|
97
|
+
combineServices: true,
|
|
98
|
+
},
|
|
99
|
+
);
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### 2. Generating Quotations
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { generateQuotationHTML } from "@bizflow/document-templates";
|
|
106
|
+
|
|
107
|
+
const quoteHtml = await generateQuotationHTML(quotationData, {
|
|
108
|
+
templateId: "corporate",
|
|
109
|
+
companyInfo: myCompany,
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### 3. Printing POS Receipts (A4 & Thermal 80mm)
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import { receiptGenerator } from "@bizflow/document-templates";
|
|
117
|
+
|
|
118
|
+
// Thermal 80mm
|
|
119
|
+
const thermalHtml = await receiptGenerator.generateReceiptHTML(
|
|
120
|
+
saleData,
|
|
121
|
+
"thermal",
|
|
122
|
+
true,
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
// Standard A4 Tax Receipt
|
|
126
|
+
const a4ReceiptHtml = await receiptGenerator.generateReceiptHTML(
|
|
127
|
+
saleData,
|
|
128
|
+
"A4",
|
|
129
|
+
false,
|
|
130
|
+
);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### 4. Headless PDF Generation in Node.js / NestJS
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
import puppeteer from "puppeteer";
|
|
137
|
+
import { generateInvoiceHTML } from "@bizflow/document-templates";
|
|
138
|
+
|
|
139
|
+
const html = await generateInvoiceHTML(invoice, { companyInfo });
|
|
140
|
+
|
|
141
|
+
const browser = await puppeteer.launch({ args: ["--no-sandbox"] });
|
|
142
|
+
const page = await browser.newPage();
|
|
143
|
+
await page.setContent(html, { waitUntil: "load" });
|
|
144
|
+
const pdfBuffer = await page.pdf({
|
|
145
|
+
format: "A4",
|
|
146
|
+
printBackground: true,
|
|
147
|
+
margin: { top: "0.5in", right: "0.5in", bottom: "0.5in", left: "0.5in" },
|
|
148
|
+
});
|
|
149
|
+
await browser.close();
|
|
150
|
+
|
|
151
|
+
// pdfBuffer is ready to attach to Resend, SendGrid, or nodemailer!
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Publishing to npm
|
|
157
|
+
|
|
158
|
+
To publish this package to npm:
|
|
159
|
+
|
|
160
|
+
1. Build the distribution bundle:
|
|
161
|
+
```bash
|
|
162
|
+
npm run build
|
|
163
|
+
```
|
|
164
|
+
2. Login to npm:
|
|
165
|
+
```bash
|
|
166
|
+
npm login
|
|
167
|
+
```
|
|
168
|
+
3. Publish:
|
|
169
|
+
```bash
|
|
170
|
+
npm publish --access public
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## License
|
|
176
|
+
|
|
177
|
+
MIT © Rethynk Web Studio
|