@paprize/puppeteer 0.0.3 → 0.0.4

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.
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/pageToPdf.ts", "../src/openReport.ts", "../src/serveReport.ts", "../src/reportToPdf.ts"],
4
+ "sourcesContent": ["import type { Page, PDFOptions } from 'puppeteer-core';\n\n/**\n * Generates a PDF from the given Puppeteer `Page` instance using the specified options.\n *\n * @param page - The Puppeteer `Page` instance to generate the PDF from.\n * @param pdfOptions - Optional additional options to customize the PDF generation. These options\n * will be merged with the default settings.\n * @returns A promise that resolves to a `Uint8Array` containing the generated PDF data.\n */\nexport function pageToPdf(\n page: Page,\n pdfOptions?: PDFOptions\n): Promise<Uint8Array> {\n return page.pdf({\n waitForFonts: true,\n printBackground: true,\n displayHeaderFooter: false,\n preferCSSPageSize: true,\n margin: {\n bottom: '0px',\n left: '0px',\n right: '0px',\n top: '0px',\n },\n ...pdfOptions,\n });\n}\n", "import type { Page } from 'puppeteer-core';\nimport { paprize_isReady, paprize_readJsonDataFile } from '@paprize/core/src';\n\n/**\n * Opens a report in the given Puppeteer page, injects a JSON data file if provided,\n * and waits for the report to be ready.\n *\n * @param page - The Puppeteer `Page` instance where the report will be opened.\n * @param reportUrl - The URL of the report to be opened.\n * @param jsonData - Optional JSON data as a string to be injected into the page.\n * @param timeout - The maximum time to wait for the report to be ready, in milliseconds. Defaults to 30,000 ms.\n * @returns A promise that resolves when the report is ready.\n * @throws Will throw an error if the report does not become ready within the specified timeout.\n */\nexport async function openReport(\n page: Page,\n reportUrl: URL,\n jsonData: string | undefined,\n timeout: number = 30000\n): Promise<void> {\n await page.exposeFunction(paprize_readJsonDataFile, () => {\n return jsonData;\n });\n\n await page.goto(reportUrl.toString(), {\n waitUntil: 'networkidle0',\n timeout,\n });\n await page.waitForFunction(`window.${paprize_isReady} === true`, {\n timeout,\n });\n}\n", "import http from 'http';\nimport type { AddressInfo } from 'node:net';\nimport handler from 'serve-handler';\nimport { promises as fs } from 'fs';\n\nexport interface ReportServer {\n server: http.Server;\n close: () => void;\n getHost: () => string;\n}\n\n/**\n * Serves a static report from the specified directory over HTTP.\n *\n * @param dir - The directory containing the static files to serve.\n * @param port - Optional. The port on which the server will listen. If not provided, a random available port will be used.\n * @returns A promise that resolves to a `ReportServer` object, which provides methods to close the server and retrieve its host URL.\n *\n * The server serves files from the specified directory and automatically rewrites requests\n * to `/index.html` for any unmatched routes. Subdirectories in the specified directory are\n * mapped to corresponding routes.\n */\nexport async function serveReport(\n dir: string,\n port?: number\n): Promise<ReportServer> {\n const staticDirectories = (await fs.readdir(dir, { withFileTypes: true }))\n .filter((x) => x.isDirectory())\n .map((x) => ({ source: x.name, destination: `/${x.name}` }));\n\n const server = http.createServer(async (req, res) => {\n await handler(req, res, {\n public: dir,\n rewrites: [\n ...staticDirectories,\n { source: '**', destination: '/index.html' },\n ],\n });\n });\n\n server.listen(port);\n const address = server.address() as AddressInfo;\n\n return {\n server,\n close: () => server.close(),\n getHost: () => `http://localhost:${address.port}`,\n };\n}\n", "import type { Page, PDFOptions } from 'puppeteer-core';\nimport { openReport } from './openReport';\nimport { pageToPdf } from './pageToPdf';\n\n/**\n * Generates a PDF from a report by navigating to the specified report URL\n * and optionally sending JSON data to the page.\n *\n * @param page - The Puppeteer `Page` instance used to interact with the report.\n * @param reportUrl - The URL of the report to be converted to a PDF.\n * @param jsonData - Optional JSON data to be sent to the report page.\n * @param pdfOptions - Optional configuration for generating the PDF, including timeout and other settings.\n * @returns A promise that resolves to a `Uint8Array` containing the generated PDF data.\n */\nexport async function reportToPdf(\n page: Page,\n reportUrl: URL,\n jsonData?: string,\n pdfOptions?: PDFOptions\n): Promise<Uint8Array> {\n await openReport(page, reportUrl, jsonData, pdfOptions?.timeout);\n return await pageToPdf(page, pdfOptions);\n}\n"],
5
+ "mappings": ";AAUO,SAAS,UACZ,MACA,YACmB;AACnB,SAA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ACnD;AACJ;;;AClCA,eAAsB,YAClB,MACA,WACA,UACA,YACmB;AACnB,QAAM,WAAW,MAAM,WAAW,UAAU,YAAY,OAAO;AAC/D,SAAO,MAAM,UAAU,MAAM,UAAU;AAC3C;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@paprize/puppeteer",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Convert HTML reports to print-ready PDFs",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",
8
8
  "CHANGELOG.md"
9
9
  ],
10
- "main": "./dist/paprize_puppeteer.umd.cjs",
11
- "module": "./dist/paprize_puppeteer.js",
10
+ "main": "./dist/paprize-puppeteer.umd.cjs",
11
+ "module": "./dist/paprize-puppeteer.js",
12
12
  "exports": {
13
13
  ".": {
14
- "types": "./dist/paprize_puppeteer.d.ts",
15
- "import": "./dist/paprize_puppeteer.js",
16
- "require": "./dist/paprize_puppeteer.umd.cjs"
14
+ "types": "./dist/paprize-puppeteer.d.ts",
15
+ "import": "./dist/paprize-puppeteer.js",
16
+ "require": "./dist/paprize-puppeteer.umd.cjs"
17
17
  },
18
18
  "./src": {
19
19
  "types": "./src/window.ts",
@@ -45,6 +45,7 @@
45
45
  "@types/serve-handler": "^6.1.4",
46
46
  "esbuild": "0.25.10",
47
47
  "puppeteer-core": "^24.19.0",
48
+ "@paprize/core": "*",
48
49
  "typescript": "~5.8.3"
49
50
  },
50
51
  "peerDependencies": {