chromiumly 2.4.0 → 2.5.1

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 (77) 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 +32 -6
  6. package/dist/chromium/converters/html.converter.js +30 -9
  7. package/dist/chromium/converters/html.converter.js.map +1 -1
  8. package/dist/chromium/converters/markdown.converter.d.ts +34 -7
  9. package/dist/chromium/converters/markdown.converter.js +32 -16
  10. package/dist/chromium/converters/markdown.converter.js.map +1 -1
  11. package/dist/chromium/converters/url.converter.d.ts +31 -5
  12. package/dist/chromium/converters/url.converter.js +29 -1
  13. package/dist/chromium/converters/url.converter.js.map +1 -1
  14. package/dist/chromium/index.js.map +1 -1
  15. package/dist/chromium/interfaces/converter.types.d.ts +3 -6
  16. package/dist/chromium/utils/converter.utils.d.ts +27 -1
  17. package/dist/chromium/utils/converter.utils.js +48 -21
  18. package/dist/chromium/utils/converter.utils.js.map +1 -1
  19. package/dist/common/constants.js.map +1 -1
  20. package/dist/common/gotenberg.utils.d.ts +18 -0
  21. package/dist/common/gotenberg.utils.js +18 -0
  22. package/dist/common/gotenberg.utils.js.map +1 -1
  23. package/dist/common/index.d.ts +1 -0
  24. package/dist/common/index.js.map +1 -1
  25. package/dist/common/types.d.ts +3 -0
  26. package/dist/common/types.js +3 -0
  27. package/dist/common/types.js.map +1 -0
  28. package/dist/gotenberg.d.ts +8 -0
  29. package/dist/gotenberg.js +8 -0
  30. package/dist/gotenberg.js.map +1 -1
  31. package/dist/libre-office/index.js.map +1 -1
  32. package/dist/libre-office/utils/constants.js +76 -76
  33. package/dist/libre-office/utils/constants.js.map +1 -1
  34. package/dist/libre-office/utils/libre-office.utils.d.ts +19 -4
  35. package/dist/libre-office/utils/libre-office.utils.js +39 -7
  36. package/dist/libre-office/utils/libre-office.utils.js.map +1 -1
  37. package/dist/main.config.d.ts +43 -0
  38. package/dist/main.config.js +43 -0
  39. package/dist/main.config.js.map +1 -1
  40. package/dist/main.js.map +1 -1
  41. package/dist/pdf-engines/index.js.map +1 -1
  42. package/dist/pdf-engines/pdf.engine.d.ts +31 -5
  43. package/dist/pdf-engines/pdf.engine.js +31 -3
  44. package/dist/pdf-engines/pdf.engine.js.map +1 -1
  45. package/dist/pdf-engines/utils/engine.utils.d.ts +12 -3
  46. package/dist/pdf-engines/utils/engine.utils.js +27 -8
  47. package/dist/pdf-engines/utils/engine.utils.js.map +1 -1
  48. package/package.json +8 -7
  49. package/src/chromium/converters/converter.ts +18 -5
  50. package/src/chromium/converters/html.converter.ts +82 -61
  51. package/src/chromium/converters/markdown.converter.ts +86 -69
  52. package/src/chromium/converters/tests/html.converter.test.ts +119 -135
  53. package/src/chromium/converters/tests/markdown.converter.test.ts +131 -150
  54. package/src/chromium/converters/tests/url.converter.test.ts +114 -123
  55. package/src/chromium/converters/url.converter.ts +84 -60
  56. package/src/chromium/index.ts +3 -3
  57. package/src/chromium/interfaces/converter.types.ts +27 -27
  58. package/src/chromium/utils/converter.utils.ts +165 -139
  59. package/src/chromium/utils/tests/converter.utils.test.ts +312 -311
  60. package/src/common/constants.ts +3 -3
  61. package/src/common/gotenberg.utils.ts +36 -17
  62. package/src/common/index.ts +3 -2
  63. package/src/common/tests/gotenberg.utils.test.ts +54 -54
  64. package/src/common/types.ts +3 -0
  65. package/src/gotenberg.ts +13 -4
  66. package/src/libre-office/index.ts +2 -2
  67. package/src/libre-office/interfaces/libre-office.types.ts +2 -2
  68. package/src/libre-office/utils/constants.ts +76 -76
  69. package/src/libre-office/utils/libre-office.utils.ts +72 -37
  70. package/src/libre-office/utils/tests/libre-office.utils.test.ts +100 -68
  71. package/src/main.config.ts +68 -22
  72. package/src/main.ts +3 -3
  73. package/src/pdf-engines/index.ts +1 -1
  74. package/src/pdf-engines/pdf.engine.ts +77 -49
  75. package/src/pdf-engines/tests/pdf.engine.test.ts +94 -94
  76. package/src/pdf-engines/utils/engine.utils.ts +30 -12
  77. package/src/pdf-engines/utils/tests/engine.utils.test.ts +60 -48
