@b2y/ecommerce-common 1.0.6 → 1.0.7
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/dbconnection/Connect.js +4 -0
- package/package.json +4 -3
- package/utility/PdfUtil.js +64 -0
package/dbconnection/Connect.js
CHANGED
|
@@ -97,6 +97,10 @@ const initializeModels = (sequelize) => {
|
|
|
97
97
|
Tenant.hasMany(User, { foreignKey: "TenantID", as: "User" });
|
|
98
98
|
User.belongsTo(Tenant, { foreignKey: "TenantID", as: "Tenant" });
|
|
99
99
|
|
|
100
|
+
// Tenant and Order
|
|
101
|
+
Order.belongsTo(Tenant, { foreignKey: 'TenantID', as: 'Tenant' });
|
|
102
|
+
Tenant.hasMany(Order, { foreignKey: 'TenantID', as: 'Order' });
|
|
103
|
+
|
|
100
104
|
// Tenant and Customer (One-to-many: A Tenant has many Customers)
|
|
101
105
|
Tenant.hasMany(Customer, { foreignKey: "TenantID", as: "Customer" });
|
|
102
106
|
Customer.belongsTo(Tenant, { foreignKey: "TenantID", as: "Tenant" });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@b2y/ecommerce-common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "E-commerce common library",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -20,9 +20,10 @@
|
|
|
20
20
|
},
|
|
21
21
|
"homepage": "https://github.com/yuvakrishna29/ecommerce-common#readme",
|
|
22
22
|
"peerDependencies": {
|
|
23
|
+
"@countrystatecity/countries": "^1.0.4",
|
|
23
24
|
"exceljs": "^4.4.0",
|
|
24
25
|
"luxon": "^3.7.2",
|
|
25
|
-
"
|
|
26
|
-
"
|
|
26
|
+
"puppeteer": "^24.35.0",
|
|
27
|
+
"sequelize": "^6.37.5"
|
|
27
28
|
}
|
|
28
29
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// utils/PdfUtil.js
|
|
2
|
+
const puppeteer = require('puppeteer');
|
|
3
|
+
|
|
4
|
+
class PdfUtil {
|
|
5
|
+
constructor(options = {}) {
|
|
6
|
+
this.defaultOptions = {
|
|
7
|
+
format: 'A4',
|
|
8
|
+
printBackground: true,
|
|
9
|
+
margin: {
|
|
10
|
+
top: '20px',
|
|
11
|
+
right: '20px',
|
|
12
|
+
bottom: '20px',
|
|
13
|
+
left: '20px'
|
|
14
|
+
},
|
|
15
|
+
...options
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Generate PDF from HTML content
|
|
21
|
+
* @param {string} htmlContent - Complete HTML content to convert to PDF
|
|
22
|
+
* @param {object} pdfOptions - Optional PDF generation options (overrides defaults)
|
|
23
|
+
* @returns {Buffer} PDF buffer
|
|
24
|
+
*/
|
|
25
|
+
async generatePDFFromHTML(htmlContent, pdfOptions = {}) {
|
|
26
|
+
let browser;
|
|
27
|
+
try {
|
|
28
|
+
// Launch puppeteer
|
|
29
|
+
browser = await puppeteer.launch({
|
|
30
|
+
headless: true,
|
|
31
|
+
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const page = await browser.newPage();
|
|
35
|
+
|
|
36
|
+
// Set content and wait for any resources to load
|
|
37
|
+
await page.setContent(htmlContent, { waitUntil: 'networkidle0' });
|
|
38
|
+
|
|
39
|
+
// Merge default options with provided options
|
|
40
|
+
const finalOptions = { ...this.defaultOptions, ...pdfOptions };
|
|
41
|
+
|
|
42
|
+
// Generate PDF
|
|
43
|
+
const pdfBuffer = await page.pdf(finalOptions);
|
|
44
|
+
|
|
45
|
+
return pdfBuffer;
|
|
46
|
+
|
|
47
|
+
} catch (error) {
|
|
48
|
+
throw error;
|
|
49
|
+
} finally {
|
|
50
|
+
if (browser) {
|
|
51
|
+
await browser.close();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Generate PDF with custom page settings
|
|
58
|
+
*/
|
|
59
|
+
async generatePDFWithCustomSettings(htmlContent, settings) {
|
|
60
|
+
return this.generatePDFFromHTML(htmlContent, settings);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = PdfUtil;
|