@paprize/puppeteer 0.4.0 → 0.4.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @paprize/puppeteer
2
2
 
3
+ ## 0.4.1
4
+
5
+ ### Changed
6
+ - Add `@paprize/core` to dependencies
7
+
8
+ ### Fixed
9
+ - Fix missing type deceleration for functions
10
+
3
11
  ## 0.4.0
4
12
 
5
13
  ### Changed
@@ -1,14 +1,79 @@
1
- export declare function runZeroReport(): Promise<void>;
1
+ import { default as default_2 } from 'http';
2
+ import { Page } from 'puppeteer-core';
3
+ import { PDFOptions } from 'puppeteer-core';
2
4
 
3
- export declare const sectionPageHeightAttribute = "data-pz-section-page-height";
5
+ /**
6
+ * Opens a report in the given Puppeteer page, injects a JSON data file if provided,
7
+ * and waits for the report to be ready.
8
+ *
9
+ * @param page - The Puppeteer `Page` instance where the report will be opened.
10
+ * @param reportUrl - The URL of the report to be opened.
11
+ * @param jsonData - Optional JSON data to be injected into the page.
12
+ * @param timeout - The maximum time to wait for the report to be ready, in milliseconds. Defaults to 30,000 ms.
13
+ * @returns A promise that resolves when the report is ready.
14
+ * @throws Will throw an error if the report does not become ready within the specified timeout.
15
+ */
16
+ export declare function openReport(page: Page, reportUrl: URL, jsonData: unknown | undefined, timeout?: number): Promise<void>;
4
17
 
5
- export declare const sectionPageMarginAttribute = "data-pz-section-page-margin";
18
+ /**
19
+ * Generates a PDF from the given Puppeteer `Page` instance using the specified options.
20
+ *
21
+ * @param page - The Puppeteer `Page` instance to generate the PDF from.
22
+ * @param options - Optional additional options to customize the PDF generation. These options
23
+ * will be merged with the default settings.
24
+ * @returns A promise that resolves to a `Uint8Array` containing the generated PDF data.
25
+ */
26
+ export declare function pageToPdf(page: Page, options?: ReportOptions): Promise<Uint8Array>;
6
27
 
7
- export declare const sectionPageOrientationAttribute = "data-pz-section-page-orientation";
28
+ /**
29
+ * Predefined static Paprize PDF options.
30
+ *
31
+ * including:
32
+ * - waitForFonts: true
33
+ * - printBackground: true
34
+ * - displayHeaderFooter: false
35
+ * - preferCSSPageSize: true
36
+ * - margin: all sides 0px
37
+ */
38
+ export declare const paprizeOptions: PDFOptions;
8
39
 
9
- export declare const sectionPageSizeAttribute = "data-pz-section-page-size";
40
+ /**
41
+ * Options for generating a PDF report with Paprize.
42
+ * extends Puppeteer's [PDFOptions](https://pptr.dev/api/puppeteer.pdfoptions)
43
+ * , excluding options that are already set by Paprize {@link paprizeOptions}
44
+ */
45
+ export declare type ReportOptions = Omit<PDFOptions, keyof typeof paprizeOptions>;
10
46
 
11
- export declare const sectionPageWidthAttribute = "data-pz-section-page-width";
47
+ export declare interface ReportServer {
48
+ server: default_2.Server;
49
+ close: () => void;
50
+ getHost: () => string;
51
+ }
52
+
53
+ /**
54
+ * Generates a PDF from a report by navigating to the specified report URL
55
+ * and optionally sending JSON data to the page.
56
+ *
57
+ * @param page - The Puppeteer `Page` instance used to interact with the report.
58
+ * @param reportUrl - The URL of the report to be converted to a PDF.
59
+ * @param jsonData - Optional JSON data to be sent to the report page.
60
+ * @param pdfOptions - Optional configuration for generating the PDF, including timeout and other settings.
61
+ * @returns A promise that resolves to a `Uint8Array` containing the generated PDF data.
62
+ */
63
+ export declare function reportToPdf(page: Page, reportUrl: URL, jsonData?: unknown, pdfOptions?: PDFOptions): Promise<Uint8Array>;
64
+
65
+ /**
66
+ * Serves a static report from the specified directory over HTTP.
67
+ *
68
+ * @param dir - The directory containing the static files to serve.
69
+ * @param port - Optional. The port on which the server will listen. If not provided, a random available port will be used.
70
+ * @returns A promise that resolves to a `ReportServer` object, which provides methods to close the server and retrieve its host URL.
71
+ *
72
+ * The server serves files from the specified directory and automatically rewrites requests
73
+ * to `/index.html` for any unmatched routes. Subdirectories in the specified directory are
74
+ * mapped to corresponding routes.
75
+ */
76
+ export declare function serveReport(dir: string, port?: number): Promise<ReportServer>;
12
77
 
13
78
  export { }
14
79
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paprize/puppeteer",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Convert HTML reports to print-ready PDFs",
5
5
  "type": "module",
6
6
  "files": [
@@ -34,19 +34,19 @@
34
34
  "license": "Apache-2.0",
35
35
  "author": "PejmanNikram",
36
36
  "devDependencies": {
37
+ "@paprize/vanilla": "0.4.0",
37
38
  "@types/serve-handler": "^6.1.4",
38
39
  "esbuild": "^0.28.1",
39
40
  "puppeteer-core": "^25.3.0",
40
41
  "typescript": "^6.0.3",
41
42
  "unplugin-dts": "^1.0.3",
42
- "vitest": "^4.1.10",
43
- "@paprize/core": "0.4.0",
44
- "@paprize/vanilla": "0.4.0"
43
+ "vitest": "^4.1.11"
45
44
  },
46
45
  "peerDependencies": {
47
46
  "puppeteer-core": ">=24.0.0"
48
47
  },
49
48
  "dependencies": {
49
+ "@paprize/core": "0.4.0",
50
50
  "serve-handler": "^6.1.7"
51
51
  },
52
52
  "scripts": {