chromiumly 3.3.0 → 3.3.2

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.
Files changed (49) hide show
  1. package/README.md +1 -0
  2. package/dist/chromium/converters/html.converter.js +1 -1
  3. package/dist/pdf-engines/utils/pdf-engines.utils.js +5 -5
  4. package/dist/pdf-engines/utils/pdf-engines.utils.js.map +1 -1
  5. package/package.json +13 -10
  6. package/src/.prettierrc.yml +0 -4
  7. package/src/chromium/converters/converter.ts +0 -22
  8. package/src/chromium/converters/html.converter.ts +0 -134
  9. package/src/chromium/converters/markdown.converter.ts +0 -129
  10. package/src/chromium/converters/tests/html.converter.test.ts +0 -190
  11. package/src/chromium/converters/tests/markdown.converter.test.ts +0 -187
  12. package/src/chromium/converters/tests/url.converter.test.ts +0 -164
  13. package/src/chromium/converters/url.converter.ts +0 -125
  14. package/src/chromium/index.ts +0 -6
  15. package/src/chromium/interfaces/common.types.ts +0 -15
  16. package/src/chromium/interfaces/converter.types.ts +0 -45
  17. package/src/chromium/interfaces/screenshot.types.ts +0 -15
  18. package/src/chromium/screenshots/html.screenshot.ts +0 -105
  19. package/src/chromium/screenshots/markdown.screenshot.ts +0 -100
  20. package/src/chromium/screenshots/screenshot.ts +0 -22
  21. package/src/chromium/screenshots/tests/html.screenshot.test.ts +0 -192
  22. package/src/chromium/screenshots/tests/markdown.screenshot.test.ts +0 -176
  23. package/src/chromium/screenshots/tests/url.screenshot.test.ts +0 -166
  24. package/src/chromium/screenshots/url.screenshot.ts +0 -96
  25. package/src/chromium/utils/converter.utils.ts +0 -187
  26. package/src/chromium/utils/screenshot.utils.ts +0 -127
  27. package/src/chromium/utils/tests/converter.utils.test.ts +0 -496
  28. package/src/chromium/utils/tests/screenshot.utils.test.ts +0 -338
  29. package/src/common/constants.ts +0 -9
  30. package/src/common/gotenberg.utils.ts +0 -86
  31. package/src/common/index.ts +0 -3
  32. package/src/common/tests/gotenberg.utils.test.ts +0 -141
  33. package/src/common/types.ts +0 -7
  34. package/src/gotenberg.ts +0 -54
  35. package/src/libre-office/index.ts +0 -1
  36. package/src/libre-office/interfaces/libre-office.types.ts +0 -156
  37. package/src/libre-office/libre-office.ts +0 -61
  38. package/src/libre-office/tests/libre-office.test.ts +0 -56
  39. package/src/libre-office/utils/constants.ts +0 -132
  40. package/src/libre-office/utils/libre-office.utils.ts +0 -128
  41. package/src/libre-office/utils/tests/libre-office.utils.test.ts +0 -156
  42. package/src/main.config.ts +0 -157
  43. package/src/main.ts +0 -13
  44. package/src/pdf-engines/index.ts +0 -1
  45. package/src/pdf-engines/interfaces/pdf-engines.types.ts +0 -10
  46. package/src/pdf-engines/pdf-engines.ts +0 -156
  47. package/src/pdf-engines/tests/pdf.engine.test.ts +0 -163
  48. package/src/pdf-engines/utils/pdf-engines.utils.ts +0 -68
  49. package/src/pdf-engines/utils/tests/pdf-engines.utils.test.ts +0 -71
