chromiumly 2.5.0 → 2.6.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.
Files changed (52) hide show
  1. package/README.md +57 -40
  2. package/dist/chromium/converters/converter.d.ts +13 -0
  3. package/dist/chromium/converters/converter.js +10 -0
  4. package/dist/chromium/converters/converter.js.map +1 -1
  5. package/dist/chromium/converters/html.converter.d.ts +33 -1
  6. package/dist/chromium/converters/html.converter.js +32 -2
  7. package/dist/chromium/converters/html.converter.js.map +1 -1
  8. package/dist/chromium/converters/markdown.converter.d.ts +29 -0
  9. package/dist/chromium/converters/markdown.converter.js +29 -0
  10. package/dist/chromium/converters/markdown.converter.js.map +1 -1
  11. package/dist/chromium/converters/url.converter.d.ts +28 -0
  12. package/dist/chromium/converters/url.converter.js +28 -0
  13. package/dist/chromium/converters/url.converter.js.map +1 -1
  14. package/dist/chromium/utils/converter.utils.d.ts +24 -0
  15. package/dist/chromium/utils/converter.utils.js +24 -0
  16. package/dist/chromium/utils/converter.utils.js.map +1 -1
  17. package/dist/common/gotenberg.utils.d.ts +18 -0
  18. package/dist/common/gotenberg.utils.js +18 -0
  19. package/dist/common/gotenberg.utils.js.map +1 -1
  20. package/dist/gotenberg.d.ts +8 -0
  21. package/dist/gotenberg.js +8 -0
  22. package/dist/gotenberg.js.map +1 -1
  23. package/dist/libre-office/utils/constants.js +76 -76
  24. package/dist/libre-office/utils/constants.js.map +1 -1
  25. package/dist/libre-office/utils/libre-office.utils.d.ts +16 -0
  26. package/dist/libre-office/utils/libre-office.utils.js +38 -15
  27. package/dist/libre-office/utils/libre-office.utils.js.map +1 -1
  28. package/dist/main.config.d.ts +43 -0
  29. package/dist/main.config.js +43 -0
  30. package/dist/main.config.js.map +1 -1
  31. package/dist/pdf-engines/pdf.engine.d.ts +31 -5
  32. package/dist/pdf-engines/pdf.engine.js +28 -0
  33. package/dist/pdf-engines/pdf.engine.js.map +1 -1
  34. package/dist/pdf-engines/utils/engine.utils.d.ts +10 -0
  35. package/dist/pdf-engines/utils/engine.utils.js +11 -1
  36. package/dist/pdf-engines/utils/engine.utils.js.map +1 -1
  37. package/package.json +14 -13
  38. package/src/chromium/converters/converter.ts +13 -0
  39. package/src/chromium/converters/html.converter.ts +36 -3
  40. package/src/chromium/converters/markdown.converter.ts +30 -1
  41. package/src/chromium/converters/tests/html.converter.test.ts +21 -2
  42. package/src/chromium/converters/url.converter.ts +29 -3
  43. package/src/chromium/utils/converter.utils.ts +24 -0
  44. package/src/chromium/utils/tests/converter.utils.test.ts +2 -2
  45. package/src/common/gotenberg.utils.ts +20 -1
  46. package/src/gotenberg.ts +9 -0
  47. package/src/libre-office/utils/constants.ts +76 -76
  48. package/src/libre-office/utils/libre-office.utils.ts +42 -14
  49. package/src/libre-office/utils/tests/libre-office.utils.test.ts +24 -4
  50. package/src/main.config.ts +46 -1
  51. package/src/pdf-engines/pdf.engine.ts +32 -4
  52. package/src/pdf-engines/utils/engine.utils.ts +11 -1
@@ -1,5 +1,15 @@
1
1
  import FormData from "form-data";
2
2
  import { PathLikeOrReadStream } from "../../common";