@@ -1,27 +1,70 @@
1
+ /**
2
+ * Enum representing the available Chromium routes for conversion.
3
+ * @enum {string}
4
+ */
1
5
  export declare enum ChromiumRoute {
2
6
  URL = "url",
3
7
  HTML = "html",
4
8
  MARKDOWN = "markdown"
5
9
  }
10
+ /**
11
+ * Enum representing the available routes for the PDF engine.
12
+ * @enum {string}
13
+ */
6
14
  declare enum PdfEngineRoute {
7
15
  MERGE = "merge"
8
16
  }
17
+ /**
18
+ * Enum representing the available routes for LibreOffice.
19
+ * @enum {string}
20
+ */
9
21
  declare enum LibreOfficeRoute {
10
22
  CONVERT = "convert"
11
23
  }
24
+ /**
25
+ * Class providing constants and routes for interacting with the Gotenberg service and related engines.
26
+ */
12
27
  export declare class Chromiumly {
28
+ /**
29
+ * The Gotenberg service endpoint.
30
+ * @type {string}
31
+ */
13
32
  static readonly GOTENBERG_ENDPOINT: string;
33
+ /**
34
+ * The path for Chromium-related conversions.
35
+ * @type {string}
36
+ */
14
37
  static readonly CHROMIUM_PATH = "forms/chromium/convert";
38
+ /**
39
+ * The path for PDF engine-related operations.
40
+ * @type {string}
41
+ */
15
42
  static readonly PDF_ENGINES_PATH = "forms/pdfengines";
43
+ /**
44
+ * The path for LibreOffice-related conversions.
45
+ * @type {string}
46
+ */
16
47
  static readonly LIBRE_OFFICE_PATH = "forms/libreoffice";
48
+ /**
49
+ * Routes for Chromium conversions.
50
+ * @type {Object}
51
+ */
17
52
  static readonly CHROMIUM_ROUTES: {
18
53
  url: ChromiumRoute;
19
54
  html: ChromiumRoute;
20
55
  markdown: ChromiumRoute;
21
56
  };
57
+ /**
58
+ * Routes for PDF engine operations.
59
+ * @type {Object}
60
+ */
22
61
  static readonly PDF_ENGINE_ROUTES: {
23
62
  merge: PdfEngineRoute;
24
63
  };
64
+ /**
65
+ * Routes for LibreOffice conversions.
66
+ * @type {Object}
67
+ */
25
68
  static readonly LIBRE_OFFICE_ROUTES: {
26
69
  convert: LibreOfficeRoute;
27
70
  };
@@ -2,35 +2,78 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Chromiumly = exports.ChromiumRoute = void 0;
4
4
  const gotenberg_1 = require("./gotenberg");
5
+ /**
6
+ * Enum representing the available Chromium routes for conversion.
7
+ * @enum {string}
8
+ */
5
9
  var ChromiumRoute;
6
10
  (function (ChromiumRoute) {
7
11
  ChromiumRoute["URL"] = "url";
8
12
  ChromiumRoute["HTML"] = "html";
9
13
  ChromiumRoute["MARKDOWN"] = "markdown";
10
14
  })(ChromiumRoute || (exports.ChromiumRoute = ChromiumRoute = {}));
15
+ /**
16
+ * Enum representing the available routes for the PDF engine.
17
+ * @enum {string}
18
+ */
11
19
  var PdfEngineRoute;
12
20
  (function (PdfEngineRoute) {
13
21
  PdfEngineRoute["MERGE"] = "merge";
14
22
  })(PdfEngineRoute || (PdfEngineRoute = {}));
23
+ /**
24
+ * Enum representing the available routes for LibreOffice.
25
+ * @enum {string}
26
+ */
15
27
  var LibreOfficeRoute;
16
28
  (function (LibreOfficeRoute) {
17
29
  LibreOfficeRoute["CONVERT"] = "convert";
18
30
  })(LibreOfficeRoute || (LibreOfficeRoute = {}));
31
+ /**
32
+ * Class providing constants and routes for interacting with the Gotenberg service and related engines.
33
+ */
19
34
  class Chromiumly {
20
35
  }
21
36
  exports.Chromiumly = Chromiumly;
37
+ /**
38
+ * The Gotenberg service endpoint.
39
+ * @type {string}
40
+ */
22
41
  Chromiumly.GOTENBERG_ENDPOINT = gotenberg_1.Gotenberg.endpoint;
42
+ /**
43
+ * The path for Chromium-related conversions.
44
+ * @type {string}
45
+ */
23
46
  Chromiumly.CHROMIUM_PATH = "forms/chromium/convert";
47
+ /**
48
+ * The path for PDF engine-related operations.
49
+ * @type {string}
50
+ */
24
51
  Chromiumly.PDF_ENGINES_PATH = "forms/pdfengines";
52
+ /**
53
+ * The path for LibreOffice-related conversions.
54
+ * @type {string}
55
+ */
25
56
  Chromiumly.LIBRE_OFFICE_PATH = "forms/libreoffice";
57
+ /**
58
+ * Routes for Chromium conversions.
59
+ * @type {Object}
60
+ */
26
61
  Chromiumly.CHROMIUM_ROUTES = {
27
62
  url: ChromiumRoute.URL,
28
63
  html: ChromiumRoute.HTML,
29
64
  markdown: ChromiumRoute.MARKDOWN,
30
65
  };
66
+ /**
67
+ * Routes for PDF engine operations.
68
+ * @type {Object}
69
+ */
31
70
  Chromiumly.PDF_ENGINE_ROUTES = {
32
71
  merge: PdfEngineRoute.MERGE,
33
72
  };
73
+ /**
74
+ * Routes for LibreOffice conversions.
75
+ * @type {Object}
76
+ */
34
77
  Chromiumly.LIBRE_OFFICE_ROUTES = {
35
78
  convert: LibreOfficeRoute.CONVERT,
36
79
  };
@@ -1 +1 @@
1
- {"version":3,"file":"main.config.js","sourceRoot":"","sources":["../src/main.config.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AAExC,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,4BAAW,CAAA;IACX,8BAAa,CAAA;IACb,sCAAqB,CAAA;AACvB,CAAC,EAJW,aAAa,6BAAb,aAAa,QAIxB;AAED,IAAK,cAEJ;AAFD,WAAK,cAAc;IACjB,iCAAe,CAAA;AACjB,CAAC,EAFI,cAAc,KAAd,cAAc,QAElB;AAED,IAAK,gBAEJ;AAFD,WAAK,gBAAgB;IACnB,uCAAmB,CAAA;AACrB,CAAC,EAFI,gBAAgB,KAAhB,gBAAgB,QAEpB;AACD,MAAa,UAAU;;AAAvB,gCAoBC;AAnBwB,6BAAkB,GAAG,qBAAS,CAAC,QAAQ,CAAC;AAExC,wBAAa,GAAG,wBAAwB,CAAC;AACzC,2BAAgB,GAAG,kBAAkB,CAAC;AACtC,4BAAiB,GAAG,mBAAmB,CAAC;AAExC,0BAAe,GAAG;IACvC,GAAG,EAAE,aAAa,CAAC,GAAG;I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G;IACzC,OAAO,EAAE,gBAAgB,CAAC,OAAO;CACpC,CAAC"}
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;AAAA,gDAA+C;AAAtC,sGAAA,SAAS,OAAA;AAClB,uCAA4E;AAAnE,yGAAA,aAAa,OAAA;AAAE,6GAAA,iBAAiB,OAAA;AAAE,wGAAA,YAAY,OAAA;AACvD,6CAA0C;AAAjC,wGAAA,SAAS,OAAA"}
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;AAAA,gDAA6C;AAArC,sGAAA,SAAS,OAAA;AACjB,uCAA0E;AAAlE,yGAAA,aAAa,OAAA;AAAE,6GAAA,iBAAiB,OAAA;AAAE,wGAAA,YAAY,OAAA;AACtD,6CAAwC;AAAhC,wGAAA,SAAS,OAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pdf-engines/index.ts"],"names":[],"mappings":";;;AAAA,2CAAyC;AAAhC,uGAAA,SAAS,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pdf-engines/index.ts"],"names":[],"mappings":";;;AAAA,2CAAuC;AAA/B,uGAAA,SAAS,OAAA"}
@@ -1,18 +1,44 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { PathLike } from "fs";
4
- import { PdfFormat } from "../common";
2
+ import { PathLikeOrReadStream, PdfFormat } from "../common";
5
3
  import { PageProperties } from "../libre-office";
4
+ /**
5
+ * Class representing a PDF engine for various operations such as merging and conversion.
6
+ */
6
7
  export declare class PDFEngine {
8
+ /**
9
+ * Merges multiple PDF files into a single PDF document.
10
+ *
11
+ * @param {Object} options - Options for the merge operation.
12
+ * @param {PathLikeOrReadStream[]} options.files - An array of PathLikes or ReadStreams to the PDF files to be merged.
13
+ * @returns {Promise<Buffer>} A Promise resolving to the merged PDF content as a Buffer.
14
+ */
7
15
  static merge({ files }: {
8
- files: PathLike[];
16
+ files: PathLikeOrReadStream[];
9
17
  }): Promise<Buffer>;
18
+ /**
19
+ * Converts various document formats to PDF.
20
+ *
21
+ * @param {Object} options - Options for the conversion operation.
22
+ * @param {PathLikeOrReadStream[]} options.files - An array of PathLikes or ReadStreams to the files to be converted to PDF.
23
+ * @param {PageProperties} [options.properties] - Page properties for the conversion.
24
+ * @param {PdfFormat} [options.pdfFormat] - PDF format options.
25
+ * @param {boolean} [options.pdfUA] - Indicates whether to generate PDF/UA compliant output.
26
+ * @param {boolean} [options.merge] - Indicates whether to merge the resulting PDFs.
27
+ * @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
28
+ */
10
29
  static convert({ files, properties, pdfFormat, pdfUA, merge, }: {
11
- files: PathLike[];
30
+ files: PathLikeOrReadStream[];
12
31
  properties?: PageProperties;
13
32
  pdfFormat?: PdfFormat;
14
33
  pdfUA?: boolean;
15
34
  merge?: boolean;
16
35
  }): Promise<Buffer>;
36
+ /**
37
+ * Generates a PDF file from a buffer and saves it to the "__generated__" directory.
38
+ *
39
+ * @param {string} filename - The filename for the generated PDF.
40
+ * @param {Buffer} buffer - The PDF content as a Buffer.
41
+ * @returns {Promise<void>} A Promise that resolves once the file is generated and saved.
42
+ */
17
43
  static generate(filename: string, buffer: Buffer): Promise<void>;
18
44
  }
@@ -9,15 +9,36 @@ const main_config_1 = require("../main.config");
9
9
  const common_1 = require("../common");
10
10
  const libre_office_1 = require("../libre-office");
11
11
  const engine_utils_1 = require("./utils/engine.utils");
12
+ /**
13
+ * Class representing a PDF engine for various operations such as merging and conversion.
14
+ */
12
15
  class PDFEngine {
16
+ /**
17
+ * Merges multiple PDF files into a single PDF document.
18
+ *
19
+ * @param {Object} options - Options for the merge operation.
20
+ * @param {PathLikeOrReadStream[]} options.files - An array of PathLikes or ReadStreams to the PDF files to be merged.
21
+ * @returns {Promise<Buffer>} A Promise resolving to the merged PDF content as a Buffer.
22
+ */
13
23
  static merge({ files }) {
14
24
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
15
25
  const data = new form_data_1.default();
16
- yield engine_utils_1.PDFEngineUtils.injectFiles(files, data);
26
+ yield engine_utils_1.PDFEngineUtils.addFiles(files, data);
17
27
  const endpoint = `${main_config_1.Chromiumly.GOTENBERG_ENDPOINT}/${main_config_1.Chromiumly.PDF_ENGINES_PATH}/${main_config_1.Chromiumly.PDF_ENGINE_ROUTES.merge}`;
18
28
  return common_1.GotenbergUtils.fetch(endpoint, data);
19
29
  });
20
30
  }
31
+ /**
32
+ * Converts various document formats to PDF.
33
+ *
34
+ * @param {Object} options - Options for the conversion operation.
35
+ * @param {PathLikeOrReadStream[]} options.files - An array of PathLikes or ReadStreams to the files to be converted to PDF.
36
+ * @param {PageProperties} [options.properties] - Page properties for the conversion.
37
+ * @param {PdfFormat} [options.pdfFormat] - PDF format options.
38
+ * @param {boolean} [options.pdfUA] - Indicates whether to generate PDF/UA compliant output.
39
+ * @param {boolean} [options.merge] - Indicates whether to merge the resulting PDFs.
40
+ * @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
41
+ */
21
42
  static convert({ files, properties, pdfFormat, pdfUA, merge, }) {
22
43
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
23
44
  const data = new form_data_1.default();
@@ -31,13 +52,20 @@ class PDFEngine {
31
52
  data.append("merge", String(merge));
32
53
  }
33
54
  if (properties) {
34
- libre_office_1.LibreOfficeUtils.injectPageProperties(data, properties);
55
+ libre_office_1.LibreOfficeUtils.addPageProperties(data, properties);
35
56
  }
36
- yield libre_office_1.LibreOfficeUtils.injectFiles(files, data);
57
+ yield libre_office_1.LibreOfficeUtils.addFiles(files, data);
37
58
  const endpoint = `${main_config_1.Chromiumly.GOTENBERG_ENDPOINT}/${main_config_1.Chromiumly.LIBRE_OFFICE_PATH}/${main_config_1.Chromiumly.LIBRE_OFFICE_ROUTES.convert}`;
38
59
  return common_1.GotenbergUtils.fetch(endpoint, data);
39
60
  });