@@ -1,496 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
- import { createReadStream, promises } from 'fs';
3
- import path from 'path';
4
- import FormData from 'form-data';
5
- import { ConverterUtils } from '../converter.utils';
6
- import { GotenbergUtils, PdfFormat } from '../../../common';
7
-
8
- describe('GotenbergUtils', () => {
9
- const mockFormDataAppend = jest.spyOn(FormData.prototype, 'append');
10
- const data = new FormData();
11
-
12
- afterEach(() => {
13
- jest.resetAllMocks();
14
- });
15
-
16
- describe('addPageProperties', () => {
17
- describe('Single page', () => {
18
- describe('when singlePage parameter is set', () => {
19
- it('should append singlePage to data', () => {
20
- ConverterUtils.addPageProperties(data, {
21
- singlePage: true
22
- });
23
- expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
24
- expect(data.append).toHaveBeenCalledWith(
25
- 'singlePage',
26
- 'true'
27
- );
28
- });
29
- });
30
- });
31
-
32
- describe('Page size', () => {
33
- describe('when page size is valid', () => {
34
- it('should append page size to data', () => {
35
- ConverterUtils.addPageProperties(data, {
36
- size: { width: 8.3, height: 11.7 }
37
- });
38
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
39
- expect(data.append).toHaveBeenCalledWith('paperWidth', 8.3);
40
- expect(data.append).toHaveBeenNthCalledWith(
41
- 2,
42
- 'paperHeight',
43
- 11.7
44
- );
45
- });
46
- });
47
- });
48
-
49
- describe('Page margins', () => {
50
- describe('when page margins are valid', () => {
51
- it('should append page margins to data', () => {
52
- ConverterUtils.addPageProperties(data, {
53
- margins: { top: 0.5, bottom: 0.5, left: 1, right: 1 }
54
- });
55
- expect(mockFormDataAppend).toHaveBeenCalledTimes(4);
56
- expect(data.append).toHaveBeenCalledWith('marginTop', 0.5);
57
- expect(data.append).toHaveBeenNthCalledWith(
58
- 2,
59
- 'marginBottom',
60
- 0.5
61
- );
62
- expect(data.append).toHaveBeenNthCalledWith(
63
- 3,
64
- 'marginLeft',
65
- 1
66
- );
67
- expect(data.append).toHaveBeenNthCalledWith(
68
- 4,
69
- 'marginRight',
70
- 1
71
- );
72
- });
73
- });
74
- });
75
-
76
- describe('Page css size', () => {
77
- describe('when preferCssPageSize parameter is set', () => {
78
- it('should append preferCssPageSize to data', () => {
79
- ConverterUtils.addPageProperties(data, {
80
- preferCssPageSize: true
81
- });
82
- expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
83
- expect(data.append).toHaveBeenCalledWith(
84
- 'preferCssPageSize',
85
- 'true'
86
- );
87
- });
88
- });
89
- });
90
-
91
- describe('Page background', () => {
92
- describe('when printBackground parameter is set', () => {
93
- it('should append printBackground to data', () => {
94
- ConverterUtils.addPageProperties(data, {
95
- printBackground: true
96
- });
97
- expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
98
- expect(data.append).toHaveBeenCalledWith(
99
- 'printBackground',
100
- 'true'
101
- );
102
- });
103
- });
104
-
105
- describe('when omitBackground parameter is set', () => {
106
- it('should append omitBackground to data', () => {
107
- ConverterUtils.addPageProperties(data, {
108
- omitBackground: true
109
- });
110
- expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
111
- expect(data.append).toHaveBeenCalledWith(
112
- 'omitBackground',
113
- 'true'
114
- );
115
- });
116
- });
117
- });
118
-
119
- describe('Page landscape', () => {
120
- describe('when landscape parameter is set', () => {
121
- it('should append landscape to data', () => {
122
- ConverterUtils.addPageProperties(data, {
123
- landscape: true
124
- });
125
- expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
126
- expect(data.append).toHaveBeenCalledWith(
127
- 'landscape',
128
- 'true'
129
- );
130
- });
131
- });
132
- });
133
-
134
- describe('Page scale', () => {
135
- describe('when page scale is valid', () => {
136
- it('should append scale to data', () => {
137
- ConverterUtils.addPageProperties(data, {
138
- scale: 1.5
139
- });
140
- expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
141
- expect(data.append).toHaveBeenCalledWith('scale', 1.5);
142
- });
143
- });
144
- });
145
-
146
- describe('Page ranges', () => {
147
- describe('when nativePageRanges is valid', () => {
148
- it('should append nativePageRanges to data', () => {
149
- ConverterUtils.addPageProperties(data, {
150
- nativePageRanges: { from: 1, to: 6 }
151
- });
152
- expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
153
- expect(data.append).toHaveBeenCalledWith(
154
- 'nativePageRanges',
155
- '1-6'
156
- );
157
- });
158
- });
159
- });
160
- });
161
-
162
- describe('addFile', () => {
163
- const __tmp__ = path.resolve(process.cwd(), '__tmp__');
164
- const filePath = path.resolve(__tmp__, 'file.html');
165
-
166
- beforeAll(async () => {
167
- await promises.mkdir(path.resolve(__tmp__), { recursive: true });
168
- await promises.writeFile(filePath, 'data');
169
- });
170
-
171
- afterAll(async () => {
172
- await promises.rm(path.resolve(__tmp__), { recursive: true });
173
- });
174
-
175
- describe('when file is passed as read stream', () => {
176
- it('should append file to data', async () => {
177
- const file = createReadStream(filePath);
178
- await GotenbergUtils.addFile(data, file, 'file');
179
- expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
180
- expect(data.append).toHaveBeenCalledWith('files', file, 'file');
181
- });
182
- });
183
-
184
- describe('when file is passed as path', () => {
185
- it('should append file to data', async () => {
186
- await GotenbergUtils.addFile(data, filePath, 'file');
187
- expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
188
- });
189
- });
190
-
191
- describe('when file is passed as buffer', () => {
192
- it('should append file to data', async () => {
193
- const file = Buffer.from('data');
194
- await GotenbergUtils.addFile(data, file, 'file');
195
- expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
196
- expect(data.append).toHaveBeenCalledWith('files', file, 'file');
197
- });
198
- });
199
- });
200
-
201
- describe('customize', () => {
202
- describe('when no option is passed', () => {
203
- it('should not append anything', async () => {
204
- await ConverterUtils.customize(data, {});
205
- expect(mockFormDataAppend).toHaveBeenCalledTimes(0);
206
- });
207
- });
208
-
209
- describe('when header parameter is passed', () => {
210
- it('should append header', async () => {
211
- await ConverterUtils.customize(data, {
212
- header: Buffer.from('header')
213
- });
214
- expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
215
- expect(data.append).toHaveBeenCalledWith(
216
- 'files',
217
- Buffer.from('header'),
218
- 'header.html'
219
- );
220
- });
221
- });
222
-
223
- describe('when footer parameter is passed', () => {
224
- it('should append footer', async () => {
225
- await ConverterUtils.customize(data, {
226
- footer: Buffer.from('footer')
227
- });
228
- expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
229
- expect(data.append).toHaveBeenCalledWith(
230
- 'files',
231
- Buffer.from('footer'),
232
- 'footer.html'
233
- );
234
- });
235
- });
236
-
237
- describe('when pdf format parameter is passed', () => {
238
- it('should append pdf format', async () => {
239
- await ConverterUtils.customize(data, {
240
- pdfFormat: PdfFormat.A_1a
241
- });
242
- expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
243
- expect(data.append).toHaveBeenCalledWith('pdfa', 'PDF/A-1a');
244
- });
245
- });
246
-
247
- describe('when pdf universal access parameter is passed', () => {
248
- it('should append pdfua format', async () => {
249
- await ConverterUtils.customize(data, {
250
- pdfUA: true
251
- });
252
- expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
253
- expect(data.append).toHaveBeenCalledWith('pdfua', 'true');
254
- });
255
- });
256
-
257
- describe('when page properties parameter is passed', () => {
258
- it('should append page propertiers', async () => {
259
- await ConverterUtils.customize(data, {
260
- properties: { size: { width: 8.3, height: 11.7 } }
261
- });
262
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
263
- expect(data.append).toHaveBeenCalledWith('paperWidth', 8.3);
264
- expect(data.append).toHaveBeenNthCalledWith(
265
- 2,
266
- 'paperHeight',
267
- 11.7
268
- );
269
- });
270
- });
271
-
272
- describe('when emulatedMediaType parameter is passed', () => {
273
- it('should append emulatedMediaType', async () => {
274
- await ConverterUtils.customize(data, {
275
- emulatedMediaType: 'screen'
276
- });
277
- expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
278
- expect(data.append).toHaveBeenCalledWith(
279
- 'emulatedMediaType',
280
- 'screen'
281
- );
282
- });
283
- });
284
-
285
- describe('when waitDelay parameter is passed', () => {
286
- it('should append waitDelay', async () => {
287
- await ConverterUtils.customize(data, {
288
- waitDelay: '5s'
289
- });
290
- expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
291
- expect(data.append).toHaveBeenCalledWith('waitDelay', '5s');
292
- });
293
- });
294
-
295
- describe('when waitForExpression parameter is passed', () => {
296
- it('should append waitForExpression', async () => {
297
- await ConverterUtils.customize(data, {
298
- waitForExpression: "document.readyState === 'complete'"
299
- });
300
- expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
301
- expect(data.append).toHaveBeenCalledWith(
302
- 'waitForExpression',
303
- "document.readyState === 'complete'"
304
- );
305
- });
306
- });
307
-
308
- describe('when userAgent parameter is passed', () => {
309
- it('should append userAgent', async () => {
310
- const userAgent =
311
- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36';
312
-
313
- await ConverterUtils.customize(data, {
314
- userAgent
315
- });
316
- expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
317
- expect(data.append).toHaveBeenCalledWith(
318
- 'userAgent',
319
- userAgent
320
- );
321
- });
322
- });
323
-
324
- describe('when extraHttpHeaders parameter is passed', () => {
325
- it('should append extraHttpHeaders', async () => {
326
- const extraHttpHeaders = {
327
- 'X-Custom-Header': 'value'
328
- };
329
-
330
- await ConverterUtils.customize(data, {
331
- extraHttpHeaders
332
- });
333
- expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
334
- expect(data.append).toHaveBeenCalledWith(
335
- 'extraHttpHeaders',
336
- JSON.stringify(extraHttpHeaders)
337
- );
338
- });
339
- });
340
-
341
- describe('when failOnConsoleExceptions parameter is passed', () => {
342
- it('should append failOnConsoleExceptions', async () => {
343
- await ConverterUtils.customize(data, {
344
- failOnConsoleExceptions: true
345
- });
346
- expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
347
- expect(data.append).toHaveBeenCalledWith(
348
- 'failOnConsoleExceptions',
349
- 'true'
350
- );
351
- });
352
- });
353
-
354
- describe('when metadata parameter is passed', () => {
355
- it('should append metadata', async () => {
356
- await ConverterUtils.customize(data, {
357
- metadata: { Author: 'John Doe' }
358
- });
359
- expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
360
- expect(data.append).toHaveBeenCalledWith(
361
- 'metadata',
362
- JSON.stringify({ Author: 'John Doe' })
363
- );
364
- });
365
- });
366
-
367
- describe('when cookies parameter is passed', () => {
368
- it('should append cookies', async () => {
369
- await ConverterUtils.customize(data, {
370
- cookies: [
371
- {
372
- name: 'sample_id',
373
- value: 'sample_value',
374
- domain: 'example.com',
375
- path: '/',
376
- secure: true,
377
- httpOnly: true,
378
- sameSite: 'Strict'
379
- }
380
- ]
381
- });
382
- expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
383
- expect(data.append).toHaveBeenCalledWith(
384
- 'cookies',
385
- JSON.stringify([
386
- {
387
- name: 'sample_id',
388
- value: 'sample_value',
389
- domain: 'example.com',
390
- path: '/',
391
- secure: true,
392
- httpOnly: true,
393
- sameSite: 'Strict'
394
- }
395
- ])
396
- );
397
- });
398
- });
399
-
400
- describe('when all options are passed', () => {
401
- it('should append all options', async () => {
402
- await ConverterUtils.customize(data, {
403
- header: Buffer.from('header.html'),
404
- footer: Buffer.from('footer.html'),
405
- pdfFormat: PdfFormat.A_1a,
406
- pdfUA: true,
407
- emulatedMediaType: 'screen',
408
- properties: { size: { width: 8.3, height: 11.7 } },
409
- waitDelay: '5s',
410
- waitForExpression: "document.readyState === 'complete'",
411
- userAgent:
412
- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
413
- extraHttpHeaders: { 'X-Custom-Header': 'value' },
414
- failOnHttpStatusCodes: [499, 599],
415
- skipNetworkIdleEvent: true,
416
- failOnConsoleExceptions: true,
417
- metadata: { Author: 'John Doe' }
418
- });
419
- expect(mockFormDataAppend).toHaveBeenCalledTimes(15);
420
- expect(data.append).toHaveBeenNthCalledWith(
421
- 1,
422
- 'pdfa',
423
- 'PDF/A-1a'
424
- );
425
- expect(data.append).toHaveBeenNthCalledWith(2, 'pdfua', 'true');
426
- expect(data.append).toHaveBeenNthCalledWith(
427
- 3,
428
- 'files',
429
- Buffer.from('header.html'),
430
- 'header.html'
431
- );
432
- expect(data.append).toHaveBeenNthCalledWith(
433
- 4,
434
- 'files',
435
- Buffer.from('footer.html'),
436
- 'footer.html'
437
- );
438
- expect(data.append).toHaveBeenNthCalledWith(
439
- 5,
440
- 'emulatedMediaType',
441
- 'screen'
442
- );
443
- expect(data.append).toHaveBeenNthCalledWith(
444
- 6,
445
- 'paperWidth',
446
- 8.3
447
- );
448
- expect(data.append).toHaveBeenNthCalledWith(
449
- 7,
450
- 'paperHeight',
451
- 11.7
452
- );
453
- expect(data.append).toHaveBeenNthCalledWith(
454
- 8,
455
- 'waitDelay',
456
- '5s'
457
- );
458
- expect(data.append).toHaveBeenNthCalledWith(
459
- 9,
460
- 'waitForExpression',
461
- "document.readyState === 'complete'"
462
- );
463
- expect(data.append).toHaveBeenNthCalledWith(
464
- 10,
465
- 'userAgent',
466
- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
467
- );
468
- expect(data.append).toHaveBeenNthCalledWith(
469
- 11,
470
- 'extraHttpHeaders',
471
- JSON.stringify({ 'X-Custom-Header': 'value' })
472
- );
473
- expect(data.append).toHaveBeenNthCalledWith(
474
- 12,
475
- 'failOnHttpStatusCodes',
476
- JSON.stringify([499, 599])
477
- );
478
- expect(data.append).toHaveBeenNthCalledWith(
479
- 13,
480
- 'failOnConsoleExceptions',
481
- 'true'
482
- );
483
- expect(data.append).toHaveBeenNthCalledWith(
484
- 14,
485
- 'skipNetworkIdleEvent',
486
- 'true'
487
- );
488
- expect(data.append).toHaveBeenNthCalledWith(
489
- 15,
490
- 'metadata',
491
- JSON.stringify({ Author: 'John Doe' })
492
- );
493
- });
494
- });
495
- });
496
- });