mindee 4.19.0 → 4.21.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 (90) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +25 -11
  3. package/package.json +1 -1
  4. package/src/cli.js +10 -20
  5. package/src/client.d.ts +3 -3
  6. package/src/client.js +2 -2
  7. package/src/http/baseEndpoint.js +2 -2
  8. package/src/http/endpoint.js +2 -2
  9. package/src/http/workflowEndpoint.js +2 -2
  10. package/src/imageOperations/invoiceSplitterExtractor/invoiceSplitterExtractor.d.ts +1 -1
  11. package/src/imageOperations/multiReceiptsExtractor/multiReceiptsExtractor.d.ts +1 -1
  12. package/src/input/index.d.ts +1 -2
  13. package/src/input/index.js +16 -15
  14. package/src/input/sources/base64Input.d.ts +12 -0
  15. package/src/input/sources/base64Input.js +22 -0
  16. package/src/input/sources/bufferInput.d.ts +10 -0
  17. package/src/input/sources/bufferInput.js +18 -0
  18. package/src/input/sources/bytesInput.d.ts +12 -0
  19. package/src/input/sources/bytesInput.js +21 -0
  20. package/src/input/sources/index.d.ts +8 -0
  21. package/src/input/sources/index.js +24 -0
  22. package/src/input/sources/inputSource.d.ts +16 -0
  23. package/src/input/sources/inputSource.js +17 -0
  24. package/src/input/sources/localInputSource.d.ts +20 -0
  25. package/src/input/{base.js → sources/localInputSource.js} +16 -26
  26. package/src/input/sources/pathInput.d.ts +11 -0
  27. package/src/input/sources/pathInput.js +27 -0
  28. package/src/input/sources/streamInput.d.ts +14 -0
  29. package/src/input/sources/streamInput.js +28 -0
  30. package/src/input/sources/urlInput.d.ts +32 -0
  31. package/src/input/sources/urlInput.js +98 -0
  32. package/src/product/driverLicense/driverLicenseV1.d.ts +16 -0
  33. package/src/product/driverLicense/driverLicenseV1.js +27 -0
  34. package/src/product/driverLicense/driverLicenseV1Document.d.ts +38 -0
  35. package/src/product/driverLicense/driverLicenseV1Document.js +84 -0
  36. package/src/product/driverLicense/index.d.ts +1 -0
  37. package/src/product/driverLicense/index.js +5 -0
  38. package/src/product/driverLicense/internal.d.ts +2 -0
  39. package/src/product/driverLicense/internal.js +7 -0
  40. package/src/product/fr/{carteVitale/carteVitaleV1.d.ts → healthCard/healthCardV1.d.ts} +5 -5
  41. package/src/product/fr/{carteVitale/carteVitaleV1.js → healthCard/healthCardV1.js} +8 -8
  42. package/src/product/fr/{carteVitale/carteVitaleV1Document.d.ts → healthCard/healthCardV1Document.d.ts} +5 -5
  43. package/src/product/fr/{carteVitale/carteVitaleV1Document.js → healthCard/healthCardV1Document.js} +5 -5
  44. package/src/product/fr/healthCard/index.d.ts +1 -0
  45. package/src/product/fr/healthCard/index.js +5 -0
  46. package/src/product/fr/healthCard/internal.d.ts +2 -0
  47. package/src/product/fr/healthCard/internal.js +7 -0
  48. package/src/product/fr/index.d.ts +2 -1
  49. package/src/product/fr/index.js +5 -3
  50. package/src/product/fr/internal.d.ts +1 -1
  51. package/src/product/fr/internal.js +2 -2
  52. package/src/product/fr/payslip/index.d.ts +1 -0
  53. package/src/product/fr/payslip/index.js +3 -1
  54. package/src/product/fr/payslip/internal.d.ts +10 -0
  55. package/src/product/fr/payslip/internal.js +21 -1
  56. package/src/product/fr/payslip/payslipV3.d.ts +16 -0
  57. package/src/product/fr/payslip/payslipV3.js +27 -0
  58. package/src/product/fr/payslip/payslipV3BankAccountDetail.d.ts +32 -0
  59. package/src/product/fr/payslip/payslipV3BankAccountDetail.js +62 -0
  60. package/src/product/fr/payslip/payslipV3Document.d.ts +35 -0
  61. package/src/product/fr/payslip/payslipV3Document.js +96 -0
  62. package/src/product/fr/payslip/payslipV3Employee.d.ts +40 -0
  63. package/src/product/fr/payslip/payslipV3Employee.js +82 -0
  64. package/src/product/fr/payslip/payslipV3Employer.d.ts +40 -0
  65. package/src/product/fr/payslip/payslipV3Employer.js +82 -0
  66. package/src/product/fr/payslip/payslipV3Employment.d.ts +40 -0
  67. package/src/product/fr/payslip/payslipV3Employment.js +82 -0
  68. package/src/product/fr/payslip/payslipV3PaidTimeOff.d.ts +36 -0
  69. package/src/product/fr/payslip/payslipV3PaidTimeOff.js +107 -0
  70. package/src/product/fr/payslip/payslipV3PayDetail.d.ts +46 -0
  71. package/src/product/fr/payslip/payslipV3PayDetail.js +168 -0
  72. package/src/product/fr/payslip/payslipV3PayPeriod.d.ts +36 -0
  73. package/src/product/fr/payslip/payslipV3PayPeriod.js +72 -0
  74. package/src/product/fr/payslip/payslipV3SalaryDetail.d.ts +36 -0
  75. package/src/product/fr/payslip/payslipV3SalaryDetail.js +110 -0
  76. package/src/product/ind/indianPassport/indianPassportV1Document.d.ts +1 -1
  77. package/src/product/ind/indianPassport/indianPassportV1Document.js +1 -1
  78. package/src/product/index.d.ts +1 -0
  79. package/src/product/index.js +3 -1
  80. package/src/product/internal.d.ts +1 -0
  81. package/src/product/internal.js +2 -1
  82. package/src/product/resume/resumeV1Document.d.ts +1 -1
  83. package/src/product/resume/resumeV1Document.js +1 -1
  84. package/src/input/base.d.ts +0 -36
  85. package/src/input/sources.d.ts +0 -59
  86. package/src/input/sources.js +0 -133
  87. package/src/product/fr/carteVitale/index.d.ts +0 -1
  88. package/src/product/fr/carteVitale/index.js +0 -5
  89. package/src/product/fr/carteVitale/internal.d.ts +0 -2
  90. package/src/product/fr/carteVitale/internal.js +0 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v4.21.0 - 2024-12-13
