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,96 +0,0 @@
1
- import { URL } from 'url';
2
- import FormData from 'form-data';
3
- import { GotenbergUtils, PathLikeOrReadStream } from '../../common';
4
- import { ImageProperties } from '../interfaces/screenshot.types';
5
- import { ScreenshotUtils } from '../utils/screenshot.utils';
6
- import { Screenshot } from './screenshot';
7
- import { ChromiumRoute, Chromiumly } from '../../main.config';
8
- import { EmulatedMediaType } from '../interfaces/common.types';
9
-
10
- /**
11
- * Class representing a URL screenshot that extends the base screenshot class.
12
- * This class is used to screenshot a URL using Gotenberg service.
13
- *
14
- * @extends Screenshot
15
- */
16
- export class UrlScreenshot extends Screenshot {
17
- /**
18
- * Creates an instance of UrlScreenshot.
19
- * Initializes the screenshot with the URL screenshot route.
20
- */
21
- constructor() {
22
- super(ChromiumRoute.URL);
23
- }
24
-
25
- /**
26
- * Screenshots URL.
27
- *
28
- * @param {Object} options - Screenshot options.
29
- * @param {string} options.url - The URL of the content to be screenshoted
30
- * @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content.
31
- * @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content.
32
- * @param {ImageProperties} [options.properties] - Image properties for the screenshot.
33
- * @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the screenshot.
34
- * @param {string} [options.waitDelay] - Delay before the screenshot process starts.
35
- * @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the screenshot.
36
- * @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the screenshot.
37
- * @param {number []} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
38
- * @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during screenshot.
39
- * @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
40
- * @param {boolean} [options.optimizeForSpeed] - Whether to optimize for speed.
41
- * @returns {Promise<Buffer>} A Promise resolving to the image buffer.
42
- */
43
- async capture({
44
- url,
45
- header,
46
- footer,
47
- properties,
48
- emulatedMediaType,
49
- waitDelay,
50
- waitForExpression,
51
- extraHttpHeaders,
52
- failOnHttpStatusCodes,
53
- failOnConsoleExceptions,
54
- skipNetworkIdleEvent,
55
- optimizeForSpeed
56
- }: {
57
- url: string;
58
- header?: PathLikeOrReadStream;
59
- footer?: PathLikeOrReadStream;
60
- properties?: ImageProperties;
61
- emulatedMediaType?: EmulatedMediaType;
62
- waitDelay?: string;
63
- waitForExpression?: string;
64
- extraHttpHeaders?: Record<string, string>;
65
- failOnHttpStatusCodes?: number[];
66
- failOnConsoleExceptions?: boolean;
67
- skipNetworkIdleEvent?: boolean;
68
- optimizeForSpeed?: boolean;
69
- }): Promise<Buffer> {
70
- const _url = new URL(url);
71
- const data = new FormData();
72
-
73
- data.append('url', _url.href);
74
-
75
- await ScreenshotUtils.customize(data, {
76
- header,
77
- footer,
78
- properties,
79
- emulatedMediaType,
80
- waitDelay,
81
- waitForExpression,
82
- extraHttpHeaders,
83
- failOnHttpStatusCodes,
84
- failOnConsoleExceptions,
85
- skipNetworkIdleEvent,
86
- optimizeForSpeed
87
- });
88
-
89
- return GotenbergUtils.fetch(
90
- this.endpoint,
91
- data,
92
- Chromiumly.getGotenbergApiBasicAuthUsername(),
93
- Chromiumly.getGotenbergApiBasicAuthPassword()
94
- );
95
- }
96
- }
@@ -1,187 +0,0 @@
1
- import FormData from 'form-data';
2
-
3
- import {
4
- ConversionOptions,
5
- PageProperties
6
- } from '../interfaces/converter.types';
7
- import { GotenbergUtils } from '../../common';
8
-
9
- /**
10
- * Utility class for handling common tasks related to conversion.
11
- */
12
- export class ConverterUtils {
13
- /**
14
- * Adds page properties to the FormData object based on the provided PageProperties.
15
- *
16
- * @param {FormData} data - The FormData object to which page properties will be added.
17
- * @param {PageProperties} pageProperties - The page properties to be added to the FormData.
18
- */
19
- public static addPageProperties(
20
- data: FormData,
21
- pageProperties: PageProperties
22
- ): void {
23
- if (pageProperties.singlePage) {
24
- data.append('singlePage', String(pageProperties.singlePage));
25
- }
26
-
27
- if (pageProperties.size) {
28
- GotenbergUtils.assert(
29
- pageProperties.size.width >= 1.0 &&
30
- pageProperties.size.height >= 1.5,
31
- 'size is smaller than the minimum printing requirements (i.e. 1.0 x 1.5 in)'
32
- );
33
-
34
- data.append('paperWidth', pageProperties.size.width);
35
- data.append('paperHeight', pageProperties.size.height);
36
- }
37
-
38
- if (pageProperties.margins) {
39
- GotenbergUtils.assert(
40
- pageProperties.margins.top >= 0 &&
41
- pageProperties.margins.bottom >= 0 &&
42
- pageProperties.margins.left >= 0 &&
43
- pageProperties.margins.left >= 0,
44
- 'negative margins are not allowed'
45
- );
46
-
47
- data.append('marginTop', pageProperties.margins.top);
48
- data.append('marginBottom', pageProperties.margins.bottom);
49
- data.append('marginLeft', pageProperties.margins.left);
50
- data.append('marginRight', pageProperties.margins.right);
51
- }
52
-
53
- if (pageProperties.preferCssPageSize) {
54
- data.append(
55
- 'preferCssPageSize',
56
- String(pageProperties.preferCssPageSize)
57
- );
58
- }
59
-
60
- if (pageProperties.printBackground) {
61
- data.append(
62
- 'printBackground',
63
- String(pageProperties.printBackground)
64
- );
65
- }
66
-
67
- if (pageProperties.omitBackground) {
68
- data.append(
69
- 'omitBackground',
70
- String(pageProperties.omitBackground)
71
- );
72
- }
73
-
74
- if (pageProperties.landscape) {
75
- data.append('landscape', String(pageProperties.landscape));
76
- }
77
-
78
- if (pageProperties.scale) {
79
- GotenbergUtils.assert(
80
- pageProperties.scale >= 0.1 && pageProperties.scale <= 2.0,
81
- 'scale is outside of [0.1 - 2] range'
82
- );
83
-
84
- data.append('scale', pageProperties.scale);
85
- }
86
-
87
- if (pageProperties.nativePageRanges) {
88
- GotenbergUtils.assert(
89
- pageProperties.nativePageRanges.from > 0 &&
90
- pageProperties.nativePageRanges.to > 0 &&
91
- pageProperties.nativePageRanges.to >=
92
- pageProperties.nativePageRanges.from,
93
- 'page ranges syntax error'
94
- );
95
-
96
- data.append(
97
- 'nativePageRanges',
98
- `${pageProperties.nativePageRanges.from}-${pageProperties.nativePageRanges.to}`
99
- );
100
- }
101
- }
102
-
103
- /**
104
- * Customizes the FormData object based on the provided conversion options.
105
- *
106
- * @param {FormData} data - The FormData object to be customized.
107
- * @param {ConversionOptions} options - The conversion options to apply to the FormData.
108
- * @returns {Promise<void>} A Promise that resolves once the customization is complete.
109
- */
110
- public static async customize(
111
- data: FormData,
112
- options: ConversionOptions
113
- ): Promise<void> {
114
- if (options.pdfFormat) {
115
- data.append('pdfa', options.pdfFormat);
116
- }
117
-
118
- if (options.pdfUA) {
119
- data.append('pdfua', String(options.pdfUA));
120
- }
121
-
122
- if (options.header) {
123
- const { header } = options;
124
- await GotenbergUtils.addFile(data, header, 'header.html');
125
- }
126
-
127
- if (options.footer) {
128
- const { footer } = options;
129
- await GotenbergUtils.addFile(data, footer, 'footer.html');
130
- }
131
-
132
- if (options.emulatedMediaType) {
133
- data.append('emulatedMediaType', options.emulatedMediaType);
134
- }
135
-
136
- if (options.properties) {
137
- ConverterUtils.addPageProperties(data, options.properties);
138
- }
139
-
140
- if (options.waitDelay) {
141
- data.append('waitDelay', options.waitDelay);
142
- }
143
-
144
- if (options.waitForExpression) {
145
- data.append('waitForExpression', options.waitForExpression);
146
- }
147
-
148
- if (options.userAgent) {
149
- data.append('userAgent', options.userAgent);
150
- }
151
-
152
- if (options.extraHttpHeaders) {
153
- data.append(
154
- 'extraHttpHeaders',
155
- JSON.stringify(options.extraHttpHeaders)
156
- );
157
- }
158
-
159
- if (options.failOnHttpStatusCodes) {
160
- data.append(
161
- 'failOnHttpStatusCodes',
162
- JSON.stringify(options.failOnHttpStatusCodes)
163
- );
164
- }
165
-
166
- if (options.failOnConsoleExceptions) {
167
- data.append(
168
- 'failOnConsoleExceptions',
169
- String(options.failOnConsoleExceptions)
170
- );
171
- }
172
-
173
- if (options.skipNetworkIdleEvent) {
174
- data.append(
175
- 'skipNetworkIdleEvent',
176
- String(options.skipNetworkIdleEvent)
177
- );
178
- }
179
- if (options.metadata) {
180
- data.append('metadata', JSON.stringify(options.metadata));
181
- }
182
-
183
- if (options.cookies) {
184
- data.append('cookies', JSON.stringify(options.cookies));
185
- }
186
- }
187
- }
@@ -1,127 +0,0 @@
1
- import {
2
- ImageProperties,
3
- ScreenshotOptions
4
- } from './../interfaces/screenshot.types';
5
- import FormData from 'form-data';
6
-
7
- import { GotenbergUtils } from '../../common';
8
-
9
- /**
10
- * Utility class for handling common tasks related to screenshot.
11
- */
12
- export class ScreenshotUtils {
13
- /**
14
- * Adds page properties to the FormData object based on the provided imageProperties.
15
- *
16
- * @param {FormData} data - The FormData object to which page properties will be added.
17
- * @param {ImageProperties} imageProperties - The page properties to be added to the FormData.
18
- */
19
- public static addImageProperties(
20
- data: FormData,
21
- imageProperties: ImageProperties
22
- ): void {
23
- data.append('format', imageProperties.format);
24
-
25
- if (imageProperties.quality) {
26
- GotenbergUtils.assert(
27
- imageProperties.format === 'jpeg',
28
- 'Compression quality is exclusively supported for JPEG format.'
29
- );
30
- GotenbergUtils.assert(
31
- imageProperties.quality >= 0 && imageProperties.quality <= 100,
32
- 'Invalid compression quality. Please provide a value between 0 and 100.'
33
- );
34
-
35
- data.append('quality', imageProperties.quality);
36
- }
37
-
38
- if (imageProperties.omitBackground) {
39
- data.append(
40
- 'omitBackground',
41
- String(imageProperties.omitBackground)
42
- );
43
- }
44
-
45
- if (imageProperties.width) {
46
- data.append('width', imageProperties.width);
47
- }
48
-
49
- if (imageProperties.height) {
50
- data.append('height', imageProperties.height);
51
- }
52
-
53
- if (imageProperties.clip) {
54
- data.append('clip', String(imageProperties.clip));
55
- }
56
- }
57
-
58
- /**
59
- * Customizes the FormData object based on the provided screenshot options.
60
- *
61
- * @param {FormData} data - The FormData object to be customized.
62
- * @param {ScreenshotOptions} options - The screenshot options to apply to the FormData.
63
- * @returns {Promise<void>} A Promise that resolves once the customization is complete.
64
- */
65
- public static async customize(
66
- data: FormData,
67
- options: ScreenshotOptions
68
- ): Promise<void> {
69
- if (options.header) {
70
- const { header } = options;
71
- await GotenbergUtils.addFile(data, header, 'header.html');
72
- }
73
-
74
- if (options.footer) {
75
- const { footer } = options;
76
- await GotenbergUtils.addFile(data, footer, 'footer.html');
77
- }
78
-
79
- if (options.emulatedMediaType) {
80
- data.append('emulatedMediaType', options.emulatedMediaType);
81
- }
82
-
83
- if (options.properties) {
84
- ScreenshotUtils.addImageProperties(data, options.properties);
85
- }
86
-
87
- if (options.waitDelay) {
88
- data.append('waitDelay', options.waitDelay);
89
- }
90
-
91
- if (options.waitForExpression) {
92
- data.append('waitForExpression', options.waitForExpression);
93
- }
94
-
95
- if (options.extraHttpHeaders) {
96
- data.append(
97
- 'extraHttpHeaders',
98
- JSON.stringify(options.extraHttpHeaders)
99
- );
100
- }
101
-
102
- if (options.failOnHttpStatusCodes) {
103
- data.append(
104
- 'failOnHttpStatusCodes',
105
- JSON.stringify(options.failOnHttpStatusCodes)
106
- );
107
- }
108
-
109
- if (options.failOnConsoleExceptions) {
110
- data.append(
111
- 'failOnConsoleExceptions',
112
- String(options.failOnConsoleExceptions)
113
- );
114
- }
115
-
116
- if (options.skipNetworkIdleEvent) {
117
- data.append(
118
- 'skipNetworkIdleEvent',
119
- String(options.skipNetworkIdleEvent)
120
- );
121
- }
122
-
123
- if (options.optimizeForSpeed) {
124
- data.append('optimizeForSpeed', String(options.optimizeForSpeed));
125
- }
126
- }
127
- }