jp-shared 1.1.13 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jp-shared",
3
- "version": "1.1.13",
3
+ "version": "1.1.14",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -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("jp-shared/utils/env-utils");
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
- try {
14
- // from below is for local development
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
- const browser = isProduction() || isTest() ? await puppeteer.launch({
25
- executablePath: await chromium.executablePath, // Path to Chromium for Firebase/Serverless
26
- args: chromium.args, // Required arguments for running headless
27
- headless: chromium.headless, // Ensure headless mode is enabled
28
- }) : await localPuppeteer.launch();
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", // Set paper format to A4 (you can customize this if needed)
39
- printBackground: true, // Include background images or colors in the PDF
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; // Re-throw the error for further handling
44
+ throw error;
50
45
  }
51
46
  };
52
47
  const sendInvoice = async (invoiceInput) => {