40
61
  }
62
+ /**
63
+ * Generates a PDF file from a buffer and saves it to the "__generated__" directory.
64
+ *
65
+ * @param {string} filename - The filename for the generated PDF.
66
+ * @param {Buffer} buffer - The PDF content as a Buffer.
67
+ * @returns {Promise<void>} A Promise that resolves once the file is generated and saved.
68
+ */
41
69
  static generate(filename, buffer) {
42
70
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
43
71
  const __generated__ = path_1.default.resolve(process.cwd(), "__generated__");
@@ -1 +1 @@
1
- {"version":3,"file":"pdf.engine.js","sourceRoot":"","sources":["../../src/pdf-engines/pdf.engine.ts"],"names":[],"mappings":";;;;AAAA,2BAAwC;AACxC,wDAAwB;AAExB,kEAAiC;AAEjC,gDAA4C;AAC5C,sCAAsD;AACtD,kDAAmE;AACnE,uDAAsD;AAEtD,MAAa,SAAS;IACb,MAAM,CAAO,KAAK,CAAC,EAAE,KAAK,EAAyB;;YACxD,MAAM,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAC;YAC5B,MAAM,6BAAc,CAAC,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YAC9C,MAAM,QAAQ,GAAG,GAAG,wBAAU,CAAC,kBAAkB,IAAI,wBAAU,CAAC,gBAAgB,IAAI,wBAAU,CAAC,iBAAiB,CAAC,KAAK,EAAE,CAAC;YACzH,OAAO,uBAAc,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC9C,CAAC;KAAA;IAEM,MAAM,CAAO,OAAO,CAAC,EAC1B,KAAK,EACL,UAAU,EACV,SAAS,EACT,KAAK,EACL,KAAK,GAON;;YACC,MAAM,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAC;YAE5B,IAAI,SAAS,EAAE,CAAC;gBACd,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;YACjC,CAAC;YAED,IAAI,KAAK,EAAE,CAAC;gBACV,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,MAA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AC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAChD,CAAC;KAAA;IAED;;;;;;OAMG;IACI,MAAM,CAAO,QAAQ,CACxB,QAAgB,EAChB,MAAc;;YAEd,MAAM,aAAa,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,eAAe,CAAC,CAAC;YACnE,MAAM,aAAQ,CAAC,KAAK,CAAC,cAAI,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,EAAC,SAAS,EAAE,IAAI,EAAC,CAAC,CAAC;YACrE,MAAM,aAAQ,CAAC,SAAS,CAAC,cAAI,CAAC,OAAO,CAAC,aAAa,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;QAC5E,CAAC;KAAA;CACJ;AA/ED,8BA+EC"}
@@ -1,6 +1,15 @@
1
- /// <reference types="node" />
2
- import { PathLike } from "fs";
3
1
  import FormData from "form-data";
2
+ import { PathLikeOrReadStream } from "../../common";
3
+ /**
4
+ * Utility class for handling common tasks related to PDF engine operations.
5
+ */
4
6
  export declare class PDFEngineUtils {
5
- static injectFiles(files: PathLike[], data: FormData): Promise<void>;
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
+ */
14
+ static addFiles(files: PathLikeOrReadStream[], data: FormData): Promise<void>;
6
15
  }
@@ -4,18 +4,37 @@ 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 {
8
- static injectFiles(files, data) {
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
+ */
18
+ static addFiles(files, data) {
9
19
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
- for (const file of files) {
11
- yield fs_1.promises.access(file, fs_1.constants.R_OK);
12
- const filename = path_1.default.basename(file.toString());
13
- const extension = path_1.default.extname(filename);
14
- if (extension === ".pdf") {
15
- data.append(filename, (0, fs_1.createReadStream)(file));
20
+ for (const [key, file] of files.entries()) {
21
+ const filename = `file${key}.pdf`;
22
+ if (Buffer.isBuffer(file)) {
23
+ data.append("files", file, filename);
24
+ }
25
+ else if (file instanceof fs_1.ReadStream) {
26
+ data.append("files", file, filename);
16
27
  }
17
28
  else {
18
- throw new Error(`${extension} is not supported`);
29
+ yield fs_1.promises.access(file, fs_1.constants.R_OK);
30
+ const filename = path_1.default.basename(file.toString());
31
+ const extension = path_1.default.extname(filename);
32
+ if (extension === ".pdf") {
33
+ data.append(filename, (0, fs_1.createReadStream)(file));
34
+ }
35
+ else {
36
+ throw new Error(`${extension} is not supported`);
37
+ }
19
38
  }
20
39
  }
21
40
  });
@@ -1 +1 @@
1
- {"version":3,"file":"engine.utils.js","sourceRoot":"","sources":["../../../src/pdf-engines/utils/engine.utils.ts"],"names":[],"mappings":";;;;AAAA,2BAAqE;AACrE,wDAAwB;AAIxB,MAAa,cAAc;IAClB,MAAM,CAAO,WAAW,CAAC,KAAiB,EAAE,IAAc;;YAC/D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,MAAM,aAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,cAAS,CAAC,IAAI,CAAC,CAAC;gBAC5C,MAAM,QAAQ,GAAG,cAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;gBAChD,MAAM,SAAS,GAAG,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;gBACzC,IAAI,SAAS,KAAK,MAAM,EAAE,CA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AAgB,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.4.0",
3
+ "version": "2.5.1",
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.10",
51
- "@types/node": "20.10.2",
50
+ "@types/jest": "29.5.11",
51
+ "@types/node": "20.10.4",
52
52
  "@types/node-fetch": "2.6.9",
53
- "@typescript-eslint/eslint-plugin": "6.13.1",
54
- "@typescript-eslint/parser": "6.13.1",
53
+ "@typescript-eslint/eslint-plugin": "6.13.2",
54
+ "@typescript-eslint/parser": "6.13.2",
55
55
  "commitizen": "4.3.0",
56
56
  "eslint": "8.55.0",
57
57
  "husky": "8.0.3",
58
58
  "inquirer": "8",
59
59
  "jest": "29.7.0",
60
60
  "jest-junit": "16.0.0",
61
- "release-it": "17.0.0",
61
+ "release-it": "17.0.1",
62
62
  "ts-jest": "29.1.1",
63
63
  "ts-node": "10.9.1",
64
64
  "tslib": "2.6.2",
65
- "typescript": "5.3.2"
65
+ "typescript": "5.3.3"
66
66
  },
67
67
  "dependencies": {
68
68
  "config": "3.3.9",
69
69
  "dotenv": "16.3.1",
70
+ "file-type": "16.5.4",
70
71
  "form-data": "4.0.0",
71
72
  "node-fetch": "2.7.0"
72
73
  }
@@ -1,9 +1,22 @@
1
- import { Chromiumly, ChromiumRoute } from "../../main.config";
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 {
4
- readonly endpoint: string;
8
+ /**
9
+ * The endpoint URL for the converter.
10
+ */
11
+ readonly endpoint: string;
5
12
 
6
- constructor(route: ChromiumRoute) {
7
- this.endpoint = `${Chromiumly.GOTENBERG_ENDPOINT}/${Chromiumly.CHROMIUM_PATH}/${Chromiumly.CHROMIUM_ROUTES[route]}`;
8
- }
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.GOTENBERG_ENDPOINT}/${Chromiumly.CHROMIUM_PATH}/${Chromiumly.CHROMIUM_ROUTES[route]}`;
21
+ }
9
22
  }
@@ -1,71 +1,92 @@
1
- import { constants, createReadStream, PathLike, promises } from "fs";
2
-
3
1
  import FormData from "form-data";
4
2
 
5
- import { GotenbergUtils, PdfFormat } from "../../common";
3
+ import {GotenbergUtils, PathLikeOrReadStream, PdfFormat} from "../../common";
6
4
  import {
7
- EmulatedMediaType,
8
- PageProperties,
5
+ EmulatedMediaType,
6
+ PageProperties,
9
7
  } from "../interfaces/converter.types";
10
- import { ConverterUtils } from "../utils/converter.utils";
11
- import { Converter } from "./converter";
12
- import { ChromiumRoute } from "../../main.config";
8
+ import {ConverterUtils} from "../utils/converter.utils";
9
+ import {Converter} from "./converter";
10
+ import {ChromiumRoute} from "../../main.config";
13
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
+ */
14
18
  export class HtmlConverter extends Converter {
15
- constructor() {
16
- super(ChromiumRoute.HTML);
17
- }
19
+ /**
20
+ * Creates an instance of HtmlConverter.
21
+ * Initializes the converter with the HTML conversion route.
22
+ */
23
+ constructor() {
24
+ super(ChromiumRoute.HTML);
25
+ }
18
26
 
19
- async convert({
20
- html,
21
- header,
22
- footer,
23
- properties,
24
- pdfFormat,
25
- pdfUA,
26
- emulatedMediaType,
27
- waitDelay,
28
- waitForExpression,
29
- userAgent,
30
- extraHttpHeaders,
31
- failOnConsoleExceptions,
32
- }: {
33
- html: PathLike;
34
- header?: PathLike;
35
- footer?: PathLike;
36
- properties?: PageProperties;
37
- pdfFormat?: PdfFormat;
38
- pdfUA?: boolean;
39
- emulatedMediaType?: EmulatedMediaType;
40
- waitDelay?: string;
41
- waitForExpression?: string;
42
- userAgent?: string;
43
- extraHttpHeaders?: Record<string, string>;
44
- failOnConsoleExceptions?: boolean;
45
- }): Promise<Buffer> {
46
- const data = new FormData();
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
+ */
45
+ async convert({
46
+ html,
47
+ header,
48
+ footer,
49
+ properties,
50
+ pdfFormat,
51
+ pdfUA,
52
+ emulatedMediaType,
53
+ waitDelay,
54
+ waitForExpression,
55
+ userAgent,
56
+ extraHttpHeaders,
57
+ failOnConsoleExceptions,
58
+ }: {
59
+ html: PathLikeOrReadStream;
60
+ header?: PathLikeOrReadStream;
61
+ footer?: PathLikeOrReadStream;
62
+ properties?: PageProperties;
63
+ pdfFormat?: PdfFormat;
64
+ pdfUA?: boolean;
65
+ emulatedMediaType?: EmulatedMediaType;
66
+ waitDelay?: string;
67
+ waitForExpression?: string;
68
+ userAgent?: string;
69
+ extraHttpHeaders?: Record<string, string>;
70
+ failOnConsoleExceptions?: boolean;
71
+ }): Promise<Buffer> {
72
+ const data = new FormData();
47
73
 
48
- if (Buffer.isBuffer(html)) {
49
- data.append("files", html, "index.html");
50
- } else {
51
- await promises.access(html, constants.R_OK);
52
- data.append("files", createReadStream(html), "index.html");
53
- }
74
+ await ConverterUtils.addFile(data, html, "index.html");
54
75
 
55
- ConverterUtils.customize(data, {
56
- header,
57
- footer,
58
- properties,
59
- pdfFormat,
60
- pdfUA,
61
- emulatedMediaType,
62
- waitDelay,
63
- waitForExpression,
64
- userAgent,
65
- extraHttpHeaders,
66
- failOnConsoleExceptions,
67
- });
76
+ await ConverterUtils.customize(data, {
77
+ header,
78
+ footer,
79
+ properties,
80
+ pdfFormat,
81
+ pdfUA,
82
+ emulatedMediaType,
83
+ waitDelay,
84
+ waitForExpression,
85
+ userAgent,
86
+ extraHttpHeaders,
87
+ failOnConsoleExceptions,
88
+ });
68
89
 
69
- return GotenbergUtils.fetch(this.endpoint, data);
70
- }
71
- }
90
+ return GotenbergUtils.fetch(this.endpoint, data);
91
+ }
92
+ }