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.
- package/README.md +1 -0
- package/dist/chromium/converters/html.converter.js +1 -1
- package/dist/pdf-engines/utils/pdf-engines.utils.js +5 -5
- package/dist/pdf-engines/utils/pdf-engines.utils.js.map +1 -1
- package/package.json +13 -10
- package/src/.prettierrc.yml +0 -4
- package/src/chromium/converters/converter.ts +0 -22
- package/src/chromium/converters/html.converter.ts +0 -134
- package/src/chromium/converters/markdown.converter.ts +0 -129
- package/src/chromium/converters/tests/html.converter.test.ts +0 -190
- package/src/chromium/converters/tests/markdown.converter.test.ts +0 -187
- package/src/chromium/converters/tests/url.converter.test.ts +0 -164
- package/src/chromium/converters/url.converter.ts +0 -125
- package/src/chromium/index.ts +0 -6
- package/src/chromium/interfaces/common.types.ts +0 -15
- package/src/chromium/interfaces/converter.types.ts +0 -45
- package/src/chromium/interfaces/screenshot.types.ts +0 -15
- package/src/chromium/screenshots/html.screenshot.ts +0 -105
- package/src/chromium/screenshots/markdown.screenshot.ts +0 -100
- package/src/chromium/screenshots/screenshot.ts +0 -22
- package/src/chromium/screenshots/tests/html.screenshot.test.ts +0 -192
- package/src/chromium/screenshots/tests/markdown.screenshot.test.ts +0 -176
- package/src/chromium/screenshots/tests/url.screenshot.test.ts +0 -166
- package/src/chromium/screenshots/url.screenshot.ts +0 -96
- package/src/chromium/utils/converter.utils.ts +0 -187
- package/src/chromium/utils/screenshot.utils.ts +0 -127
- package/src/chromium/utils/tests/converter.utils.test.ts +0 -496
- package/src/chromium/utils/tests/screenshot.utils.test.ts +0 -338
- package/src/common/constants.ts +0 -9
- package/src/common/gotenberg.utils.ts +0 -86
- package/src/common/index.ts +0 -3
- package/src/common/tests/gotenberg.utils.test.ts +0 -141
- package/src/common/types.ts +0 -7
- package/src/gotenberg.ts +0 -54
- package/src/libre-office/index.ts +0 -1
- package/src/libre-office/interfaces/libre-office.types.ts +0 -156
- package/src/libre-office/libre-office.ts +0 -61
- package/src/libre-office/tests/libre-office.test.ts +0 -56
- package/src/libre-office/utils/constants.ts +0 -132
- package/src/libre-office/utils/libre-office.utils.ts +0 -128
- package/src/libre-office/utils/tests/libre-office.utils.test.ts +0 -156
- package/src/main.config.ts +0 -157
- package/src/main.ts +0 -13
- package/src/pdf-engines/index.ts +0 -1
- package/src/pdf-engines/interfaces/pdf-engines.types.ts +0 -10
- package/src/pdf-engines/pdf-engines.ts +0 -156
- package/src/pdf-engines/tests/pdf.engine.test.ts +0 -163
- package/src/pdf-engines/utils/pdf-engines.utils.ts +0 -68
- package/src/pdf-engines/utils/tests/pdf-engines.utils.test.ts +0 -71
package/README.md
CHANGED
|
@@ -67,7 +67,7 @@ class HtmlConverter extends converter_1.Converter {
|
|
|
67
67
|
metadata,
|
|
68
68
|
cookies
|
|
69
69
|
});
|
|
70
|
-
return common_1.GotenbergUtils.fetch(this.endpoint, data, main_config_1.Chromiumly.
|
|
70
|
+
return common_1.GotenbergUtils.fetch(this.endpoint, data, main_config_1.Chromiumly.getGotenbergApiBasicAuthUsername(), main_config_1.Chromiumly.getGotenbergApiBasicAuthPassword());
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
}
|
|
@@ -17,7 +17,7 @@ class PDFEnginesUtils {
|
|
|
17
17
|
*/
|
|
18
18
|
static addFiles(files, data) {
|
|
19
19
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
|
|
20
|
+
yield Promise.all(files.map((file, key) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
21
21
|
const filename = `file${key}.pdf`;
|
|
22
22
|
if (Buffer.isBuffer(file)) {
|
|
23
23
|
data.append('files', file, filename);
|
|
@@ -27,16 +27,16 @@ class PDFEnginesUtils {
|
|
|
27
27
|
}
|
|
28
28
|
else {
|
|
29
29
|
yield fs_1.promises.access(file, fs_1.constants.R_OK);
|
|
30
|
-
const
|
|
31
|
-
const extension = path_1.default.extname(
|
|
30
|
+
const _filename = path_1.default.basename(file.toString());
|
|
31
|
+
const extension = path_1.default.extname(_filename);
|
|
32
32
|
if (extension === '.pdf') {
|
|
33
|
-
data.append(
|
|
33
|
+
data.append(_filename, (0, fs_1.createReadStream)(file));
|
|
34
34
|
}
|
|
35
35
|
else {
|
|
36
36
|
throw new Error(`${extension} is not supported`);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
}
|
|
39
|
+
})));
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pdf-engines.utils.js","sourceRoot":"","sources":["../../../src/pdf-engines/utils/pdf-engines.utils.ts"],"names":[],"mappings":";;;;AAAA,2BAAuE;AACvE,wDAAwB;AASxB;;GAEG;AACH,MAAa,eAAe;IACxB;;;;;;OAMG;IACI,MAAM,CAAO,QAAQ,CACxB,KAA6B,EAC7B,IAAc;;YAEd,
|
|
1
|
+
{"version":3,"file":"pdf-engines.utils.js","sourceRoot":"","sources":["../../../src/pdf-engines/utils/pdf-engines.utils.ts"],"names":[],"mappings":";;;;AAAA,2BAAuE;AACvE,wDAAwB;AASxB;;GAEG;AACH,MAAa,eAAe;IACxB;;;;;;OAMG;IACI,MAAM,CAAO,QAAQ,CACxB,KAA6B,EAC7B,IAAc;;YAEd,MAAM,OAAO,CAAC,GAAG,CACb,KAAK,CAAC,GAAG,CAAC,CAAO,IAAI,EAAE,GAAG,EAAE,EAAE;gBAC1B,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;gBAClC,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;oBACxB,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;gBACzC,CAAC;qBAAM,IAAI,IAAI,YAAY,eAAU,EAAE,CAAC;oBACpC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;gBACzC,CAAC;qBAAM,CAAC;oBACJ,MAAM,aAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,cAAS,CAAC,IAAI,CAAC,CAAC;oBAC5C,MAAM,SAAS,GAAG,cAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;oBACjD,MAAM,SAAS,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;oBAC1C,IAAI,SAAS,KAAK,MAAM,EAAE,CAAC;wBACvB,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,IAAA,qBAAgB,EAAC,IAAI,CAAC,CAAC,CAAC;oBACnD,CAAC;yBAAM,CAAC;wBACJ,MAAM,IAAI,KAAK,CAAC,GAAG,SAAS,mBAAmB,CAAC,CAAC;oBACrD,CAAC;gBACL,CAAC;YACL,CAAC,CAAA,CAAC,CACL,CAAC;QACN,CAAC;KAAA;IAED;;;;;;OAMG;IACI,MAAM,CAAO,SAAS,CACzB,IAAc,EACd,OAAyC;;YAEzC,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;gBACf,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;YACtC,CAAC;YAED,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;gBAChB,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;YAChD,CAAC;YAED,IAAI,UAAU,IAAI,OAAO,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;gBAC5C,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC9D,CAAC;QACL,CAAC;KAAA;CACJ;AAxDD,0CAwDC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chromiumly",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.2",
|
|
4
4
|
"description": "A lightweight Typescript library that interacts with Gotenberg's different modules to convert a variety of document formats to PDF files.",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"types": "dist/main.d.ts",
|
|
7
7
|
"files": [
|
|
8
|
-
"dist"
|
|
9
|
-
"src"
|
|
8
|
+
"dist"
|
|
10
9
|
],
|
|
11
10
|
"repository": {
|
|
12
11
|
"type": "git",
|
|
@@ -21,9 +20,13 @@
|
|
|
21
20
|
"gotenberg",
|
|
22
21
|
"chromium",
|
|
23
22
|
"LibreOffice",
|
|
23
|
+
"screenshots",
|
|
24
24
|
"html",
|
|
25
25
|
"markdown",
|
|
26
|
-
"pdf"
|
|
26
|
+
"pdf",
|
|
27
|
+
"docx",
|
|
28
|
+
"pptx",
|
|
29
|
+
"xlsx"
|
|
27
30
|
],
|
|
28
31
|
"scripts": {
|
|
29
32
|
"clean": "rm -rf dist build",
|
|
@@ -41,7 +44,7 @@
|
|
|
41
44
|
}
|
|
42
45
|
},
|
|
43
46
|
"devDependencies": {
|
|
44
|
-
"@babel/preset-typescript": "7.24.
|
|
47
|
+
"@babel/preset-typescript": "7.24.7",
|
|
45
48
|
"@commitlint/cli": "^19.0.3",
|
|
46
49
|
"@commitlint/config-conventional": "^19.0.3",
|
|
47
50
|
"@commitlint/cz-commitlint": "^19.0.3",
|
|
@@ -50,10 +53,10 @@
|
|
|
50
53
|
"@types/dotenv": "8.2.0",
|
|
51
54
|
"@types/form-data": "2.5.0",
|
|
52
55
|
"@types/jest": "29.5.12",
|
|
53
|
-
"@types/node": "20.
|
|
56
|
+
"@types/node": "20.14.2",
|
|
54
57
|
"@types/node-fetch": "2.6.11",
|
|
55
|
-
"@typescript-eslint/eslint-plugin": "7.
|
|
56
|
-
"@typescript-eslint/parser": "7.
|
|
58
|
+
"@typescript-eslint/eslint-plugin": "7.13.0",
|
|
59
|
+
"@typescript-eslint/parser": "7.13.0",
|
|
57
60
|
"commitizen": "4.3.0",
|
|
58
61
|
"eslint": "8.57.0",
|
|
59
62
|
"eslint-config-prettier": "^9.1.0",
|
|
@@ -62,11 +65,11 @@
|
|
|
62
65
|
"jest": "29.7.0",
|
|
63
66
|
"jest-junit": "16.0.0",
|
|
64
67
|
"lint-staged": "^15.2.2",
|
|
65
|
-
"prettier": "3.2
|
|
68
|
+
"prettier": "3.3.2",
|
|
66
69
|
"release-it": "17.3.0",
|
|
67
70
|
"ts-jest": "29.1.4",
|
|
68
71
|
"ts-node": "10.9.2",
|
|
69
|
-
"tslib": "2.6.
|
|
72
|
+
"tslib": "2.6.3",
|
|
70
73
|
"typescript": "5.4.5"
|
|
71
74
|
},
|
|
72
75
|
"dependencies": {
|
package/src/.prettierrc.yml
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Chromiumly, ChromiumRoute } from '../../main.config';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Abstract class representing a generic converter.
|
|
5
|
-
* Concrete converter classes should extend this class and implement specific conversion logic.
|
|
6
|
-
*/
|
|
7
|
-
export abstract class Converter {
|
|
8
|
-
/**
|
|
9
|
-
* The endpoint URL for the converter.
|
|
10
|
-
*/
|
|
11
|
-
readonly endpoint: string;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Creates an instance of the Converter class.
|
|
15
|
-
* Initializes the endpoint URL based on the provided ChromiumRoute.
|
|
16
|
-
*
|
|
17
|
-
* @param {ChromiumRoute} route - The ChromiumRoute enum value representing the conversion route.
|
|
18
|
-
*/
|
|
19
|
-
constructor(route: ChromiumRoute) {
|
|
20
|
-
this.endpoint = `${Chromiumly.getGotenbergEndpoint()}/${Chromiumly.CHROMIUM_CONVERT_PATH}/${Chromiumly.CHROMIUM_ROUTES[route]}`;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import FormData from 'form-data';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
GotenbergUtils,
|
|
5
|
-
Metadata,
|
|
6
|
-
PathLikeOrReadStream,
|
|
7
|
-
PdfFormat
|
|
8
|
-
} from '../../common';
|
|
9
|
-
import { Cookie, PageProperties } from '../interfaces/converter.types';
|
|
10
|
-
import { ConverterUtils } from '../utils/converter.utils';
|
|
11
|
-
import { Converter } from './converter';
|
|
12
|
-
import { ChromiumRoute, Chromiumly } from '../../main.config';
|
|
13
|
-
import { EmulatedMediaType } from '../interfaces/common.types';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Class representing an HTML converter that extends the base Converter class.
|
|
17
|
-
* This class is used to convert HTML content to PDF using Gotenberg service.
|
|
18
|
-
*
|
|
19
|
-
* @extends Converter
|
|
20
|
-
*/
|
|
21
|
-
export class HtmlConverter extends Converter {
|
|
22
|
-
/**
|
|
23
|
-
* Creates an instance of HtmlConverter.
|
|
24
|
-
* Initializes the converter with the HTML conversion route.
|
|
25
|
-
*/
|
|
26
|
-
constructor() {
|
|
27
|
-
super(ChromiumRoute.HTML);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Converts HTML content to PDF.
|
|
32
|
-
*
|
|
33
|
-
* @param {Object} options - Conversion options.
|
|
34
|
-
* @param {PathLikeOrReadStream} options.html - PathLike or ReadStream of the HTML content to be converted.
|
|
35
|
-
* @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content.
|
|
36
|
-
* @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content.
|
|
37
|
-
* @param {PageProperties} [options.properties] - Page properties for the conversion.
|
|
38
|
-
* @param {PdfFormat} [options.pdfFormat] - PDF format options.
|
|
39
|
-
* @param {boolean} [options.pdfUA] - Indicates whether to generate PDF/UA compliant output.
|
|
40
|
-
* @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the conversion.
|
|
41
|
-
* @param {string} [options.waitDelay] - Delay before the conversion process starts.
|
|
42
|
-
* @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the conversion.
|
|
43
|
-
* @param {string} [options.userAgent] - User agent string to use during the conversion.
|
|
44
|
-
* @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the conversion.
|
|
45
|
-
* @param {number[]} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
46
|
-
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during conversion.
|
|
47
|
-
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
48
|
-
* @param {Metadata} options.metadata - Metadata to be written.
|
|
49
|
-
* @param {Cookie[]} options.cookies - Cookies to be written.
|
|
50
|
-
* @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
|
|
51
|
-
*/
|
|
52
|
-
async convert({
|
|
53
|
-
html,
|
|
54
|
-
assets,
|
|
55
|
-
header,
|
|
56
|
-
footer,
|
|
57
|
-
properties,
|
|
58
|
-
pdfFormat,
|
|
59
|
-
pdfUA,
|
|
60
|
-
emulatedMediaType,
|
|
61
|
-
waitDelay,
|
|
62
|
-
waitForExpression,
|
|
63
|
-
userAgent,
|
|
64
|
-
extraHttpHeaders,
|
|
65
|
-
failOnHttpStatusCodes,
|
|
66
|
-
failOnConsoleExceptions,
|
|
67
|
-
skipNetworkIdleEvent,
|
|
68
|
-
metadata,
|
|
69
|
-
cookies
|
|
70
|
-
}: {
|
|
71
|
-
html: PathLikeOrReadStream;
|
|
72
|
-
assets?: { file: PathLikeOrReadStream; name: string }[];
|
|
73
|
-
header?: PathLikeOrReadStream;
|
|
74
|
-
footer?: PathLikeOrReadStream;
|
|
75
|
-
properties?: PageProperties;
|
|
76
|
-
/**
|
|
77
|
-
* @deprecated Starting from Gotenberg version 8.0.0, Chromium no longer provides support for pdfFormat.
|
|
78
|
-
* @see {@link https://github.com/gotenberg/gotenberg/releases/tag/v8.0.0}
|
|
79
|
-
*/
|
|
80
|
-
pdfFormat?: PdfFormat;
|
|
81
|
-
pdfUA?: boolean;
|
|
82
|
-
emulatedMediaType?: EmulatedMediaType;
|
|
83
|
-
waitDelay?: string;
|
|
84
|
-
waitForExpression?: string;
|
|
85
|
-
/**
|
|
86
|
-
* @deprecated Starting from Gotenberg version 8.0.0, Chromium no longer provides support for userAgent.
|
|
87
|
-
* @see {@link https://github.com/gotenberg/gotenberg/releases/tag/v8.0.0}
|
|
88
|
-
*/
|
|
89
|
-
userAgent?: string;
|
|
90
|
-
extraHttpHeaders?: Record<string, string>;
|
|
91
|
-
failOnHttpStatusCodes?: number[];
|
|
92
|
-
failOnConsoleExceptions?: boolean;
|
|
93
|
-
skipNetworkIdleEvent?: boolean;
|
|
94
|
-
metadata?: Metadata;
|
|
95
|
-
cookies?: Cookie[];
|
|
96
|
-
}): Promise<Buffer> {
|
|
97
|
-
const data = new FormData();
|
|
98
|
-
|
|
99
|
-
await GotenbergUtils.addFile(data, html, 'index.html');
|
|
100
|
-
|
|
101
|
-
if (assets?.length) {
|
|
102
|
-
await Promise.all(
|
|
103
|
-
assets.map(({ file, name }) =>
|
|
104
|
-
GotenbergUtils.addFile(data, file, name)
|
|
105
|
-
)
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
await ConverterUtils.customize(data, {
|
|
110
|
-
header,
|
|
111
|
-
footer,
|
|
112
|
-
properties,
|
|
113
|
-
pdfFormat,
|
|
114
|
-
pdfUA,
|
|
115
|
-
emulatedMediaType,
|
|
116
|
-
waitDelay,
|
|
117
|
-
waitForExpression,
|
|
118
|
-
userAgent,
|
|
119
|
-
extraHttpHeaders,
|
|
120
|
-
failOnHttpStatusCodes,
|
|
121
|
-
failOnConsoleExceptions,
|
|
122
|
-
skipNetworkIdleEvent,
|
|
123
|
-
metadata,
|
|
124
|
-
cookies
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
return GotenbergUtils.fetch(
|
|
128
|
-
this.endpoint,
|
|
129
|
-
data,
|
|
130
|
-
Chromiumly.getGotenbergApiBasicAuthPassword(),
|
|
131
|
-
Chromiumly.getGotenbergApiBasicAuthPassword()
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import FormData from 'form-data';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
GotenbergUtils,
|
|
5
|
-
PdfFormat,
|
|
6
|
-
PathLikeOrReadStream,
|
|
7
|
-
Metadata
|
|
8
|
-
} from '../../common';
|
|
9
|
-
import { Cookie, PageProperties } from '../interfaces/converter.types';
|
|
10
|
-
import { ConverterUtils } from '../utils/converter.utils';
|
|
11
|
-
import { Converter } from './converter';
|
|
12
|
-
import { ChromiumRoute, Chromiumly } from '../../main.config';
|
|
13
|
-
import { EmulatedMediaType } from '../interfaces/common.types';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Class representing a Markdown converter that extends the base Converter class.
|
|
17
|
-
* This class is used to convert HTML with markdown content to PDF using Gotenberg service.
|
|
18
|
-
*
|
|
19
|
-
* @extends Converter
|
|
20
|
-
*/
|
|
21
|
-
export class MarkdownConverter extends Converter {
|
|
22
|
-
/**
|
|
23
|
-
* Creates an instance of MarkdownConverter.
|
|
24
|
-
* Initializes the converter with the Markdown conversion route.
|
|
25
|
-
*/
|
|
26
|
-
constructor() {
|
|
27
|
-
super(ChromiumRoute.MARKDOWN);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Converts HTML with markdown content to PDF.
|
|
32
|
-
*
|
|
33
|
-
* @param {Object} options - Conversion options.
|
|
34
|
-
* @param {PathLikeOrReadStream} options.html - PathLike or ReadStream of the HTML content to be converted.
|
|
35
|
-
* @param {PathLikeOrReadStream} options.markdown - PathLike or ReadStream of the Markdown content to be converted.
|
|
36
|
-
* @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content.
|
|
37
|
-
* @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content.
|
|
38
|
-
* @param {PageProperties} [options.properties] - Page properties for the conversion.
|
|
39
|
-
* @param {PdfFormat} [options.pdfFormat] - PDF format options.
|
|
40
|
-
* @param {boolean} [options.pdfUA] - Indicates whether to generate PDF/UA compliant output.
|
|
41
|
-
* @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the conversion.
|
|
42
|
-
* @param {string} [options.waitDelay] - Delay before the conversion process starts.
|
|
43
|
-
* @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the conversion.
|
|
44
|
-
* @param {string} [options.userAgent] - User agent string to use during the conversion.
|
|
45
|
-
* @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the conversion.
|
|
46
|
-
* @param {number []} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
47
|
-
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during conversion.
|
|
48
|
-
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
49
|
-
* @param {Metadata} options.metadata - Metadata to be written.
|
|
50
|
-
* @param {Cookie[]} options.cookies - Cookies to be written.
|
|
51
|
-
* @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
|
|
52
|
-
*/
|
|
53
|
-
async convert({
|
|
54
|
-
html,
|
|
55
|
-
markdown,
|
|
56
|
-
header,
|
|
57
|
-
footer,
|
|
58
|
-
properties,
|
|
59
|
-
pdfFormat,
|
|
60
|
-
pdfUA,
|
|
61
|
-
emulatedMediaType,
|
|
62
|
-
waitDelay,
|
|
63
|
-
waitForExpression,
|
|
64
|
-
userAgent,
|
|
65
|
-
extraHttpHeaders,
|
|
66
|
-
failOnHttpStatusCodes,
|
|
67
|
-
failOnConsoleExceptions,
|
|
68
|
-
skipNetworkIdleEvent,
|
|
69
|
-
metadata,
|
|
70
|
-
cookies
|
|
71
|
-
}: {
|
|
72
|
-
html: PathLikeOrReadStream;
|
|
73
|
-
markdown: PathLikeOrReadStream;
|
|
74
|
-
header?: PathLikeOrReadStream;
|
|
75
|
-
footer?: PathLikeOrReadStream;
|
|
76
|
-
properties?: PageProperties;
|
|
77
|
-
/**
|
|
78
|
-
* @deprecated Starting from Gotenberg version 8.0.0, Chromium no longer provides support for pdfFormat.
|
|
79
|
-
* @see {@link https://github.com/gotenberg/gotenberg/releases/tag/v8.0.0}
|
|
80
|
-
*/
|
|
81
|
-
pdfFormat?: PdfFormat;
|
|
82
|
-
pdfUA?: boolean;
|
|
83
|
-
emulatedMediaType?: EmulatedMediaType;
|
|
84
|
-
waitDelay?: string;
|
|
85
|
-
waitForExpression?: string;
|
|
86
|
-
/**
|
|
87
|
-
* @deprecated Starting from Gotenberg version 8.0.0, Chromium no longer provides support for userAgent.
|
|
88
|
-
* @see {@link https://github.com/gotenberg/gotenberg/releases/tag/v8.0.0}
|
|
89
|
-
*/
|
|
90
|
-
userAgent?: string;
|
|
91
|
-
extraHttpHeaders?: Record<string, string>;
|
|
92
|
-
failOnHttpStatusCodes?: number[];
|
|
93
|
-
failOnConsoleExceptions?: boolean;
|
|
94
|
-
skipNetworkIdleEvent?: boolean;
|
|
95
|
-
metadata?: Metadata;
|
|
96
|
-
cookies?: Cookie[];
|
|
97
|
-
}): Promise<Buffer> {
|
|
98
|
-
const data = new FormData();
|
|
99
|
-
|
|
100
|
-
await GotenbergUtils.addFile(data, html, 'index.html');
|
|
101
|
-
|
|
102
|
-
await GotenbergUtils.addFile(data, markdown, 'file.md');
|
|
103
|
-
|
|
104
|
-
await ConverterUtils.customize(data, {
|
|
105
|
-
header,
|
|
106
|
-
footer,
|
|
107
|
-
properties,
|
|
108
|
-
pdfFormat,
|
|
109
|
-
pdfUA,
|
|
110
|
-
emulatedMediaType,
|
|
111
|
-
waitDelay,
|
|
112
|
-
waitForExpression,
|
|
113
|
-
userAgent,
|
|
114
|
-
extraHttpHeaders,
|
|
115
|
-
failOnHttpStatusCodes,
|
|
116
|
-
failOnConsoleExceptions,
|
|
117
|
-
skipNetworkIdleEvent,
|
|
118
|
-
metadata,
|
|
119
|
-
cookies
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
return GotenbergUtils.fetch(
|
|
123
|
-
this.endpoint,
|
|
124
|
-
data,
|
|
125
|
-
Chromiumly.getGotenbergApiBasicAuthUsername(),
|
|
126
|
-
Chromiumly.getGotenbergApiBasicAuthPassword()
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2
|
-
import { createReadStream, promises } from 'fs';
|
|
3
|
-
|
|
4
|
-
import fetch from 'node-fetch';
|
|
5
|
-
import FormData from 'form-data';
|
|
6
|
-
|
|
7
|
-
import { PdfFormat } from '../../../common';
|
|
8
|
-
import { HtmlConverter } from '../html.converter';
|
|
9
|
-
|
|
10
|
-
const { Response } = jest.requireActual('node-fetch');
|
|
11
|
-
jest.mock('node-fetch', () => jest.fn());
|
|
12
|
-
|
|
13
|
-
describe('HtmlConverter', () => {
|
|
14
|
-
const converter = new HtmlConverter();
|
|
15
|
-
|
|
16
|
-
describe('endpoint', () => {
|
|
17
|
-
it('should route to Chromium HTML route', () => {
|
|
18
|
-
expect(converter.endpoint).toEqual(
|
|
19
|
-
'http://localhost:3000/forms/chromium/convert/html'
|
|
20
|
-
);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
describe('convert', () => {
|
|
25
|
-
const mockPromisesAccess = jest.spyOn(promises, 'access');
|
|
26
|
-
const mockFetch = fetch as jest.MockedFunction<typeof fetch>;
|
|
27
|
-
const mockFormDataAppend = jest.spyOn(FormData.prototype, 'append');
|
|
28
|
-
|
|
29
|
-
const assets = [
|
|
30
|
-
{ file: Buffer.from('asset1'), name: 'asset1' },
|
|
31
|
-
{ file: Buffer.from('asset2'), name: 'asset2' }
|
|
32
|
-
];
|
|
33
|
-
|
|
34
|
-
beforeEach(() => {
|
|
35
|
-
(createReadStream as jest.Mock) = jest.fn();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
afterEach(() => {
|
|
39
|
-
jest.resetAllMocks();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe('when html parameter is passed', () => {
|
|
43
|
-
it('should return a buffer', async () => {
|
|
44
|
-
mockFetch.mockResolvedValue(new Response('content'));
|
|
45
|
-
const buffer = await converter.convert({
|
|
46
|
-
html: Buffer.from('data')
|
|
47
|
-
});
|
|
48
|
-
expect(buffer).toEqual(Buffer.from('content'));
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe('when pdf format parameter is passed', () => {
|
|
53
|
-
it('should return a buffer', async () => {
|
|
54
|
-
mockFetch.mockResolvedValue(new Response('content'));
|
|
55
|
-
const buffer = await converter.convert({
|
|
56
|
-
html: Buffer.from('data'),
|
|
57
|
-
pdfFormat: PdfFormat.A_1a
|
|
58
|
-
});
|
|
59
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
60
|
-
expect(buffer).toEqual(Buffer.from('content'));
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
describe('when page properties parameter is passed', () => {
|
|
65
|
-
it('should return a buffer', async () => {
|
|
66
|
-
mockFetch.mockResolvedValue(new Response('content'));
|
|
67
|
-
const buffer = await converter.convert({
|
|
68
|
-
html: Buffer.from('data'),
|
|
69
|
-
properties: { size: { width: 8.3, height: 11.7 } }
|
|
70
|
-
});
|
|
71
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
|
|
72
|
-
expect(buffer).toEqual(Buffer.from('content'));
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
describe('when header parameter is passed', () => {
|
|
77
|
-
it('should return a buffer', async () => {
|
|
78
|
-
mockFetch.mockResolvedValue(new Response('content'));
|
|
79
|
-
const buffer = await converter.convert({
|
|
80
|
-
html: Buffer.from('data'),
|
|
81
|
-
header: Buffer.from('header')
|
|
82
|
-
});
|
|
83
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
84
|
-
expect(buffer).toEqual(Buffer.from('content'));
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
describe('when footer parameter is passed', () => {
|
|
89
|
-
it('should return a buffer', async () => {
|
|
90
|
-
mockFetch.mockResolvedValue(new Response('content'));
|
|
91
|
-
const buffer = await converter.convert({
|
|
92
|
-
html: Buffer.from('data'),
|
|
93
|
-
footer: Buffer.from('footer')
|
|
94
|
-
});
|
|
95
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
96
|
-
expect(buffer).toEqual(Buffer.from('content'));
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
describe('when assets parameter is passed', () => {
|
|
101
|
-
it('should return a buffer', async () => {
|
|
102
|
-
mockFetch.mockResolvedValue(new Response('content'));
|
|
103
|
-
const buffer = await converter.convert({
|
|
104
|
-
html: Buffer.from('data'),
|
|
105
|
-
assets
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
|
|
109
|
-
expect(buffer).toEqual(Buffer.from('content'));
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
describe('when emulatedMediaType parameter is passed', () => {
|
|
114
|
-
it('should return a buffer', async () => {
|
|
115
|
-
mockFetch.mockResolvedValue(new Response('content'));
|
|
116
|
-
const buffer = await converter.convert({
|
|
117
|
-
html: Buffer.from('data'),
|
|
118
|
-
emulatedMediaType: 'screen'
|
|
119
|
-
});
|
|
120
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
121
|
-
expect(buffer).toEqual(Buffer.from('content'));
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
describe('when failOnHttpStatusCodes parameter is passed', () => {
|
|
126
|
-
it('should return a buffer', async () => {
|
|
127
|
-
mockFetch.mockResolvedValue(new Response('content'));
|
|
128
|
-
const buffer = await converter.convert({
|
|
129
|
-
html: Buffer.from('data'),
|
|
130
|
-
failOnHttpStatusCodes: [499, 599]
|
|
131
|
-
});
|
|
132
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
133
|
-
expect(buffer).toEqual(Buffer.from('content'));
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
describe('when skipNetworkIdleEvent parameter is passed', () => {
|
|
138
|
-
it('should return a buffer', async () => {
|
|
139
|
-
mockFetch.mockResolvedValue(new Response('content'));
|
|
140
|
-
const buffer = await converter.convert({
|
|
141
|
-
html: Buffer.from('data'),
|
|
142
|
-
skipNetworkIdleEvent: true
|
|
143
|
-
});
|
|
144
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
|
|
145
|
-
expect(buffer).toEqual(Buffer.from('content'));
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
describe('when all parameters are passed', () => {
|
|
150
|
-
it('should return a buffer', async () => {
|
|
151
|
-
mockPromisesAccess.mockResolvedValue();
|
|
152
|
-
mockFetch.mockResolvedValue(new Response('content'));
|
|
153
|
-
const buffer = await converter.convert({
|
|
154
|
-
html: Buffer.from('data'),
|
|
155
|
-
assets,
|
|
156
|
-
header: Buffer.from('header'),
|
|
157
|
-
footer: Buffer.from('footer'),
|
|
158
|
-
pdfFormat: PdfFormat.A_1a,
|
|
159
|
-
emulatedMediaType: 'screen',
|
|
160
|
-
properties: { size: { width: 8.3, height: 11.7 } }
|
|
161
|
-
});
|
|
162
|
-
expect(mockFormDataAppend).toHaveBeenCalledTimes(9);
|
|
163
|
-
expect(buffer).toEqual(Buffer.from('content'));
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
describe('when file does not exist', () => {
|
|
168
|
-
it('should throw an error', async () => {
|
|
169
|
-
const errorMessage =
|
|
170
|
-
"ENOENT: no such file or directory, access 'path/to/index.html'";
|
|
171
|
-
mockPromisesAccess.mockRejectedValue(new Error(errorMessage));
|
|
172
|
-
await expect(() =>
|
|
173
|
-
converter.convert({ html: 'path/to/index.html' })
|
|
174
|
-
).rejects.toThrow(errorMessage);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
describe('when fetch request fails', () => {
|
|
179
|
-
it('should throw an error', async () => {
|
|
180
|
-
const errorMessage =
|
|
181
|
-
'FetchError: request to http://localhost:3000/forms/chromium/convert/html failed';
|
|
182
|
-
mockPromisesAccess.mockResolvedValue();
|
|
183
|
-
mockFetch.mockRejectedValue(new Error(errorMessage));
|
|
184
|
-
await expect(() =>
|
|
185
|
-
converter.convert({ html: 'path/to/index.html' })
|
|
186
|
-
).rejects.toThrow(errorMessage);
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
});
|