jp-shared 1.1.12 → 1.1.14
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/package.json +1 -1
- package/utils/sendInvoice-utils.js +22 -27
package/package.json
CHANGED
|
@@ -6,47 +6,42 @@ const { invoiceEmailTemplate } = require("./invoiceTemplate");
|
|
|
6
6
|
const { ToWords } = require("to-words");
|
|
7
7
|
const { OUR_ORG_INFO } = require("../constants");
|
|
8
8
|
const { invoiceSchema } = require("../../../src/validators");
|
|
9
|
-
const { isProduction, isTest } = require("
|
|
9
|
+
const { isProduction, isTest } = require("./env-utils");
|
|
10
|
+
// const { isProduction, isTest } = require("jp-shared/utils");
|
|
10
11
|
const toWords = new ToWords();
|
|
11
12
|
|
|
12
13
|
const generatePDF = async (htmlContent) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// const browser = await localPuppeteer.launch();
|
|
16
|
-
|
|
17
|
-
//Launch browser with necessary configuration for Firebase or serverless environments
|
|
18
|
-
const browser = await puppeteer.launch({
|
|
19
|
-
executablePath: await chromium.executablePath, // Path to Chromium for Firebase/Serverless
|
|
20
|
-
args: chromium.args, // Required arguments for running headless
|
|
21
|
-
headless: chromium.headless, // Ensure headless mode is enabled
|
|
22
|
-
});
|
|
14
|
+
try {
|
|
15
|
+
let browser;
|
|
23
16
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
if (isProduction() || isTest()) {
|
|
18
|
+
// In serverless/production environments
|
|
19
|
+
browser = await puppeteer.launch({
|
|
20
|
+
executablePath: await chromium.executablePath,
|
|
21
|
+
args: chromium.args,
|
|
22
|
+
headless: chromium.headless,
|
|
23
|
+
});
|
|
24
|
+
} else {
|
|
25
|
+
// In local development
|
|
26
|
+
const localPuppeteer = require("puppeteer"); // Use full puppeteer
|
|
27
|
+
browser = await localPuppeteer.launch({
|
|
28
|
+
headless: true,
|
|
29
|
+
args: ["--no-sandbox", "--disable-setuid-sandbox"],
|
|
30
|
+
});
|
|
31
|
+
}
|
|
29
32
|
|
|
30
|
-
// Create a new page in the browser
|
|
31
33
|
const page = await browser.newPage();
|
|
32
|
-
|
|
33
|
-
// Set the HTML content dynamically passed to this function
|
|
34
34
|
await page.setContent(htmlContent);
|
|
35
|
-
|
|
36
|
-
// Generate the PDF from the page's content
|
|
37
35
|
const pdfBuffer = await page.pdf({
|
|
38
|
-
format: "A4",
|
|
39
|
-
printBackground: true,
|
|
36
|
+
format: "A4",
|
|
37
|
+
printBackground: true,
|
|
40
38
|
});
|
|
41
39
|
|
|
42
|
-
// Close the browser once done
|
|
43
40
|
await browser.close();
|
|
44
|
-
|
|
45
|
-
// Return the PDF as a buffer
|
|
46
41
|
return pdfBuffer;
|
|
47
42
|
} catch (error) {
|
|
48
43
|
console.error("Error generating PDF:", error);
|
|
49
|
-
throw error;
|
|
44
|
+
throw error;
|
|
50
45
|
}
|
|
51
46
|
};
|
|
52
47
|
const sendInvoice = async (invoiceInput) => {
|