4
+ ### Changes
5
+ * :sparkles: allow local downloading of remote sources
6
+ * :coffin: remove support for (FR) Carte Vitale V1 in favor of French Health Card V1
7
+ ### Fixes
8
+ * :bug: fix broken loading from bytes
9
+
10
+
11
+ ## v4.20.0 - 2024-11-28
12
+ ### Changes
13
+ * :sparkles: add support for French Health Card V1
14
+ * :sparkles: add support for Driver License V1
15
+ * :sparkles: add support for Payslip FR V3
16
+
17
+
3
18
  ## v4.19.0 - 2024-11-27
4
19
  ### Changes
5
20
  * :coffin: remove support for international ID V1
package/README.md CHANGED
@@ -35,26 +35,40 @@ const apiResponse = mindeeClient.parse(mindee.product.InvoiceV4, inputSource);
35
35
 
36
36
  **Note:** Files can also be loaded from:
37
37
 
38
- A URL (`https` only):
38
+ A base64 encoded string:
39
39
  ```js
40
- const inputSource = mindeeClient.docFromUrl("https://my-url");
40
+ const inputSource = mindeeClient.docFromBase64(myInputString, "my-file-name.ext")
41
41
  ```
42
42
 
43
- A base64 encoded string:
43
+ A byte sequence:
44
44
  ```js
45
- const inputSource = mindeeClient.docFromBase64(myInputString, "my-file-name")
45
+ const inputSource = mindeeClient.docFromBytes(myInputBytes, "my-file-name.ext")
46
46
  ```
47
47
 
48
48
  A stream:
49
49
  ```js
50
- const inputSource = mindeeClient.docFromStream(myReadableStream, "my-file-name")
50
+ const inputSource = mindeeClient.docFromStream(myReadableStream, "my-file-name.ext")
51
51
  ```
52
52
 
53
53
  A buffer:
54
54
  ```js
55
- const inputSource = mindeeClient.docFromBuffer(myBuffer, "my-file-name")
55
+ const inputSource = mindeeClient.docFromBuffer(myBuffer, "my-file-name.ext")
56
+ ```
57
+
58
+ A URL (`https` only):
59
+ ```js
60
+ const inputSource = mindeeClient.docFromUrl("https://my-url");
61
+ ```
62
+
63
+ You can also load the document locally before sending it:
64
+ ```js
65
+ const inputSource = mindeeClient.docFromUrl("https://my-url");
66
+ await inputSource.init();
67
+ const localInputSource = inputSource.asLocalInputSource();
56
68
  ```
