@shad0wz7/nestjs-pdf 2.5.4 → 3.0.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/README.md CHANGED
@@ -1,17 +1,17 @@
1
1
  # nestjs-pdf
2
2
 
3
- > **⚠️ Maintenance branch — NestJS 11 / CommonJS (v2.x).**
4
- > This is the `v2` line: CommonJS-only, built for **NestJS 11**. It's kept for
5
- > maintenance/security fixes only — no new features land here.
3
+ > **v3 — ESM-first, NestJS 12.** This is the active `main` line: authored in
4
+ > ESM, published as a dual CJS/ESM package, and targets **NestJS 12+**.
6
5
  >
7
- > Active development has moved to **v3**, on the `main` branch: ESM-first with
8
- > a dual CJS/ESM build, and requires **NestJS 12+**. See its
9
- > [README](https://github.com/ShadowZ11/nestjs-pdf/blob/main/README.md) for
10
- > details, and pin this line explicitly if you need it:
6
+ > Still on **NestJS 11** or need a pure CommonJS package? Use the maintenance
7
+ > `v2` branch instead:
11
8
  >
12
9
  > ```bash
13
10
  > npm install @shad0wz7/nestjs-pdf@^2
14
11
  > ```
12
+ >
13
+ > See the [`v2` branch README](https://github.com/ShadowZ11/nestjs-pdf/blob/v2/README.md)
14
+ > for details. It receives maintenance/security fixes only — new features land on v3.
15
15
 
16
16
  [![npm version](https://img.shields.io/npm/v/%40shad0wz7%2Fnestjs-pdf?label=npm%20version)](https://www.npmjs.com/package/%40shad0wz7%2Fnestjs-pdf)
17
17
  [![NPM License](https://img.shields.io/npm/l/%40shad0wz7%2Fnestjs-pdf)](https://github.com/ShadowZ11/nestjs-pdf?tab=MIT-1-ov-file)
@@ -29,6 +29,11 @@ Main features:
29
29
  - Add signature fields based on a text anchor in an existing PDF
30
30
  - Simple API (module and service) to integrate easily into a Nest application
31
31
 
32
+ ## Requirements
33
+
34
+ - **Node.js** `^20.19.0`, `^22.12.0` or `>=24.0.0` (aligned with NestJS 12)
35
+ - **NestJS** `^12.0.0` (`@nestjs/common`, `@nestjs/core`) and `rxjs ^7.8.0` as peer dependencies
36
+
32
37
  ## Installation
33
38
 
34
39
  To add the library inside your project :
@@ -50,7 +55,7 @@ Import the module and configure it in your Nest application:
50
55
 
51
56
  To use a template engine, you need to install the corresponding package as a dependency in your project:
52
57
 
53
- - For Handlebars: `npm install @gboutte/nestjs-hbs`
58
+ - For Handlebars: `npm install handlebars`
54
59
  - For EJS: `npm install ejs`
55
60
  - For Pug: `npm install pug`
56
61
  - For MJML: `npm install mjml`
@@ -60,7 +65,7 @@ To use a template engine, you need to install the corresponding package as a dep
60
65
 
61
66
  ```ts
62
67
  import { Module } from '@nestjs/common';
63
- import { NestjsPdfModule } from 'nestjs-pdf';
68
+ import { NestjsPdfModule } from '@shad0wz7/nestjs-pdf';
64
69
 
65
70
  @Module({
66
71
  imports: [
@@ -74,11 +79,20 @@ import { NestjsPdfModule } from 'nestjs-pdf';
74
79
  export class AppModule {}
75
80
  ```
76
81
 
82
+ > **Enable shutdown hooks.** On shutdown, `nestjs-pdf` waits for in-flight PDF jobs
83
+ > to finish, closes the Puppeteer browser and (optionally) wipes its browser cache.
84
+ > This only runs if your app enables Nest's shutdown hooks:
85
+ >
86
+ > ```ts
87
+ > const app = await NestFactory.create(AppModule);
88
+ > app.enableShutdownHooks();
89
+ > ```
90
+
77
91
  Inject the service and generate a PDF:
78
92
 
79
93
  ```ts
80
94
  import { Controller, Get } from '@nestjs/common';
81
- import { NestjsPdfService } from 'nestjs-pdf';
95
+ import { NestjsPdfService } from '@shad0wz7/nestjs-pdf';
82
96
 
83
97
  @Controller()
84
98
  export class AppController {
@@ -129,25 +143,25 @@ If the anchor is not found, the signature field will be added at a default posit
129
143
 
130
144
  The library exposes Puppeteer options via the `PuppeteerParameters` interface (see `src/puppeteer/puppeteer-parameters.interface.ts`). You can configure:
131
145
 
132
- | | Description |
133
- | --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
134
- | `pdfOptions` | The pdf options can be found on: https://pptr.dev/api/puppeteer.pdfoptions. Native Puppeteer options for `page.pdf` |
135
- | `hbsOptions` | The handlebars can be found on [@gboutte/nestjs-hbs](https://github.com/gboutte/nestjs-hbs) as it use a peer dependency and not handlebars directly |
136
- | `ejsOptions` | The ejs options can be found on [EJS documentation](https://ejs.co/#options) |
137
- | `pugOptions` | The pug options can be found on [Pug documentation](https://pugjs.org/api/reference.html#options) |
138
- | `mjmlOptions` | The mjml options can be found on [MJML documentation](https://mjml.io/documentation/#options) |
139
- | `nunjucksOptions` | The nunjucks options can be found on [Nunjucks documentation](https://mozilla.github.io/nunjucks/api.html#configure) |
140
- | `etaOptions` | The eta options can be found on [Eta documentation](https://eta.js.org/docs/4.x.x/api/configuration) |
141
- | `mustacheOptions` | The mustache options can be found on [Mustache documentation](https://mustache.github.io/mustache.5.html) |
142
- | `browser` | The browser to use for the PDF generation. By default: `Browser.CHROMIUM`. Allowed values `Browser.CHROMIUM`, `Browser.CHROMEHEADLESSSHELL`, `Browser.CHROME`, `Browser.FIREFOX`, `Browser.CHROMEDRIVER` ([Official documentation of Browser](https://pptr.dev/browsers-api/browsers.browser)) |
143
- | `browserTag` | The version of the browser to use for the PDF generation. By default: `BrowserTag.LATEST` if Browser is **CHROMIUM** else `BrowserTag.STABLE`. Allowed values `BrowserTag.STABLE`, `BrowserTag.LATEST`, `BrowserTag.BETA`, `BrowserTag.DEV`, `BrowserTag.CANARY` |
144
- | `browserInstallBaseUrl` | The baseUrl used for the installation of the browser. This baseUrl is passed to the [`install`](https://pptr.dev/browsers-api/browsers.install) method of `@puppeteer/browsers` |
145
- | `headless` | Define if you want to use chromium headless or not, or the old headless version (`shell`). By default it's `true`. Allowed values: `true`,`false`,`"shell"` |
146
- | `useLockedBrowser` | Define if you want to use the locked version of the browser. By default it's `false`. Allowed values: `true`,`false` |
147
- | `buildId` | You can force the build id. Should be `string` |
148
- | `cleanupBrowserCacheOnExit` | Define if you want to clean up the browser cache folder on exit. By default it's `true`. Allowed values: `true`,`false` |
149
- | `extraPuppeteerArgs` | It passes some extra arguments to Puppeteer's launch method. You can check the default args at bellow. Should be `string[]` |
150
- | `executablePath` | The path to the browser executable to use. If not specified, Puppeteer will install Chromium in cache dir. (useLockedBrowser is useless with this param specified) |
146
+ | | Description |
147
+ | --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
148
+ | `pdfOptions` | The pdf options can be found on: https://pptr.dev/api/puppeteer.pdfoptions. Native Puppeteer options for `page.pdf` |
149
+ | `hbsOptions` | Handlebars configuration: `templateDirectory` (base dir for `renderFile`), `partialDirectory` (files registered as partials), `compileOptions`, `templateOptions`, and `helpers` (`{ name, fn }[]`). Like the other engines it can be set globally here or overridden per call (`generatePdfFromTemplateHbs*(..., { hbsOptions })`). Helpers/partials run on an isolated Handlebars environment (no global leakage). |
150
+ | `ejsOptions` | The ejs options can be found on [EJS documentation](https://ejs.co/#options) |
151
+ | `pugOptions` | The pug options can be found on [Pug documentation](https://pugjs.org/api/reference.html#options) |
152
+ | `mjmlOptions` | The mjml options can be found on [MJML documentation](https://mjml.io/documentation/#options) |
153
+ | `nunjucksOptions` | The nunjucks options can be found on [Nunjucks documentation](https://mozilla.github.io/nunjucks/api.html#configure) |
154
+ | `etaOptions` | The eta options can be found on [Eta documentation](https://eta.js.org/docs/4.x.x/api/configuration) |
155
+ | `mustacheOptions` | The mustache options can be found on [Mustache documentation](https://mustache.github.io/mustache.5.html) |
156
+ | `browser` | The browser to use for the PDF generation. By default: `Browser.CHROMIUM`. Allowed values `Browser.CHROMIUM`, `Browser.CHROMEHEADLESSSHELL`, `Browser.CHROME`, `Browser.FIREFOX`, `Browser.CHROMEDRIVER` ([Official documentation of Browser](https://pptr.dev/browsers-api/browsers.browser)) |
157
+ | `browserTag` | The version of the browser to use for the PDF generation. By default: `BrowserTag.LATEST` if Browser is **CHROMIUM** else `BrowserTag.STABLE`. Allowed values `BrowserTag.STABLE`, `BrowserTag.LATEST`, `BrowserTag.BETA`, `BrowserTag.DEV`, `BrowserTag.CANARY` |
158
+ | `browserInstallBaseUrl` | The baseUrl used for the installation of the browser. This baseUrl is passed to the [`install`](https://pptr.dev/browsers-api/browsers.install) method of `@puppeteer/browsers` |
159
+ | `headless` | Define if you want to use chromium headless or not, or the old headless version (`shell`). By default it's `true`. Allowed values: `true`,`false`,`"shell"` |
160
+ | `useLockedBrowser` | Define if you want to use the locked version of the browser. By default it's `false`. Allowed values: `true`,`false` |
161
+ | `buildId` | You can force the build id. Should be `string` |
162
+ | `cleanupBrowserCacheOnExit` | Wipe the downloaded browser cache folder when the app shuts down (requires `app.enableShutdownHooks()`). Set to `false` to keep the cache between runs. By default it's `true`. Allowed values: `true`,`false` |
163
+ | `extraPuppeteerArgs` | It passes some extra arguments to Puppeteer's launch method. You can check the default args at bellow. Should be `string[]` |
164
+ | `executablePath` | The path to the browser executable to use. If not specified, Puppeteer will install Chromium in cache dir. (useLockedBrowser is useless with this param specified) |
151
165
 
152
166
  these are the default extra arguments passed to Puppeteer:
153
167
 
@@ -210,11 +224,12 @@ If you want to test locally the examples with the entire project, you can follow
210
224
 
211
225
  ## Tests
212
226
 
213
- This repository includes unit and integration tests (Jest). To run the tests:
227
+ This repository includes unit tests (Vitest). To run them:
214
228
 
215
229
  ```bash
216
- pnpm run test
217
- pnpm run test:e2e
230
+ pnpm test # single run
231
+ pnpm test:watch # watch mode
232
+ pnpm test:cov # with coverage
218
233
  ```
219
234
 
220
235
  ## Contributing