3
+ /**
4
+ * Utility class for handling common tasks related to PDF engine operations.
5
+ */
3
6
  export declare class PDFEngineUtils {
7
+ /**
8
+ * Adds PDF files to the FormData object.
9
+ *
10
+ * @param {PathLikeOrReadStream[]} files - An array of PDF files to be added to the FormData.
11
+ * @param {FormData} data - The FormData object to which PDF files will be added.
12
+ * @throws {Error} Throws an error if the file extension is not supported.
13
+ */
4
14
  static addFiles(files: PathLikeOrReadStream[], data: FormData): Promise<void>;
5
15
  }
@@ -4,11 +4,21 @@ exports.PDFEngineUtils = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fs_1 = require("fs");
6
6
  const path_1 = tslib_1.__importDefault(require("path"));
7
+ /**
8
+ * Utility class for handling common tasks related to PDF engine operations.
9
+ */
7
10
  class PDFEngineUtils {
11
+ /**
12
+ * Adds PDF files to the FormData object.
13
+ *
14
+ * @param {PathLikeOrReadStream[]} files - An array of PDF files to be added to the FormData.
15
+ * @param {FormData} data - The FormData object to which PDF files will be added.
16
+ * @throws {Error} Throws an error if the file extension is not supported.
17
+ */
8
18
  static addFiles(files, data) {
9
19
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
20
  for (const [key, file] of files.entries()) {
11
- const filename = `file${key}`;
21
+ const filename = `file${key}.pdf`;
12
22
  if (Buffer.isBuffer(file)) {
13
23
  data.append("files", file, filename);
14
24
  }
@@ -1 +1 @@
1
- {"version":3,"file":"engine.utils.js","sourceRoot":"","sources":["../../../src/pdf-engines/utils/engine.utils.ts"],"names":[],"mappings":";;;;AAAA,2BAAqE;AACrE,wDAAwB;AAKxB,MAAa,cAAc;IAChB,MAAM,CAAO,QAAQ,CAAC,KAA6B,EAAE,IAAc;;YACtE,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;gBACxC,MAAM,QAAQ,GAAG,OAAO,GAAG,EAAE,CAAA;gBAC7B,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,QAAQ,GAAG,cAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;oBAChD,MAAM,SAAS,GAAG,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;oBACzC,IAAI,SAAS,KAAK,MAAM,EAAE,CAAC;wBACvB,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAA,qBAAgB,EAAC,IAAI,CAAC,CAAC,CAAC;oBAClD,CAAC;yBAAM,CAAC;wBACJ,MAAM,IAAI,KAAK,CAAC,GAAG,SAAS,mBAAmB,CAAC,CAAC;oBACrD,CAAC;gBACL,CAAC;YACL,CAAC;QACL,CAAC;KAAA;CACJ;AApBD,wCAoBC"}
1
+ {"version":3,"file":"engine.utils.js","sourceRoot":"","sources":["../../../src/pdf-engines/utils/engine.utils.ts"],"names":[],"mappings":";;;;AAAA,2BAAqE;AACrE,wDAAwB;AAKxB;;GAEG;AACH,MAAa,cAAc;IACvB;;;;;;OAMG;IACI,MAAM,CAAO,QAAQ,CAAC,KAA6B,EAAE,IAAc;;YACtE,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;gBACxC,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAA;gBACjC,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,QAAQ,GAAG,cAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;oBAChD,MAAM,SAAS,GAAG,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;oBACzC,IAAI,SAAS,KAAK,MAAM,EAAE,CAAC;wBACvB,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAA,qBAAgB,EAAC,IAAI,CAAC,CAAC,CAAC;oBAClD,CAAC;yBAAM,CAAC;wBACJ,MAAM,IAAI,KAAK,CAAC,GAAG,SAAS,mBAAmB,CAAC,CAAC;oBACrD,CAAC;gBACL,CAAC;YACL,CAAC;QACL,CAAC;KAAA;CACJ;AA3BD,wCA2BC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chromiumly",
3
- "version": "2.5.0",
3
+ "version": "2.6.0",
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",
@@ -47,26 +47,27 @@
47
47
  "@types/config": "3.3.3",
48
48
  "@types/dotenv": "8.2.0",
49
49
  "@types/form-data": "2.5.0",
50
- "@types/jest": "29.5.11",
51
- "@types/node": "20.10.4",
52
- "@types/node-fetch": "2.6.9",
53
- "@typescript-eslint/eslint-plugin": "6.13.2",
54
- "@typescript-eslint/parser": "6.13.2",
50
+ "@types/jest": "29.5.12",
51
+ "@types/node": "20.11.19",
52
+ "@types/node-fetch": "2.6.11",
53
+ "@typescript-eslint/eslint-plugin": "7.0.1",
54
+ "@typescript-eslint/parser": "7.0.1",
55
55
  "commitizen": "4.3.0",
56
- "eslint": "8.55.0",
57
- "husky": "8.0.3",
56
+ "eslint": "8.56.0",
57
+ "husky": "9.0.11",
58
58
  "inquirer": "8",
59
59
  "jest": "29.7.0",
60
60
  "jest-junit": "16.0.0",
61
- "release-it": "17.0.1",
62
- "ts-jest": "29.1.1",
63
- "ts-node": "10.9.1",
61
+ "release-it": "17.0.5",
62
+ "ts-jest": "29.1.2",
63
+ "ts-node": "10.9.2",
64
64
  "tslib": "2.6.2",
65
65
  "typescript": "5.3.3"
66
66
  },
67
67
  "dependencies": {
68
- "config": "3.3.9",
69
- "dotenv": "16.3.1",
68
+ "config": "3.3.11",
69
+ "dotenv": "16.4.4",
70
+ "file-type": "16.5.4",
70
71
  "form-data": "4.0.0",
71
72
  "node-fetch": "2.7.0"
72
73
  }
@@ -1,8 +1,21 @@
1
1
  import {Chromiumly, ChromiumRoute} from "../../main.config";
2
2
 
3
+ /**
4
+ * Abstract class representing a generic converter.
5
+ * Concrete converter classes should extend this class and implement specific conversion logic.
6
+ */
3
7
  export abstract class Converter {
8
+ /**
9
+ * The endpoint URL for the converter.
10
+ */
4
11
  readonly endpoint: string;
5
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
+ */
6
19
  constructor(route: ChromiumRoute) {
7
20
  this.endpoint = `${Chromiumly.GOTENBERG_ENDPOINT}/${Chromiumly.CHROMIUM_PATH}/${Chromiumly.CHROMIUM_ROUTES[route]}`;
8
21
  }
@@ -1,4 +1,3 @@
1
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
1
  import FormData from "form-data";
3
2
 
4
3
  import {GotenbergUtils, PathLikeOrReadStream, PdfFormat} from "../../common";
@@ -10,13 +9,42 @@ import {ConverterUtils} from "../utils/converter.utils";
10
9
  import {Converter} from "./converter";
11
10
  import {ChromiumRoute} from "../../main.config";
12
11
 
12
+ /**
13
+ * Class representing an HTML converter that extends the base Converter class.
14
+ * This class is used to convert HTML content to PDF using Gotenberg service.
15
+ *
16
+ * @extends Converter
17
+ */
13
18
  export class HtmlConverter extends Converter {
19
+ /**
20
+ * Creates an instance of HtmlConverter.
21
+ * Initializes the converter with the HTML conversion route.
22
+ */
14
23
  constructor() {
15
24
  super(ChromiumRoute.HTML);
16
25
  }
17
26
 
27
+ /**
28
+ * Converts HTML content to PDF.
29
+ *
30
+ * @param {Object} options - Conversion options.
31
+ * @param {PathLikeOrReadStream} options.html - PathLike or ReadStream of the HTML content to be converted.
32
+ * @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content.
33
+ * @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content.
34
+ * @param {PageProperties} [options.properties] - Page properties for the conversion.
35
+ * @param {PdfFormat} [options.pdfFormat] - PDF format options.
36
+ * @param {boolean} [options.pdfUA] - Indicates whether to generate PDF/UA compliant output.
37
+ * @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the conversion.
38
+ * @param {string} [options.waitDelay] - Delay before the conversion process starts.
39
+ * @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the conversion.
40
+ * @param {string} [options.userAgent] - User agent string to use during the conversion.
41
+ * @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the conversion.
42
+ * @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during conversion.
43
+ * @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
44
+ */
18
45
  async convert({
19
46
  html,
47
+ assets,
20
48
  header,
21
49
  footer,
22
50
  properties,
@@ -30,6 +58,7 @@ export class HtmlConverter extends Converter {
30
58
  failOnConsoleExceptions,
31
59
  }: {
32
60
  html: PathLikeOrReadStream;
61
+ assets?: { file: PathLikeOrReadStream, name: string }[]
33
62
  header?: PathLikeOrReadStream;
34
63
  footer?: PathLikeOrReadStream;
35
64
  properties?: PageProperties;
@@ -44,7 +73,11 @@ export class HtmlConverter extends Converter {
44
73
  }): Promise<Buffer> {
45
74
  const data = new FormData();
46
75
 
47
- await ConverterUtils.addFile(data, html, "index.html")
76
+ await ConverterUtils.addFile(data, html, "index.html");
77
+
78
+ if (assets?.length) {
79
+ await Promise.all(assets.map(({ file, name }) => ConverterUtils.addFile(data, file, name)))
80
+ }
48
81
 
49
82
  await ConverterUtils.customize(data, {
50
83
  header,
@@ -62,4 +95,4 @@ export class HtmlConverter extends Converter {
62
95
 
63
96
  return GotenbergUtils.fetch(this.endpoint, data);
64
97
  }
65
- }
98
+ }
@@ -9,11 +9,40 @@ import {ConverterUtils} from "../utils/converter.utils";
9
9
  import {Converter} from "./converter";
10
10
  import {ChromiumRoute} from "../../main.config";
11
11
 
12
+ /**
13
+ * Class representing a Markdown converter that extends the base Converter class.
14
+ * This class is used to convert HTML with markdown content to PDF using Gotenberg service.
15
+ *
16
+ * @extends Converter
17
+ */
12
18
  export class MarkdownConverter extends Converter {
19
+ /**
20
+ * Creates an instance of MarkdownConverter.
21
+ * Initializes the converter with the Markdown conversion route.
22
+ */
13
23
  constructor() {
14
24
  super(ChromiumRoute.MARKDOWN);
15
25
  }
16
26
 
27
+ /**
28
+ * Converts HTML with markdown content to PDF.
29
+ *
30
+ * @param {Object} options - Conversion options.
31
+ * @param {PathLikeOrReadStream} options.html - PathLike or ReadStream of the HTML content to be converted.
32
+ * @param {PathLikeOrReadStream} options.markdown - PathLike or ReadStream of the Markdown content to be converted.
33
+ * @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content.
34
+ * @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content.
35
+ * @param {PageProperties} [options.properties] - Page properties for the conversion.
36
+ * @param {PdfFormat} [options.pdfFormat] - PDF format options.
37
+ * @param {boolean} [options.pdfUA] - Indicates whether to generate PDF/UA compliant output.
38
+ * @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the conversion.
39
+ * @param {string} [options.waitDelay] - Delay before the conversion process starts.
40
+ * @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the conversion.
41
+ * @param {string} [options.userAgent] - User agent string to use during the conversion.
42
+ * @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the conversion.
43
+ * @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during conversion.
44
+ * @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
45
+ */
17
46
  async convert({
18
47
  html,
19
48
  markdown,
@@ -65,4 +94,4 @@ export class MarkdownConverter extends Converter {
65
94
 
66
95
  return GotenbergUtils.fetch(this.endpoint, data);
67
96
  }
68
- }
97
+ }
@@ -25,7 +25,12 @@ describe("HtmlConverter", () => {
25
25
  const mockPromisesAccess = jest.spyOn(promises, "access");
26
26
  const mockFetch = fetch as jest.MockedFunction<typeof fetch>;
27
27
  const mockFormDataAppend = jest.spyOn(FormData.prototype, "append");
28
-
28
+
29
+ const assets = [
30
+ { file: Buffer.from('asset1'), name: 'asset1' },
31
+ { file: Buffer.from('asset2'), name: 'asset2' }
32
+ ]
33
+
29
34
  beforeEach(() => {
30
35
  (createReadStream as jest.Mock) = jest.fn()
31
36
  });
@@ -92,6 +97,19 @@ describe("HtmlConverter", () => {
92
97
  });
93
98
  });
94
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
+
95
113
  describe("when emulatedMediaType parameter is passed", () => {
96
114
  it("should return a buffer", async () => {
97
115
  mockFetch.mockResolvedValue(new Response("content"));
@@ -110,13 +128,14 @@ describe("HtmlConverter", () => {
110
128
  mockFetch.mockResolvedValue(new Response("content"));
111
129
  const buffer = await converter.convert({
112
130
  html: Buffer.from("data"),
131
+ assets,
113
132
  header: Buffer.from("header"),
114
133
  footer: Buffer.from("footer"),
115
134
  pdfFormat: PdfFormat.A_1a,
116
135
  emulatedMediaType: "screen",
117
136
  properties: {size: {width: 8.3, height: 11.7}},
118
137
  });
119
- expect(mockFormDataAppend).toHaveBeenCalledTimes(7);
138
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(9);
120
139
  expect(buffer).toEqual(Buffer.from("content"));
121
140
  });
122
141
  });
@@ -1,7 +1,5 @@
1
1
  import {URL} from "url";
2
-
3
2
  import FormData from "form-data";
4
-
5
3
  import {GotenbergUtils, PdfFormat, PathLikeOrReadStream} from "../../common";
6
4
  import {
7
5
  EmulatedMediaType,
@@ -11,11 +9,39 @@ import {ConverterUtils} from "../utils/converter.utils";
11
9
  import {Converter} from "./converter";
12
10
  import {ChromiumRoute} from "../../main.config";
13
11
 
12
+ /**
13
+ * Class representing a URL converter that extends the base Converter class.
14
+ * This class is used to convert content from a URL to PDF using Gotenberg service.
15
+ *
16
+ * @extends Converter
17
+ */
14
18
  export class UrlConverter extends Converter {
19
+ /**
20
+ * Creates an instance of UrlConverter.
21
+ * Initializes the converter with the URL conversion route.
22
+ */
15
23
  constructor() {
16
24
  super(ChromiumRoute.URL);
17
25
  }
18
26
 
27
+ /**
28
+ * Converts content from a URL to PDF.
29
+ *
30
+ * @param {Object} options - Conversion options.
31
+ * @param {string} options.url - The URL of the content to be converted to PDF.
32
+ * @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content.
33
+ * @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content.
34
+ * @param {PageProperties} [options.properties] - Page properties for the conversion.
35
+ * @param {PdfFormat} [options.pdfFormat] - PDF format options.
36
+ * @param {boolean} [options.pdfUA] - Indicates whether to generate PDF/UA compliant output.
37
+ * @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the conversion.
38
+ * @param {string} [options.waitDelay] - Delay before the conversion process starts.
39
+ * @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the conversion.
40
+ * @param {string} [options.userAgent] - User agent string to use during the conversion.
41
+ * @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the conversion.
42
+ * @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during conversion.
43
+ * @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
44
+ */
19
45
  async convert({
20
46
  url,
21
47
  header,
@@ -64,4 +90,4 @@ export class UrlConverter extends Converter {
64
90
 
65
91
  return GotenbergUtils.fetch(this.endpoint, data);
66
92
  }
67
- }
93
+ }
@@ -8,7 +8,16 @@ import {
8
8
  import {GotenbergUtils, PathLikeOrReadStream} from "../../common";
9
9
  import {ReadStream} from "fs";
10
10
 
11
+ /**
12
+ * Utility class for handling common tasks related to conversion.
13
+ */
11
14
  export class ConverterUtils {
15
+ /**
16
+ * Adds page properties to the FormData object based on the provided PageProperties.
17
+ *
18
+ * @param {FormData} data - The FormData object to which page properties will be added.
19
+ * @param {PageProperties} pageProperties - The page properties to be added to the FormData.
20
+ */
12
21
  public static addPageProperties(
13
22
  data: FormData,
14
23
  pageProperties: PageProperties
@@ -82,6 +91,14 @@ export class ConverterUtils {
82
91
  }
83
92
  }
84
93
 
94
+ /**
95
+ * Adds a file to the FormData object.
96
+ *
97
+ * @param {FormData} data - The FormData object to which the file will be added.
98
+ * @param {PathLikeOrReadStream} file - The file to be added (either a PathLike or a ReadStream).
99
+ * @param {string} name - The name to be used for the file in the FormData.
100
+ * @returns {Promise<void>} A Promise that resolves once the file has been added.
101
+ */
85
102
  public static async addFile(data: FormData, file: PathLikeOrReadStream, name: string) {
86
103
  if (Buffer.isBuffer(file)) {
87
104
  data.append("files", file, name);
@@ -93,6 +110,13 @@ export class ConverterUtils {
93
110
  }
94
111
  }
95
112
 
113
+ /**
114
+ * Customizes the FormData object based on the provided conversion options.
115
+ *
116
+ * @param {FormData} data - The FormData object to be customized.
117
+ * @param {ConversionOptions} options - The conversion options to apply to the FormData.
118
+ * @returns {Promise<void>} A Promise that resolves once the customization is complete.
119
+ */
96
120
  public static async customize(
97
121
  data: FormData,
98
122
  options: ConversionOptions
@@ -119,13 +119,13 @@ describe("ConverterUtils", () => {
119
119
 
120
120
  beforeAll(async () => {
121
121
  await promises.mkdir(path.resolve(__tmp__), {recursive: true});
122
- await promises.writeFile(filePath, "file");
122
+ await promises.writeFile(filePath, "data");
123
123
  })
124
124
 
125
125
  afterAll(async () => {
126
126
  await promises.rm(path.resolve(__tmp__), {recursive: true})
127
127
  })
128
-
128
+
129
129
  describe("when file is passed as read stream", () => {
130
130
  it("should append file to data", async () => {
131
131
  const file = createReadStream(filePath)
@@ -1,13 +1,31 @@
1
1
  import FormData from "form-data";
2
2
  import fetch from "node-fetch";
3
3
 
4
+ /**
5
+ * Utility class for common tasks related to the Gotenberg service.
6
+ */
4
7
  export class GotenbergUtils {
8
+ /**
9
+ * Asserts that a condition is true; otherwise, throws an error with the specified message.
10
+ *
11
+ * @param {boolean} condition - The condition to assert.
12
+ * @param {string} message - The error message to throw if the condition is false.
13
+ * @throws {Error} Throws an error with the specified message if the condition is false.
14
+ */
5
15
  public static assert(condition: boolean, message: string): asserts condition {
6
16
  if (!condition) {
7
17
  throw new Error(message);
8
18
  }
9
19
  }
10
20
 
21
+ /**
22
+ * Performs a POST request to the specified Gotenberg endpoint with the provided FormData.
23
+ *
24
+ * @param {string} endpoint - The Gotenberg endpoint URL.
25
+ * @param {FormData} data - The FormData object to be sent in the POST request.
26
+ * @returns {Promise<Buffer>} A Promise that resolves to the response body as a Buffer.
27
+ * @throws {Error} Throws an error if the HTTP response status is not OK.
28
+ */
11
29
  public static async fetch(endpoint: string, data: FormData): Promise<Buffer> {
12
30
  const response = await fetch(endpoint, {
13
31
  method: "post",
@@ -20,6 +38,7 @@ export class GotenbergUtils {
20
38
  if (!response.ok) {
21
39
  throw new Error(`${response.status} ${response.statusText}`);
22
40
  }
41
+
23
42
  return response.buffer();
24
43
  }
25
- }
44
+ }
package/src/gotenberg.ts CHANGED
@@ -15,7 +15,16 @@ if (dotenvConfig.error) {
15
15
  dotenv.config({path: path.resolve(envFileFallback)});
16
16
  }
17
17
 
18
+ /**
19
+ * Class representing configuration for interacting with Gotenberg service.
20
+ */
18
21
  export class Gotenberg {
22
+ /**
23
+ * The Gotenberg service endpoint.
24
+ * Defaults to the value from the environment variable `GOTENBERG_ENDPOINT`, or falls back to the configuration file.
25
+ * @type {string}
26
+ */
19
27
  public static endpoint: string =
20
28
  process.env.GOTENBERG_ENDPOINT || config.get<string>("gotenberg.endpoint");
21
29
  }
30
+
@@ -1,78 +1,78 @@
1
1
  export const LIBRE_OFFICE_EXTENSIONS = [
2
- ".bib",
3
- ".doc",
4
- ".xml",
5
- ".docx",
6
- ".fodt",
7
- ".html",
8
- ".ltx",
9
- ".txt",
10
- ".odt",
11
- ".ott",
12
- ".pdb",
13
- ".pdf",
14
- ".psw",
15
- ".rtf",
16
- ".sdw",
17
- ".stw",
18
- ".sxw",
19
- ".uot",
20
- ".vor",
21
- ".wps",
22
- ".epub",
23
- ".png",
24
- ".bmp",
25
- ".emf",
26
- ".eps",
27
- ".fodg",
28
- ".gif",
29
- ".jpg",
30
- ".met",
31
- ".odd",
32
- ".otg",
33
- ".pbm",
34
- ".pct",
35
- ".pgm",
36
- ".ppm",
37
- ".ras",
38
- ".std",
39
- ".svg",
40
- ".svm",
41
- ".swf",
42
- ".sxd",
43
- ".sxw",
44
- ".tiff",
45
- ".xhtml",
46
- ".xpm",
47
- ".fodp",
48
- ".potm",
49
- ".pot",
50
- ".pptx",
51
- ".pps",
52
- ".ppt",
53
- ".pwp",
54
- ".sda",
55
- ".sdd",
56
- ".sti",
57
- ".sxi",
58
- ".uop",
59
- ".wmf",
60
- ".csv",
61
- ".dbf",
62
- ".dif",
63
- ".fods",
64
- ".ods",
65
- ".ots",
66
- ".pxl",
67
- ".sdc",
68
- ".slk",
69
- ".stc",
70
- ".sxc",
71
- ".uos",
72
- ".xls",
73
- ".xlt",
74
- ".xlsx",
75
- ".tif",
76
- ".jpeg",
77
- ".odp",
2
+ "bib",
3
+ "doc",
4
+ "xml",
5
+ "docx",
6
+ "fodt",
7
+ "html",
8
+ "ltx",
9
+ "txt",
10
+ "odt",
11
+ "ott",
12
+ "pdb",
13
+ "pdf",
14
+ "psw",
15
+ "rtf",
16
+ "sdw",
17
+ "stw",
18
+ "sxw",
19
+ "uot",
20
+ "vor",
21
+ "wps",
22
+ "epub",
23
+ "png",
24
+ "bmp",
25
+ "emf",
26
+ "eps",
27
+ "fodg",
28
+ "gif",
29
+ "jpg",
30
+ "met",
31
+ "odd",
32
+ "otg",
33
+ "pbm",
34
+ "pct",
35
+ "pgm",
36
+ "ppm",
37
+ "ras",
38
+ "std",
39
+ "svg",
40
+ "svm",
41
+ "swf",
42
+ "sxd",
43
+ "sxw",
44
+ "tiff",
45
+ "xhtml",
46
+ "xpm",
47
+ "fodp",
48
+ "potm",
49
+ "pot",
50
+ "pptx",
51
+ "pps",
52
+ "ppt",
53
+ "pwp",
54
+ "sda",
55
+ "sdd",
56
+ "sti",
57
+ "sxi",
58
+ "uop",
59
+ "wmf",
60
+ "csv",
61
+ "dbf",
62
+ "dif",
63
+ "fods",
64
+ "ods",
65
+ "ots",
66
+ "pxl",
67
+ "sdc",
68
+ "slk",
69
+ "stc",
70
+ "sxc",
71
+ "uos",
72
+ "xls",
73
+ "xlt",
74
+ "xlsx",
75
+ "tif",
76
+ "jpeg",
77
+ "odp",
78
78
  ];