medusajs-documents-plugin 0.0.0-stage → 1.1.2
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/.medusa/server/src/admin/index.js +2441 -0
- package/.medusa/server/src/admin/index.mjs +2442 -0
- package/.medusa/server/src/api/admin/documents/[id]/document/route.js +36 -0
- package/.medusa/server/src/api/admin/documents/[id]/send/route.js +41 -0
- package/.medusa/server/src/api/admin/documents/[id]/sync-zoho/route.js +68 -0
- package/.medusa/server/src/api/admin/documents/custom/route.js +48 -0
- package/.medusa/server/src/api/admin/documents/manual/route.js +46 -0
- package/.medusa/server/src/api/admin/documents/route.js +36 -0
- package/.medusa/server/src/api/admin/documents/settings/route.js +44 -0
- package/.medusa/server/src/api/admin/documents/templates/preview/route.js +159 -0
- package/.medusa/server/src/api/admin/documents/zoho/list/route.js +51 -0
- package/.medusa/server/src/api/documents/[id]/document/route.js +36 -0
- package/.medusa/server/src/api/documents/r/[code]/route.js +29 -0
- package/.medusa/server/src/api/documents/templates/preview/route.js +159 -0
- package/.medusa/server/src/api/store/documents/r/[code]/route.js +22 -0
- package/.medusa/server/src/index.js +27 -0
- package/.medusa/server/src/modules/documents/index.js +13 -0
- package/.medusa/server/src/modules/documents/migrations/Migration20261012164601.js +23 -0
- package/.medusa/server/src/modules/documents/migrations/Migration20261014150000.js +20 -0
- package/.medusa/server/src/modules/documents/migrations/Migration20261015160000.js +46 -0
- package/.medusa/server/src/modules/documents/models/document-link.js +12 -0
- package/.medusa/server/src/modules/documents/models/document-record.js +33 -0
- package/.medusa/server/src/modules/documents/models/document-settings.js +79 -0
- package/.medusa/server/src/modules/documents/service.js +587 -0
- package/.medusa/server/src/services/notification-sender.js +612 -0
- package/.medusa/server/src/services/order-notification-templates.js +510 -0
- package/.medusa/server/src/services/pdf-post-processor.js +64 -0
- package/.medusa/server/src/services/pdfkit-generator.js +438 -0
- package/.medusa/server/src/services/zoho-books.js +221 -0
- package/.medusa/server/src/subscribers/order-documents.js +424 -0
- package/.medusa/server/src/subscribers/repair-documents.js +216 -0
- package/.medusa/server/src/utils/integrate.js +37 -0
- package/.medusa/server/src/utils/payment-link.js +69 -0
- package/.medusa/server/src/workflows/create-manual-document.js +27 -0
- package/.medusa/server/src/workflows/generate-document.js +24 -0
- package/.medusa/server/src/workflows/index.js +20 -0
- package/.medusa/server/src/workflows/send-document-notification.js +41 -0
- package/CHANGELOG.md +87 -0
- package/LICENSE +21 -0
- package/README.md +201 -2
- package/package.json +86 -4
package/README.md
CHANGED
|
@@ -1,3 +1,202 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Medusa v2 Documents Plugin (`medusajs-documents-plugin`)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A powerful, production-ready document generation, accounting, and multi-channel notification plugin for **Medusa v2**, modeled after `@rsc-labs/medusa-documents-v2` with deep **Zoho Books** accounting integration, **PDFKit multi-template fallback**, **Paystack QR codes & short payment links**, **Medusa Workflows**, and a **unified Admin Documents Hub**.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Key Features
|
|
8
|
+
|
|
9
|
+
1. **Unified Documents Hub**
|
|
10
|
+
- Access all invoices, payment receipts, quotations/estimates, packing slips, and custom certificates in one single Medusa Admin tab.
|
|
11
|
+
- Eliminates the need to switch back and forth into the Zoho Books app for day-to-day document lookup.
|
|
12
|
+
- Includes full-text search, type filtering, source filtering (Zoho vs PDFKit), and direct actions: View PDF, Send Notification, Push to Zoho, and Copy Short Link.
|
|
13
|
+
|
|
14
|
+
2. **Zoho Books Integration & Exposed Customizations**
|
|
15
|
+
- Official Zoho Books API v3 integration with automated OAuth access token refreshing.
|
|
16
|
+
- Contacts, Invoices, and Estimates automatically sync to your Zoho organization.
|
|
17
|
+
- Exposes common Zoho customizations directly in the plugin settings (Terms & Conditions, Customer Notes, Net Payment Due Days, Tax Inclusive/Exclusive treatment, Invoice Prefix) so you don't have to open Zoho Books to tweak them.
|
|
18
|
+
|
|
19
|
+
3. **PDFKit Fallback with Multiple Design Templates**
|
|
20
|
+
- Automatically takes over when Zoho Books is disabled, credentials are unset, or for documents that Zoho doesn't support (such as Packing Slips and Custom Warranty Certificates).
|
|
21
|
+
- Choose between 3 distinct aesthetic templates in the **PDF Templates** tab:
|
|
22
|
+
- **Modern Minimalist**: Crisp headers, subtle borders, accent banners, and modern typography.
|
|
23
|
+
- **Classic Corporate**: Traditional formal grid, serif typography, double border lines.
|
|
24
|
+
- **Clean Tech Monospace**: High-contrast, monospace typography optimized for hardware, repairs, and technical orders.
|
|
25
|
+
- Instant live PDF preview button for each template directly in Admin.
|
|
26
|
+
|
|
27
|
+
4. **Paystack Payment Links & Embedded QR Codes**
|
|
28
|
+
- For all unpaid documents (orders with remaining balance or repair tickets):
|
|
29
|
+
- Computes exact balance due.
|
|
30
|
+
- Generates secure Paystack storefront HMAC checkout URL (`/pay/:hash/:order_id` or `/repairs/track?token=...`).
|
|
31
|
+
- Shortens the link to keep text messages clean.
|
|
32
|
+
- Appends the payment link directly to Zoho invoice notes and custom fields.
|
|
33
|
+
- Embeds a scan-to-pay QR code onto the top right of the PDF invoice!
|
|
34
|
+
|
|
35
|
+
5. **Automations & Captured Events Tab**
|
|
36
|
+
- Dedicated tab in the Admin UI with on/off switches for each event subscriber:
|
|
37
|
+
- `order.placed`: Autogenerates Tax Invoice + QR payment link.
|
|
38
|
+
- `order.completed`: Autogenerates Packing Slip.
|
|
39
|
+
- `payment.captured`: Autogenerates Payment Receipt.
|
|
40
|
+
- `order.fulfillment_created`: Autogenerates Packing Slip.
|
|
41
|
+
- `repair.status_changed`: Autogenerates updated repair invoice or quote.
|
|
42
|
+
- `repair.ticket.compliance_requested`: Autogenerates Quotation.
|
|
43
|
+
- `repair.created`: Autogenerates initial Job Card / Estimate.
|
|
44
|
+
- `repair.completed`: Autogenerates final Repair Invoice.
|
|
45
|
+
- `repair.customer_reminder`: Nudges customer with document link.
|
|
46
|
+
|
|
47
|
+
6. **Custom Document Creator with Direct Email Delivery**
|
|
48
|
+
- Create custom certificates (e.g. Warranty Certificates, Work Orders, Proforma Invoices, Agreements) with custom body text and optional line items.
|
|
49
|
+
- Immediately dispatches the document PDF link and customized message to the customer's email via the Medusa notification module.
|
|
50
|
+
|
|
51
|
+
7. **Multi-Channel Dispatch Optimized for Email, SMS & WhatsApp**
|
|
52
|
+
- **Email**: Responsive HTML email with document branding, summary, action buttons (download PDF, pay online if unpaid).
|
|
53
|
+
- **SMS**: Concise SMS message with company name, doc reference, amount, due status, and short links.
|
|
54
|
+
- **WhatsApp**: Clean message with emojis, bold formatting, and short links.
|
|
55
|
+
|
|
56
|
+
8. **Shortened Links Engine**
|
|
57
|
+
- Database model & public route (`/api/store/documents/r/:code`) providing 302 redirection for clean, short messages.
|
|
58
|
+
|
|
59
|
+
9. **Inter-Plugin Delegation Helper**
|
|
60
|
+
- Exported helper function `delegateDocumentGeneration` allowing `medusajs-repairshop-plugin` or custom checkout modules to resolve `documents` and offload document creation.
|
|
61
|
+
|
|
62
|
+
10. **Medusa v2 Workflows**
|
|
63
|
+
- `generateDocumentWorkflow`: Full compensation-safe document generation pipeline.
|
|
64
|
+
- `sendDocumentNotificationWorkflow`: Multi-channel notification pipeline.
|
|
65
|
+
- `createManualDocumentWorkflow`: Manual document creation pipeline.
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## How to Enable the Zoho QR Code Feature
|
|
70
|
+
|
|
71
|
+
Our plugin gives you two complementary ways to enable and display QR codes on Zoho invoices:
|
|
72
|
+
|
|
73
|
+
### Method A: Plugin Automatic QR Code Embedding (Recommended)
|
|
74
|
+
Our plugin automatically embeds a high-resolution, scan-to-pay Paystack QR code on the top-right corner of the generated Zoho PDF, and includes the short payment link in the Zoho invoice customer notes:
|
|
75
|
+
1. In the Medusa Admin sidebar, open **Documents**.
|
|
76
|
+
2. Click the **Settings & Zoho** tab.
|
|
77
|
+
3. Under **Zoho Books Integration**, ensure **Enable Zoho Books Sync** is turned on.
|
|
78
|
+
4. Under **Exposed Zoho Invoice Customizations**, ensure **Embed Payment QR Code on Zoho Invoices** is switched **ON** (enabled by default).
|
|
79
|
+
5. (Optional) Set the **Custom Field Name for Payment Link** (e.g., `Payment Link`).
|
|
80
|
+
6. Click **Save All Settings**.
|
|
81
|
+
|
|
82
|
+
Whenever an invoice with an unpaid balance is generated, our post-processor streams the Zoho PDF, stamps the payment QR code on the top right, and adds the payment instructions directly into the document.
|
|
83
|
+
|
|
84
|
+
### Method B: Zoho Books Native Invoice QR Code Setting
|
|
85
|
+
If you also want Zoho Books' web portal and native email templates to display QR codes:
|
|
86
|
+
1. Log in to your [Zoho Books Dashboard](https://books.zoho.com).
|
|
87
|
+
2. Go to **Settings (Gear Icon)** > **Preferences** > **Invoices**.
|
|
88
|
+
3. Scroll down to the **Invoice QR Code** section and toggle it to **Enabled**.
|
|
89
|
+
4. Under **QR Code Type**, choose **Invoice URL** or **Custom**.
|
|
90
|
+
5. If using custom invoice templates, ensure the `%InvoiceQRCodeImage%` or `<img src="%InvQRCodeImgSrcURL%"/>` placeholder is positioned in your template header.
|
|
91
|
+
6. Click **Save** in Zoho Books.
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Installation & Setup
|
|
96
|
+
|
|
97
|
+
### 1. Add to `medusa-config.ts`
|
|
98
|
+
In your Medusa project's `medusa-config.ts` (or `medusa-config.js`):
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
module.exports = defineConfig({
|
|
102
|
+
plugins: [
|
|
103
|
+
{
|
|
104
|
+
resolve: "medusajs-documents-plugin",
|
|
105
|
+
options: {}
|
|
106
|
+
},
|
|
107
|
+
// other plugins...
|
|
108
|
+
],
|
|
109
|
+
modules: [
|
|
110
|
+
{
|
|
111
|
+
key: "documents",
|
|
112
|
+
resolve: "medusajs-documents-plugin",
|
|
113
|
+
options: {}
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### 2. Run Database Migrations
|
|
120
|
+
```bash
|
|
121
|
+
npx medusa db:migrate
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### 3. Build & Run
|
|
125
|
+
```bash
|
|
126
|
+
yarn build
|
|
127
|
+
yarn dev
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## Inter-Plugin Integration: How to Use in `medusajs-repairshop-plugin`
|
|
133
|
+
|
|
134
|
+
To delegate document generation from your repair plugin to this plugin:
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
import { delegateDocumentGeneration } from "medusajs-documents-plugin";
|
|
138
|
+
|
|
139
|
+
// Inside your repair endpoint or service:
|
|
140
|
+
const result = await delegateDocumentGeneration(container, {
|
|
141
|
+
display_id: `RT-${ticket.ticket_number}`,
|
|
142
|
+
title: "Repair Invoice",
|
|
143
|
+
type: "invoice",
|
|
144
|
+
repair_ticket_id: ticket.id,
|
|
145
|
+
customer: {
|
|
146
|
+
name: customer.first_name,
|
|
147
|
+
email: customer.email,
|
|
148
|
+
phone: customer.phone,
|
|
149
|
+
},
|
|
150
|
+
items: [
|
|
151
|
+
{ title: "OEM Screen Replacement", quantity: 1, unit_price: 150 },
|
|
152
|
+
{ title: "Labor Fee", quantity: 1, unit_price: 45 }
|
|
153
|
+
],
|
|
154
|
+
total: 195,
|
|
155
|
+
currency_code: "usd",
|
|
156
|
+
payment_link: `https://store.example.com/repairs/track?token=${ticket.approval_token}`,
|
|
157
|
+
auto_send: true,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
if (result) {
|
|
161
|
+
// Successfully generated through Documents plugin (via Zoho or PDFKit)!
|
|
162
|
+
console.log("Generated Document ID:", result.record.id);
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## Running Automated Tests
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
yarn test
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Runs the 6 unit and integration test suites:
|
|
175
|
+
- PDFKit Generator (Modern, Classic, Minimal templates & Custom documents)
|
|
176
|
+
- PDF Post-Processor (QR Code embedding, watermark validation)
|
|
177
|
+
- Payment Link Generator (HMAC calculation & balance due validation)
|
|
178
|
+
- Zoho Books Service (OAuth & API payload mapping)
|
|
179
|
+
- Notification Sender (Channel routing & payload formatting)
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## Automated Releases & NPM Publishing
|
|
184
|
+
|
|
185
|
+
This repository includes a fully automated GitHub Actions pipeline (`.github/workflows/release.yml`):
|
|
186
|
+
- **Automated Versioning**: Automatically detects existing release tags, tags the version, and bumps `patch` on pushes to `main`.
|
|
187
|
+
- **Changelog Extraction**: Extracts the corresponding version section from `CHANGELOG.md` to format the GitHub Release notes / release readme.
|
|
188
|
+
- **Compressed Release Assets**: Builds and packages:
|
|
189
|
+
- 📦 `medusajs-documents-plugin-vX.Y.Z.zip` (compressed distribution zipfile)
|
|
190
|
+
- 📦 `medusajs-documents-plugin-vX.Y.Z.tgz` (npm tarball)
|
|
191
|
+
- **NPM Publishing**: Publishes to [npm](https://www.npmjs.com/package/medusajs-documents-plugin) using `NODE_AUTH_TOKEN`.
|
|
192
|
+
|
|
193
|
+
### Setting Up NPM Publishing
|
|
194
|
+
To enable automated publishing to npm:
|
|
195
|
+
1. Generate an Automation or Publish token on [npmjs.com](https://www.npmjs.com) (`Access Tokens -> Generate New Token -> Automation`).
|
|
196
|
+
2. In your GitHub repository: Go to **Settings** > **Secrets and variables** > **Actions** > **New repository secret**.
|
|
197
|
+
3. Name: `NPM_TOKEN`, Value: `<your_npm_token>`.
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## License
|
|
202
|
+
MIT © [Urban Device Care](https://urbandevicecare.co.uk)
|
package/package.json
CHANGED
|
@@ -1,6 +1,88 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "medusajs-documents-plugin",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.1.2",
|
|
4
|
+
"description": "Comprehensive document generation and management module for Medusa v2 with Zoho Books integration, PDFKit fallback, QR codes, shortlinks, multi-channel notifications and unified admin hub.",
|
|
5
|
+
"author": "Urban Device Care <info@urbandevicecare.co.uk>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/urbandevicecare/medusajs-documents-plugin.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/urbandevicecare/medusajs-documents-plugin/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/urbandevicecare/medusajs-documents-plugin#readme",
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
".medusa/server",
|
|
20
|
+
"README.md",
|
|
21
|
+
"CHANGELOG.md",
|
|
22
|
+
"LICENSE"
|
|
23
|
+
],
|
|
24
|
+
"main": "./.medusa/server/src/index.js",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": "./.medusa/server/src/index.js",
|
|
27
|
+
"./package.json": "./package.json",
|
|
28
|
+
"./workflows": "./.medusa/server/src/workflows/index.js",
|
|
29
|
+
"./.medusa/server/src/modules/*": "./.medusa/server/src/modules/*/index.js",
|
|
30
|
+
"./modules/*": "./.medusa/server/src/modules/*/index.js",
|
|
31
|
+
"./*": "./.medusa/server/src/*.js",
|
|
32
|
+
"./admin": {
|
|
33
|
+
"import": "./.medusa/server/src/admin/index.mjs",
|
|
34
|
+
"require": "./.medusa/server/src/admin/index.js",
|
|
35
|
+
"default": "./.medusa/server/src/admin/index.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"medusa",
|
|
40
|
+
"plugin",
|
|
41
|
+
"medusa-plugin",
|
|
42
|
+
"medusa-documents",
|
|
43
|
+
"medusa-documents-v2",
|
|
44
|
+
"zoho-books",
|
|
45
|
+
"pdfkit",
|
|
46
|
+
"invoices"
|
|
47
|
+
],
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "medusa plugin:build",
|
|
50
|
+
"dev": "medusa plugin:dev",
|
|
51
|
+
"test": "npx tsx --test tests/run-all-tests.ts",
|
|
52
|
+
"prepack": "medusa plugin:build"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"pdf-lib": "^1.17.1",
|
|
56
|
+
"pdfkit": "^0.18.0",
|
|
57
|
+
"qrcode": "^1.5.4"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@medusajs/admin-sdk": "2.17.2",
|
|
61
|
+
"@medusajs/cli": "2.17.2",
|
|
62
|
+
"@medusajs/framework": "2.17.2",
|
|
63
|
+
"@medusajs/icons": "2.17.2",
|
|
64
|
+
"@medusajs/medusa": "2.17.2",
|
|
65
|
+
"@medusajs/ui": "4.1.8",
|
|
66
|
+
"@types/node": "^20.0.0",
|
|
67
|
+
"@types/pdfkit": "^0.17.6",
|
|
68
|
+
"@types/qrcode": "^1.5.6",
|
|
69
|
+
"@types/react": "^18.3.2",
|
|
70
|
+
"@types/react-dom": "^18.2.25",
|
|
71
|
+
"ts-node": "^10.9.2",
|
|
72
|
+
"typescript": "^5.6.2",
|
|
73
|
+
"vite": "^5.2.11"
|
|
74
|
+
},
|
|
75
|
+
"peerDependencies": {
|
|
76
|
+
"@medusajs/admin-sdk": "2.17.2",
|
|
77
|
+
"@medusajs/framework": "2.17.2",
|
|
78
|
+
"@medusajs/icons": "2.17.2",
|
|
79
|
+
"@medusajs/ui": "4.1.8",
|
|
80
|
+
"react": "^18.2.0",
|
|
81
|
+
"react-dom": "^18.2.0",
|
|
82
|
+
"react-router-dom": "^6.0.0"
|
|
83
|
+
},
|
|
84
|
+
"engines": {
|
|
85
|
+
"node": ">=20"
|
|
86
|
+
},
|
|
87
|
+
"packageManager": "yarn@4.18.0"
|
|
88
|
+
}
|