@stamhoofd/backend-renderer 2.57.1 → 2.59.0

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": "@stamhoofd/backend-renderer",
3
- "version": "2.57.1",
3
+ "version": "2.59.0",
4
4
  "main": "./dist/index.js",
5
5
  "exports": {
6
6
  ".": {
@@ -23,16 +23,16 @@
23
23
  "@types/node": "^20.12"
24
24
  },
25
25
  "dependencies": {
26
- "@simonbackx/simple-endpoints": "1.14.0",
26
+ "@simonbackx/simple-endpoints": "1.15.0",
27
27
  "@simonbackx/simple-logging": "^1.0.1",
28
28
  "formidable": "3.5.1",
29
29
  "luxon": "3.4.4",
30
30
  "mockdate": "^3.0.2",
31
31
  "mysql": "^2.18.1",
32
- "puppeteer": "22.12.0"
32
+ "puppeteer": "^23.9.0"
33
33
  },
34
34
  "publishConfig": {
35
35
  "access": "public"
36
36
  },
37
- "gitHead": "f109d195d0bbb0e49c7b7bcef403b710c68c025b"
37
+ "gitHead": "a7043be8f8fde4fd1c91943495132a21921ebbe1"
38
38
  }
@@ -12,7 +12,7 @@ import { FileCache } from '../helpers/FileCache';
12
12
  type Params = Record<string, never>;
13
13
  type Body = undefined;
14
14
  type Query = undefined;
15
- type ResponseBody = Buffer;
15
+ type ResponseBody = Uint8Array;
16
16
 
17
17
  /**
18
18
  * One endpoint to create, patch and delete groups. Usefull because on organization setup, we need to create multiple groups at once. Also, sometimes we need to link values and update multiple groups at once
@@ -121,7 +121,7 @@ export class HtmlToPdfEndpoint extends Endpoint<Params, Query, Body, ResponseBod
121
121
  });
122
122
  }
123
123
 
124
- let pdf: Buffer | null = null;
124
+ let pdf: Uint8Array | null = null;
125
125
  try {
126
126
  pdf = await this.htmlToPdf(html, { retryCount: 2, startDate: new Date() });
127
127
  }
@@ -145,23 +145,24 @@ export class HtmlToPdfEndpoint extends Endpoint<Params, Query, Body, ResponseBod
145
145
  nextBrowserIndex = 0;
146
146
 
147
147
  async useBrowser<T>(callback: (browser: Browser) => Promise<T>): Promise<T> {
148
+ console.log('Requesting browser');
148
149
  this.nextBrowserIndex++;
149
150
  if (this.nextBrowserIndex >= this.browsers.length) {
150
151
  this.nextBrowserIndex = 0;
151
152
  }
152
153
  return await QueueHandler.schedule('getBrowser' + this.nextBrowserIndex, async () => {
153
154
  if (!this.browsers[this.nextBrowserIndex]) {
154
- this.browsers[this.nextBrowserIndex] = { browser: await puppeteer.launch({ pipe: true }), count: 0 };
155
+ this.browsers[this.nextBrowserIndex] = { browser: await puppeteer.launch({}), count: 0 };
155
156
  }
156
157
  const browser = this.browsers[this.nextBrowserIndex]!;
157
- if (browser.count > 50 || !browser.browser.isConnected()) {
158
+ if (browser.count > 50 || !browser.browser.connected) {
158
159
  try {
159
160
  await browser.browser.close();
160
161
  }
161
162
  catch (e) {
162
163
  console.error(e);
163
164
  }
164
- this.browsers[this.nextBrowserIndex] = { browser: await puppeteer.launch({ pipe: true }), count: 0 };
165
+ this.browsers[this.nextBrowserIndex] = { browser: await puppeteer.launch({}), count: 0 };
165
166
  }
166
167
 
167
168
  return await callback(browser.browser);
@@ -184,7 +185,7 @@ export class HtmlToPdfEndpoint extends Endpoint<Params, Query, Body, ResponseBod
184
185
  /**
185
186
  * This will move to a different external service
186
187
  */
187
- async htmlToPdf(html: string, options: { retryCount: number; startDate: Date }): Promise<Buffer | null> {
188
+ async htmlToPdf(html: string, options: { retryCount: number; startDate: Date }): Promise<Uint8Array | null> {
188
189
  const response = await this.useBrowser(async (browser) => {
189
190
  try {
190
191
  // Create a new page
@@ -203,6 +204,8 @@ export class HtmlToPdfEndpoint extends Endpoint<Params, Query, Body, ResponseBod
203
204
  displayHeaderFooter: false,
204
205
  });
205
206
  await page.close();
207
+
208
+ console.log('Rendered document pdf');
206
209
  return pdf;
207
210
  }
208
211
  catch (e) {
@@ -2,7 +2,7 @@ import { SimpleError } from '@simonbackx/simple-errors';
2
2
  import { promises as fs } from 'fs';
3
3
 
4
4
  export class FileCache {
5
- static async write(cacheId: string, timestamp: Date, data: Buffer) {
5
+ static async write(cacheId: string, timestamp: Date, data: Uint8Array | Buffer) {
6
6
  if (cacheId.includes('/')) {
7
7
  throw new SimpleError({
8
8
  code: 'invalid_field',