@medicus.ai/medicus-report-pdf-generator 1.3.9 → 1.3.10

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.
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  const fs = require("fs");
3
+ const crypto = require("crypto");
3
4
  const { promisify } = require('util');
4
5
  const { JSDOM } = require("jsdom");
5
6
  const path = require("path");
@@ -1001,8 +1002,12 @@ let generateHTMLWellbeingReport = async (data, isDebugging, clientName, language
1001
1002
  // Setup
1002
1003
  debug = isDebugging;
1003
1004
  const client = clientName || 'default';
1004
- OUT_FILE = path.resolve(__dirname + `/../output/${client}-pdf-` + Date.now() + '.html');
1005
- Pdf_file = `/output/${client}-pdf-` + Date.now() + '.html';
1005
+ // Per-call unique paths so concurrent callers never share a file on disk.
1006
+ // The puppeteer `goto(file:///…)` step is what previously read another
1007
+ // user's HTML when two requests overlapped, producing a swapped PDF body.
1008
+ const callId = crypto.randomUUID();
1009
+ const callOutFile = path.resolve(__dirname + `/../output/${client}-pdf-${callId}.html`);
1010
+ const callPdfFile = `/output/${client}-pdf-${callId}.html`;
1006
1011
 
1007
1012
  // Language configuration
1008
1013
  language = empty(language) ? 'en' : language;
@@ -1113,11 +1118,12 @@ let generateHTMLWellbeingReport = async (data, isDebugging, clientName, language
1113
1118
  }
1114
1119
 
1115
1120
  // Write file
1116
- await promisify(fs.writeFile)(OUT_FILE, finalHtml);
1121
+ await promisify(fs.writeFile)(callOutFile, finalHtml);
1117
1122
 
1118
1123
  return {
1119
1124
  html: finalHtml,
1120
- outputFile: OUT_FILE,
1125
+ outputFile: callOutFile,
1126
+ pdfFile: callPdfFile,
1121
1127
  header: renderedHeader,
1122
1128
  footer: footerHtml,
1123
1129
  historyData
@@ -1138,8 +1144,12 @@ let generateHTMLWellbeingReportWithSmartReport = async (data, isDebugging, clien
1138
1144
  // Setup
1139
1145
  debug = isDebugging;
1140
1146
  const client = clientName || 'default';
1141
- OUT_FILE = path.resolve(__dirname + `/../output/${client}-pdf-` + Date.now() + '.html');
1142
- Pdf_file = `/output/${client}-pdf-` + Date.now() + '.html';
1147
+ // Per-call unique paths so concurrent callers never share a file on disk.
1148
+ // The puppeteer `goto(file:///…)` step is what previously read another
1149
+ // user's HTML when two requests overlapped, producing a swapped PDF body.
1150
+ const callId = crypto.randomUUID();
1151
+ const callOutFile = path.resolve(__dirname + `/../output/${client}-pdf-${callId}.html`);
1152
+ const callPdfFile = `/output/${client}-pdf-${callId}.html`;
1143
1153
 
1144
1154
  // Extract data
1145
1155
  const wellbeingData = data.wellbeing || {};
@@ -1485,11 +1495,12 @@ let generateHTMLWellbeingReportWithSmartReport = async (data, isDebugging, clien
1485
1495
  }
1486
1496
 
1487
1497
  // Write file
1488
- await promisify(fs.writeFile)(OUT_FILE, finalHtml);
1498
+ await promisify(fs.writeFile)(callOutFile, finalHtml);
1489
1499
 
1490
1500
  return {
1491
1501
  html: finalHtml,
1492
- outputFile: OUT_FILE,
1502
+ outputFile: callOutFile,
1503
+ pdfFile: callPdfFile,
1493
1504
  header: renderedHeader,
1494
1505
  footer: templates.footer,
1495
1506
  historyData,
@@ -1545,15 +1556,16 @@ const setupPageContent = async (page, contentHtml, filePath) => {
1545
1556
  let generatePDFWellbeingReport = async (data) => {
1546
1557
  try {
1547
1558
  const contentHtml = data.html;
1548
- OUT_FILE = data.outputFile;
1549
1559
 
1550
1560
  // Launch browser and setup page
1551
1561
  const browser = await launchBrowser();
1552
1562
  const page = await browser.newPage();
1553
1563
  debugLog("page launched!");
1554
1564
 
1555
- // Setup content
1556
- await setupPageContent(page, contentHtml, Pdf_file);
1565
+ // Use the per-call relative path produced by generateHTMLWellbeingReport.
1566
+ // Reading module-level state here was the root cause of cross-user PDF
1567
+ // body swapping under concurrent requests.
1568
+ await setupPageContent(page, contentHtml, data.pdfFile);
1557
1569
  debugLog("page opened!");
1558
1570
 
1559
1571
  // Generate PDF
@@ -1789,15 +1801,17 @@ const setupExtendedPageContent = async (page, contentHtml, filePath) => {
1789
1801
  const generatePDFReport = async (data, hideWellbeingUI = false) => {
1790
1802
  try {
1791
1803
  const contentHtml = data.html;
1792
- const OUT_FILE = data.outputFile;
1793
1804
  const footerTemplate = getPdfFooterTemplate(data.client, data.selectedLabs, data.footer);
1794
1805
 
1795
1806
  // Launch browser and setup page
1796
1807
  const browser = await launchExtendedBrowser();
1797
1808
  const page = await browser.newPage();
1798
1809
 
1799
- // Setup content
1800
- await setupExtendedPageContent(page, contentHtml, Pdf_file);
1810
+ // Use the per-call relative path produced by
1811
+ // generateHTMLWellbeingReportWithSmartReport. Reading module-level
1812
+ // state here was the root cause of cross-user PDF body swapping
1813
+ // under concurrent requests.
1814
+ await setupExtendedPageContent(page, contentHtml, data.pdfFile);
1801
1815
 
1802
1816
  // Generate PDF with header and footer (PHA needs larger bottom margin to prevent content overlapping footer)
1803
1817
  const bottomMargin = (data.client || '').toLowerCase() === 'pha' ? '60px' : '50px';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medicus.ai/medicus-report-pdf-generator",
3
- "version": "1.3.09",
3
+ "version": "1.3.10",
4
4
  "description": "Nasco corporate report - latest update in 12/10/2023 - Fix HRC for bionext",
5
5
  "main": "index.js",
6
6
  "scripts": {