57
69
 
70
+ **Note:** Files hidden behind redirections are rejected by the server; this solution helps to circumvent that issue.
71
+
58
72
  #### Region-Specific Documents
59
73
 
60
74
  Region-Specific Documents use the following syntax:
@@ -72,7 +86,7 @@ const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext");
72
86
  const apiResponse = mindeeClient.parse(mindee.product.fr.IdCardV1, inputSource);
73
87
  ```
74
88
 
75
- #### Custom Documents (API Builder)
89
+ #### Custom Documents (docTI & Custom APIs)
76
90
 
77
91
  Custom documents will require you to provide their endpoint manually.
78
92
 
@@ -97,9 +111,9 @@ const customEndpoint = mindeeClient.createEndpoint(
97
111
  );
98
112
 
99
113
  // Parse it
100
- const apiResponse = mindeeClient
101
- .parse(
102
- mindee.product.CustomV1,
114
+ const apiResponse = await mindeeClient
115
+ .enqueueAndParse(
116
+ mindee.product.GeneratedV1,
103
117
  inputSource,
104
118
  {
105
119
  endpoint: customEndpoint
@@ -156,7 +170,7 @@ Complete details on the working of the library are available in the following gu
156
170
  * [Node.js EU License Plate OCR](https://developers.mindee.com/docs/nodejs-eu-license-plate-ocr)
157
171
  * [Node.js EU Driver License OCR](https://developers.mindee.com/docs/nodejs-eu-driver-license-ocr)
158
172
  * [Node.js FR Bank Account Detail OCR](https://developers.mindee.com/docs/nodejs-fr-bank-account-details-ocr)
159
- * [Node.js FR Carte Vitale OCR](https://developers.mindee.com/docs/nodejs-fr-carte-vitale-ocr)
173
+ * [Node.js FR Health Card OCR](https://developers.mindee.com/docs/nodejs-fr-health-card-ocr)
160
174
  * [Node.js FR ID Card OCR](https://developers.mindee.com/docs/nodejs-fr-carte-nationale-didentite-ocr)
161
175
  * [Node.js US Bank Check OCR](https://developers.mindee.com/docs/nodejs-us-bank-check-ocr)
162
176
  * [Node.js US W9 OCR](https://developers.mindee.com/docs/nodejs-us-w9-ocr)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mindee",
3
- "version": "4.19.0",
3
+ "version": "4.21.0",
4
4
  "description": "Mindee Client Library for Node.js",
5
5
  "main": "src/index.js",
6
6
  "bin": "bin/mindee.js",
package/src/cli.js CHANGED
@@ -109,13 +109,13 @@ const CLI_COMMAND_CONFIG = new Map([
109
109
  },
110
110
  ],
111
111
  [
112
- "fr-carte-vitale",
112
+ "fr-health-card",
113
113
  {
114
- displayName: "FR Carte Vitale",
115
- docClass: product.fr.CarteVitaleV1,
114
+ displayName: "FR Health Card",
115
+ docClass: product.fr.HealthCardV1,
116
116
  allWords: false,
117
- async: false,
118
- sync: true,
117
+ async: true,
118
+ sync: false,
119
119
  },
120
120
  ],
121
121
  [
@@ -139,13 +139,13 @@ const CLI_COMMAND_CONFIG = new Map([
139
139
  },
140
140
  ],
141
141
  [
142
- "eu-driver-license",
142
+ "driver-license",
143
143
  {
144
- displayName: "EU Driver License",
145
- docClass: product.eu.DriverLicenseV1,
144
+ displayName: "Driver License",
145
+ docClass: product.DriverLicenseV1,
146
146
  allWords: false,
147
- async: false,
148
- sync: true,
147
+ async: true,
148
+ sync: false,
149
149
  },
150
150
  ],
151
151
  [
@@ -228,16 +228,6 @@ const CLI_COMMAND_CONFIG = new Map([
228
228
  sync: true,
229
229
  },
230
230
  ],
231
- [
232
- "us-driver-license",
233
- {
234
- displayName: "US Driver License",
235
- docClass: product.us.DriverLicenseV1,
236
- allWords: false,
237
- async: false,
238
- sync: true,
239
- },
240
- ],
241
231
  [
242
232
  "us-healthcare-card",
243
233
  {
package/src/client.d.ts CHANGED
@@ -221,11 +221,11 @@ export declare class Client {
221
221
  */
222
222
  docFromStream(inputStream: Readable, filename: string): StreamInput;
223
223
  /**
224
- * Load an input document from a bytes string.
225
- * @param inputBytes input content, as readable bytes.
224
+ * Load an input document from bytes.
225
+ * @param inputBytes input content, as a Uint8Array or Buffer.
226
226
  * @param filename file name.
227
227
  */
228
- docFromBytes(inputBytes: string, filename: string): BytesInput;
228
+ docFromBytes(inputBytes: Uint8Array, filename: string): BytesInput;
229
229
  /**
230
230
  * Load an input document from a URL.
231
231
  * @param url input url. Must be HTTPS.
package/src/client.js CHANGED
@@ -300,8 +300,8 @@ Job status: ${pollResults.job.status}.`);
300
300
  });
301
301
  }
302
302
  /**
303
- * Load an input document from a bytes string.
304
- * @param inputBytes input content, as readable bytes.
303
+ * Load an input document from bytes.
304
+ * @param inputBytes input content, as a Uint8Array or Buffer.
305
305
  * @param filename file name.
306
306
  */
307
307
  docFromBytes(inputBytes, filename) {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BaseEndpoint = void 0;
4
4
  const logger_1 = require("../logger");
5
5
  const https_1 = require("https");
6
- const base_1 = require("../input/base");
6
+ const input_1 = require("../input");
7
7
  /**
8
8
  * Base endpoint for the Mindee API.
9
9
  */
@@ -18,7 +18,7 @@ class BaseEndpoint {
18
18
  * @param pageOptions page cutting options.
19
19
  */
20
20
  async cutDocPages(inputDoc, pageOptions) {
21
- if (inputDoc instanceof base_1.LocalInputSource && inputDoc.isPdf()) {
21
+ if (inputDoc instanceof input_1.LocalInputSource && inputDoc.isPdf()) {
22
22
  await inputDoc.cutPdf(pageOptions);
23
23
  }
24
24
  }
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Endpoint = void 0;
13
13
  const url_1 = require("url");
14
14
  const form_data_1 = __importDefault(require("form-data"));
15
- const base_1 = require("../input/base");
15
+ const input_1 = require("../input");
16
16
  const error_1 = require("./error");
17
17
  const baseEndpoint_1 = require("./baseEndpoint");
18
18
  const responseValidation_1 = require("./responseValidation");
@@ -140,7 +140,7 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
140
140
  searchParams.append("full_text_ocr", "true");
141
141
  }
142
142
  const form = new form_data_1.default();
143
- if (input instanceof base_1.LocalInputSource && input.fileObject instanceof Buffer) {
143
+ if (input instanceof input_1.LocalInputSource && input.fileObject instanceof Buffer) {
144
144
  form.append("document", input.fileObject, {
145
145
  filename: input.filename,
146
146
  });
@@ -13,7 +13,7 @@ exports.WorkflowEndpoint = void 0;
13
13
  const baseEndpoint_1 = require("./baseEndpoint");
14
14
  const url_1 = require("url");
15
15
  const form_data_1 = __importDefault(require("form-data"));
16
- const base_1 = require("../input/base");
16
+ const input_1 = require("../input");
17
17
  const responseValidation_1 = require("./responseValidation");
18
18
  const error_1 = require("./error");
19
19
  /**
@@ -57,7 +57,7 @@ class WorkflowEndpoint extends baseEndpoint_1.BaseEndpoint {
57
57
  searchParams.append("full_text_ocr", "true");
58
58
  }
59
59
  const form = new form_data_1.default();
60
- if (input instanceof base_1.LocalInputSource && input.fileObject instanceof Buffer) {
60
+ if (input instanceof input_1.LocalInputSource && input.fileObject instanceof Buffer) {
61
61
  form.append("document", input.fileObject, {
62
62
  filename: input.filename,
63
63
  });
@@ -1,5 +1,5 @@
1
1
  import { InvoiceSplitterV1 } from "../../product";
2
- import { LocalInputSource } from "../../input/base";
2
+ import { LocalInputSource } from "../../input";
3
3
  import { ExtractedInvoiceSplitterImage } from "./extractedInvoiceSplitterImage";
4
4
  /**
5
5
  * Extracts & cuts the pages of a main document invoice according to the provided indexes.
@@ -1,6 +1,6 @@
1
1
  import { MultiReceiptsDetectorV1 } from "../../product";
2
2
  import { ExtractedMultiReceiptImage } from "./extractedMultiReceiptImage";
3
- import { LocalInputSource } from "../../input/base";
3
+ import { LocalInputSource } from "../../input";
4
4
  /**
5
5
  * Extracts individual receipts from multi-receipts documents.
6
6
  *
@@ -1,4 +1,3 @@
1
1
  export { PageOptions, PageOptionsOperation } from "./pageOptions";
2
- export { Base64Input, BytesInput, PathInput, StreamInput, UrlInput, BufferInput, } from "./sources";
3
- export { InputSource, INPUT_TYPE_BASE64, INPUT_TYPE_BYTES, INPUT_TYPE_PATH, INPUT_TYPE_STREAM, INPUT_TYPE_BUFFER, } from "./base";
2
+ export * from "./sources";
4
3
  export { LocalResponse } from "./localResponse";
@@ -1,21 +1,22 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LocalResponse = exports.INPUT_TYPE_BUFFER = exports.INPUT_TYPE_STREAM = exports.INPUT_TYPE_PATH = exports.INPUT_TYPE_BYTES = exports.INPUT_TYPE_BASE64 = exports.InputSource = exports.BufferInput = exports.UrlInput = exports.StreamInput = exports.PathInput = exports.BytesInput = exports.Base64Input = exports.PageOptionsOperation = void 0;
17
+ exports.LocalResponse = exports.PageOptionsOperation = void 0;
4
18
  var pageOptions_1 = require("./pageOptions");
5
19
  Object.defineProperty(exports, "PageOptionsOperation", { enumerable: true, get: function () { return pageOptions_1.PageOptionsOperation; } });
6
- var sources_1 = require("./sources");
7
- Object.defineProperty(exports, "Base64Input", { enumerable: true, get: function () { return sources_1.Base64Input; } });
8
- Object.defineProperty(exports, "BytesInput", { enumerable: true, get: function () { return sources_1.BytesInput; } });
9
- Object.defineProperty(exports, "PathInput", { enumerable: true, get: function () { return sources_1.PathInput; } });
10
- Object.defineProperty(exports, "StreamInput", { enumerable: true, get: function () { return sources_1.StreamInput; } });
11
- Object.defineProperty(exports, "UrlInput", { enumerable: true, get: function () { return sources_1.UrlInput; } });
12
- Object.defineProperty(exports, "BufferInput", { enumerable: true, get: function () { return sources_1.BufferInput; } });
13
- var base_1 = require("./base");
14
- Object.defineProperty(exports, "InputSource", { enumerable: true, get: function () { return base_1.InputSource; } });
15
- Object.defineProperty(exports, "INPUT_TYPE_BASE64", { enumerable: true, get: function () { return base_1.INPUT_TYPE_BASE64; } });
16
- Object.defineProperty(exports, "INPUT_TYPE_BYTES", { enumerable: true, get: function () { return base_1.INPUT_TYPE_BYTES; } });
17
- Object.defineProperty(exports, "INPUT_TYPE_PATH", { enumerable: true, get: function () { return base_1.INPUT_TYPE_PATH; } });
18
- Object.defineProperty(exports, "INPUT_TYPE_STREAM", { enumerable: true, get: function () { return base_1.INPUT_TYPE_STREAM; } });
19
- Object.defineProperty(exports, "INPUT_TYPE_BUFFER", { enumerable: true, get: function () { return base_1.INPUT_TYPE_BUFFER; } });
20
+ __exportStar(require("./sources"), exports);
20
21
  var localResponse_1 = require("./localResponse");
21
22
  Object.defineProperty(exports, "LocalResponse", { enumerable: true, get: function () { return localResponse_1.LocalResponse; } });
@@ -0,0 +1,12 @@
1
+ import { LocalInputSource } from "./localInputSource";
2
+ interface Base64InputProps {
3
+ inputString: string;
4
+ filename: string;
5
+ }
6
+ export declare class Base64Input extends LocalInputSource {
7
+ private inputString;
8
+ fileObject: Buffer;
9
+ constructor({ inputString, filename }: Base64InputProps);
10
+ init(): Promise<void>;
11
+ }
12
+ export {};
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Base64Input = void 0;
4
+ const localInputSource_1 = require("./localInputSource");
5
+ const inputSource_1 = require("./inputSource");
6
+ class Base64Input extends localInputSource_1.LocalInputSource {
7
+ constructor({ inputString, filename }) {
8
+ super({
9
+ inputType: inputSource_1.INPUT_TYPE_BASE64,
10
+ });
11
+ this.fileObject = Buffer.alloc(0);
12
+ this.filename = filename;
13
+ this.inputString = inputString;
14
+ }
15
+ async init() {
16
+ this.fileObject = Buffer.from(this.inputString, "base64");
17
+ this.mimeType = await this.checkMimetype();
18
+ // clear out the string
19
+ this.inputString = "";
20
+ }
21
+ }
22
+ exports.Base64Input = Base64Input;
@@ -0,0 +1,10 @@
1
+ import { LocalInputSource } from "./localInputSource";
2
+ interface BufferInputProps {
3
+ buffer: Buffer;
4
+ filename: string;
5
+ }
6
+ export declare class BufferInput extends LocalInputSource {
7
+ constructor({ buffer, filename }: BufferInputProps);
8
+ init(): Promise<void>;
9
+ }
10
+ export {};
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BufferInput = void 0;
4
+ const localInputSource_1 = require("./localInputSource");
5
+ const inputSource_1 = require("./inputSource");
6
+ class BufferInput extends localInputSource_1.LocalInputSource {
7
+ constructor({ buffer, filename }) {
8
+ super({
9
+ inputType: inputSource_1.INPUT_TYPE_BUFFER,
10
+ });
11
+ this.fileObject = buffer;
12
+ this.filename = filename;
13
+ }
14
+ async init() {
15
+ this.mimeType = await this.checkMimetype();
16
+ }
17
+ }
18
+ exports.BufferInput = BufferInput;
@@ -0,0 +1,12 @@
1
+ import { LocalInputSource } from "./localInputSource";
2
+ interface BytesInputProps {
3
+ inputBytes: Uint8Array;
4
+ filename: string;
5
+ }
6
+ export declare class BytesInput extends LocalInputSource {
7
+ private inputBytes;
8
+ fileObject: Buffer;
9
+ constructor({ inputBytes, filename }: BytesInputProps);
10
+ init(): Promise<void>;
11
+ }
12
+ export {};
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BytesInput = void 0;
4
+ const inputSource_1 = require("./inputSource");
5
+ const localInputSource_1 = require("./localInputSource");
6
+ class BytesInput extends localInputSource_1.LocalInputSource {
7
+ constructor({ inputBytes, filename }) {
8
+ super({
9
+ inputType: inputSource_1.INPUT_TYPE_BYTES,
10
+ });
11
+ this.fileObject = Buffer.alloc(0);
12
+ this.filename = filename;
13
+ this.inputBytes = inputBytes;
14
+ }
15
+ async init() {
16
+ this.fileObject = Buffer.from(this.inputBytes);
17
+ this.mimeType = await this.checkMimetype();
18
+ this.inputBytes = new Uint8Array(0);
19
+ }
20
+ }
21
+ exports.BytesInput = BytesInput;
@@ -0,0 +1,8 @@
1
+ export { Base64Input } from "./base64Input";
2
+ export { BufferInput } from "./bufferInput";
3
+ export { BytesInput } from "./bytesInput";
4
+ export { InputSource, INPUT_TYPE_PATH, INPUT_TYPE_STREAM, InputConstructor, INPUT_TYPE_BUFFER, INPUT_TYPE_BASE64, INPUT_TYPE_BYTES } from "./inputSource";
5
+ export { LocalInputSource } from "./localInputSource";
6
+ export { PathInput } from "./pathInput";
7
+ export { StreamInput } from "./streamInput";
8
+ export { UrlInput } from "./urlInput";
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UrlInput = exports.StreamInput = exports.PathInput = exports.LocalInputSource = exports.INPUT_TYPE_BYTES = exports.INPUT_TYPE_BASE64 = exports.INPUT_TYPE_BUFFER = exports.INPUT_TYPE_STREAM = exports.INPUT_TYPE_PATH = exports.InputSource = exports.BytesInput = exports.BufferInput = exports.Base64Input = void 0;
4
+ var base64Input_1 = require("./base64Input");
5
+ Object.defineProperty(exports, "Base64Input", { enumerable: true, get: function () { return base64Input_1.Base64Input; } });
6
+ var bufferInput_1 = require("./bufferInput");
7
+ Object.defineProperty(exports, "BufferInput", { enumerable: true, get: function () { return bufferInput_1.BufferInput; } });
8
+ var bytesInput_1 = require("./bytesInput");
9
+ Object.defineProperty(exports, "BytesInput", { enumerable: true, get: function () { return bytesInput_1.BytesInput; } });
10
+ var inputSource_1 = require("./inputSource");
11
+ Object.defineProperty(exports, "InputSource", { enumerable: true, get: function () { return inputSource_1.InputSource; } });
12
+ Object.defineProperty(exports, "INPUT_TYPE_PATH", { enumerable: true, get: function () { return inputSource_1.INPUT_TYPE_PATH; } });
13
+ Object.defineProperty(exports, "INPUT_TYPE_STREAM", { enumerable: true, get: function () { return inputSource_1.INPUT_TYPE_STREAM; } });
14
+ Object.defineProperty(exports, "INPUT_TYPE_BUFFER", { enumerable: true, get: function () { return inputSource_1.INPUT_TYPE_BUFFER; } });
15
+ Object.defineProperty(exports, "INPUT_TYPE_BASE64", { enumerable: true, get: function () { return inputSource_1.INPUT_TYPE_BASE64; } });
16
+ Object.defineProperty(exports, "INPUT_TYPE_BYTES", { enumerable: true, get: function () { return inputSource_1.INPUT_TYPE_BYTES; } });
17
+ var localInputSource_1 = require("./localInputSource");
18
+ Object.defineProperty(exports, "LocalInputSource", { enumerable: true, get: function () { return localInputSource_1.LocalInputSource; } });
19
+ var pathInput_1 = require("./pathInput");
20
+ Object.defineProperty(exports, "PathInput", { enumerable: true, get: function () { return pathInput_1.PathInput; } });
21
+ var streamInput_1 = require("./streamInput");
22
+ Object.defineProperty(exports, "StreamInput", { enumerable: true, get: function () { return streamInput_1.StreamInput; } });
23
+ var urlInput_1 = require("./urlInput");
24
+ Object.defineProperty(exports, "UrlInput", { enumerable: true, get: function () { return urlInput_1.UrlInput; } });
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @param {string} inputType - the type of input used in file ("base64", "path", "dummy").
3
+ * NB: dummy is only used for tests purposes
4
+ */
5
+ export interface InputConstructor {
6
+ inputType: string;
7
+ }
8
+ export declare const INPUT_TYPE_STREAM = "stream";
9
+ export declare const INPUT_TYPE_BASE64 = "base64";
10
+ export declare const INPUT_TYPE_BYTES = "bytes";
11
+ export declare const INPUT_TYPE_PATH = "path";
12
+ export declare const INPUT_TYPE_BUFFER = "buffer";
13
+ export declare abstract class InputSource {
14
+ fileObject: Buffer | string;
15
+ init(): Promise<void>;
16
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InputSource = exports.INPUT_TYPE_BUFFER = exports.INPUT_TYPE_PATH = exports.INPUT_TYPE_BYTES = exports.INPUT_TYPE_BASE64 = exports.INPUT_TYPE_STREAM = void 0;
4
+ exports.INPUT_TYPE_STREAM = "stream";
5
+ exports.INPUT_TYPE_BASE64 = "base64";
6
+ exports.INPUT_TYPE_BYTES = "bytes";
7
+ exports.INPUT_TYPE_PATH = "path";
8
+ exports.INPUT_TYPE_BUFFER = "buffer";
9
+ class InputSource {
10
+ constructor() {
11
+ this.fileObject = "";
12
+ }
13
+ async init() {
14
+ throw new Error("not Implemented");
15
+ }
16
+ }
17
+ exports.InputSource = InputSource;
@@ -0,0 +1,20 @@
1
+ import { PageOptions } from "../pageOptions";
2
+ import { InputSource, InputConstructor } from "./inputSource";
3
+ export declare abstract class LocalInputSource extends InputSource {
4
+ inputType: string;
5
+ filename: string;
6
+ filepath?: string;
7
+ mimeType: string;
8
+ fileObject: Buffer | string;
9
+ /**
10
+ * @param {InputConstructor} constructor Constructor parameters.
11
+ */
12
+ protected constructor({ inputType }: InputConstructor);
13
+ isPdf(): boolean;
14
+ checkMimetype(): Promise<string>;
15
+ /**
16
+ * Cut PDF pages.
17
+ * @param pageOptions
18
+ */
19
+ cutPdf(pageOptions: PageOptions): Promise<void>;
20
+ }
@@ -22,18 +22,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
25
28
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.LocalInputSource = exports.InputSource = exports.INPUT_TYPE_BUFFER = exports.INPUT_TYPE_PATH = exports.INPUT_TYPE_BYTES = exports.INPUT_TYPE_BASE64 = exports.INPUT_TYPE_STREAM = void 0;
29
+ exports.LocalInputSource = void 0;
30
+ const handler_1 = require("../../errors/handler");
31
+ const logger_1 = require("../../logger");
32
+ const path_1 = __importDefault(require("path"));
27
33
  const fileType = __importStar(require("file-type"));
28
- const path = __importStar(require("path"));
29
- const pdf_1 = require("../pdf");
30
- const logger_1 = require("../logger");
31
- const handler_1 = require("../errors/handler");
32
- exports.INPUT_TYPE_STREAM = "stream";
33
- exports.INPUT_TYPE_BASE64 = "base64";
34
- exports.INPUT_TYPE_BYTES = "bytes";
35
- exports.INPUT_TYPE_PATH = "path";
36
- exports.INPUT_TYPE_BUFFER = "buffer";
34
+ const pdf_1 = require("../../pdf");
35
+ const inputSource_1 = require("./inputSource");
37
36
  const MIMETYPES = new Map([
38
37
  [".pdf", "application/pdf"],
39
38
  [".heic", "image/heic"],
@@ -45,22 +44,13 @@ const MIMETYPES = new Map([
45
44
  [".webp", "image/webp"],
46
45
  ]);
47
46
  const ALLOWED_INPUT_TYPES = [
48
- exports.INPUT_TYPE_STREAM,
49
- exports.INPUT_TYPE_BASE64,
50
- exports.INPUT_TYPE_BYTES,
51
- exports.INPUT_TYPE_PATH,
52
- exports.INPUT_TYPE_BUFFER,
47
+ inputSource_1.INPUT_TYPE_STREAM,
48
+ inputSource_1.INPUT_TYPE_BASE64,
49
+ inputSource_1.INPUT_TYPE_BYTES,
50
+ inputSource_1.INPUT_TYPE_PATH,
51
+ inputSource_1.INPUT_TYPE_BUFFER,
53
52
  ];
54
- class InputSource {
55
- constructor() {
56
- this.fileObject = "";
57
- }
58
- async init() {
59
- throw new Error("not Implemented");
60
- }
61
- }
62
- exports.InputSource = InputSource;
63
- class LocalInputSource extends InputSource {
53
+ class LocalInputSource extends inputSource_1.InputSource {
64
54
  /**
65
55
  * @param {InputConstructor} constructor Constructor parameters.
66
56
  */
@@ -84,7 +74,7 @@ class LocalInputSource extends InputSource {
84
74
  throw new Error(`MIME type cannot be verified on input source of type ${this.inputType}.`);
85
75
  }
86
76
  let mimeType;
87
- const fileExt = path.extname(this.filename);
77
+ const fileExt = path_1.default.extname(this.filename);
88
78
  if (fileExt) {
89
79
  mimeType = MIMETYPES.get(fileExt.toLowerCase()) || "";
90
80
  }
@@ -0,0 +1,11 @@
1
+ import { LocalInputSource } from "./localInputSource";
2
+ interface PathInputProps {
3
+ inputPath: string;
4
+ }
5
+ export declare class PathInput extends LocalInputSource {
6
+ readonly inputPath: string;
7
+ fileObject: Buffer;
8
+ constructor({ inputPath }: PathInputProps);
9
+ init(): Promise<void>;
10
+ }
11
+ export {};
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PathInput = void 0;
7
+ const inputSource_1 = require("./inputSource");
8
+ const localInputSource_1 = require("./localInputSource");
9
+ const path_1 = __importDefault(require("path"));
10
+ const logger_1 = require("../../logger");
11
+ const fs_1 = require("fs");
12
+ class PathInput extends localInputSource_1.LocalInputSource {
13
+ constructor({ inputPath }) {
14
+ super({
15
+ inputType: inputSource_1.INPUT_TYPE_PATH,
16
+ });
17
+ this.fileObject = Buffer.alloc(0);
18
+ this.inputPath = inputPath;
19
+ this.filename = path_1.default.basename(this.inputPath);
20
+ }
21
+ async init() {
22
+ logger_1.logger.debug(`Loading from: ${this.inputPath}`);
23
+ this.fileObject = Buffer.from(await fs_1.promises.readFile(this.inputPath));
24
+ this.mimeType = await this.checkMimetype();
25
+ }
26
+ }
27
+ exports.PathInput = PathInput;
@@ -0,0 +1,14 @@
1
+ import { Readable } from "stream";
2
+ import { LocalInputSource } from "./localInputSource";
3
+ interface StreamInputProps {
4
+ inputStream: Readable;
5
+ filename: string;
6
+ }
7
+ export declare class StreamInput extends LocalInputSource {
8
+ private readonly inputStream;
9
+ fileObject: Buffer;
10
+ constructor({ inputStream, filename }: StreamInputProps);
11
+ init(): Promise<void>;
12
+ stream2buffer(stream: Readable): Promise<Buffer>;
13
+ }
14
+ export {};