mindee 3.0.1 → 3.1.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v3.1.1 - 2022-11-08
4
+ ### Changes
5
+ * :bug: fix proper import and documentation of region-specific documents
6
+
7
+ ## v3.1.0 - 2022-11-08
8
+ ### Changes
9
+ * :sparkles: Add support for French ID cards.
10
+ * :sparkles: add buffer input source
11
+
3
12
  ## v3.0.1 - 2022-11-02
4
13
  ### Fixes
5
14
  * :bug: Fix for `supplier` property name in `ReceiptV4` document.
package/README.md CHANGED
@@ -13,63 +13,69 @@ npm install mindee
13
13
 
14
14
  Finally, Node.js away!
15
15
 
16
- ### Off-the-Shelf Documents
16
+ ### Loading a File and Parsing It
17
17
 
18
+ #### Global Documents
18
19
  ```js
19
20
  const mindee = require("mindee");
20
21
  // for TS or modules:
21
22
  // import * as mindee from "mindee";
22
23
 
23
24
  // Init a new client
24
- const mindeeClient = new mindee.Client({apiKey: "my-api-key"});
25
+ const mindeeClient = new mindee.Client({ apiKey: "my-api-key" });
25
26
 
26
27
  // Load a file from disk and parse it
27
- const invoiceResponse = mindeeClient
28
- .docFromPath("/path/to/the/invoice.pdf")
28
+ const apiResponse = mindeeClient
29
+ .docFromPath("/path/to/the/file.ext")
29
30
  .parse(mindee.InvoiceV3);
31
+ ```
30
32
 
31
- // Print a brief summary of the parsed data
32
- invoiceResponse.then((resp) => {
33
-
34
- // The document property can be undefined:
35
- // * TypeScript will throw an error without this guard clause
36
- // (or consider using the '?' notation)
37
- // * JavaScript will be very happy to produce subtle bugs
38
- // without this guard clause
39
- if (resp.document === undefined) return;
33
+ #### Region-Specific Documents
34
+ ```js
35
+ const mindee = require("mindee");
36
+ // for TS or modules:
37
+ // import * as mindee from "mindee";
40
38
 
41
- // full object
42
- console.log(resp.document);
39
+ // Init a new client
40
+ const mindeeClient = new mindee.Client({ apiKey: "my-api-key" });
43
41
 
44
- // string summary
45
- console.log(resp.document.toString());
46
- });
42
+ // Load a file from disk and parse it
43
+ const apiResponse = mindeeClient
44
+ .docFromPath("/path/to/the/file.ext")
45
+ .parse(mindee.fr.IdCardV1);
47
46
  ```
48
47
 
49
- ### Custom Documents (API Builder)
50
-
48
+ #### Custom Documents (API Builder)
51
49
  ```js
52
50
  const mindee = require("mindee");
53
51
  // for TS or modules:
54
52
  // import * as mindee from "mindee";
55
53
 
56
54
  // Init a new client and add your document endpoint
57
- const mindeeClient = new mindee.Client({apiKey: "my-api-key"})
55
+ const mindeeClient = new mindee.Client({ apiKey: "my-api-key" })
58
56
  .addEndpoint({
59
57
  accountName: "john",
60
58
  endpointName: "wsnine",
61
59
  });
62
60
 
63
61
  // Load a file from disk and parse it
64
- const customResponse = mindeeClient
65
- .docFromPath("/path/to/the/wsnine.jpg")
62
+ const apiResponse = mindeeClient
63
+ .docFromPath("/path/to/the/file.ext")
66
64
  .parse(mindee.CustomV1, { endpointName: "wsnine" });
65
+ ```
67
66
 
67
+ ### Handling the Return
68
+ ```js
68
69
  // Print a brief summary of the parsed data
69
- customResponse.then((resp) => {
70
+ invoiceResponse.then((resp) => {
70
71
 
72
+ // The document property can be undefined:
73
+ // * TypeScript will throw an error without this guard clause
74
+ // (or consider using the '?' notation)
75
+ // * JavaScript will be very happy to produce subtle bugs
76
+ // without this guard clause
71
77
  if (resp.document === undefined) return;
72
-
78
+
73
79
  // full object
74
80
  console.log(resp.document);
75
81
 
@@ -83,7 +89,7 @@ There's more to it than that for those that need more features, or want to
83
89
  customize the experience.
84
90
 
85
91
  All the juicy details are described in the
86
- **[Official Documentation](https://developers.mindee.com/docs/nodejs-sdk)**.
92
+ **[Official Guide](https://developers.mindee.com/docs/nodejs-sdk)**.
87
93
 
88
94
  ## License
89
95
  Copyright © Mindee
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mindee",
3
- "version": "3.0.1",
3
+ "version": "3.1.1",
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
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.cli = void 0;
4
4
  const commander_1 = require("commander");
5
5
  const documents_1 = require("./documents");
6
+ const fr_1 = require("./documents/fr");
6
7
  const api_1 = require("./api");
7
8
  const client_1 = require("./client");
8
9
  const program = new commander_1.Command();
@@ -10,13 +11,14 @@ const COMMAND_INVOICE = "invoice";
10
11
  const COMMAND_RECEIPT = "receipt";
11
12
  const COMMAND_PASSPORT = "passport";
12
13
  const COMMAND_FINANCIAL = "financial";
14
+ const COMMAND_FR_ID_CARD = "fr-id-card";
13
15
  const COMMAND_CUSTOM = "custom";
14
16
  const CLI_COMMAND_CONFIG = new Map([
15
17
  [
16
18
  COMMAND_INVOICE,
17
19
  {
18
20
  description: "Invoice V3",
19
- docType: documents_1.DOC_TYPE_INVOICE_V3,
21
+ docType: documents_1.InvoiceV3.name,
20
22
  fullText: true,
21
23
  },
22
24
  ],
@@ -24,7 +26,7 @@ const CLI_COMMAND_CONFIG = new Map([
24
26
  COMMAND_RECEIPT,
25
27
  {
26
28
  description: "Expense Receipt V4",
27
- docType: documents_1.DOC_TYPE_RECEIPT_V4,
29
+ docType: documents_1.ReceiptV4.name,
28
30
  fullText: true,
29
31
  },
30
32
  ],
@@ -32,7 +34,7 @@ const CLI_COMMAND_CONFIG = new Map([
32
34
  COMMAND_PASSPORT,
33
35
  {
34
36
  description: "Passport V1",
35
- docType: documents_1.DOC_TYPE_PASSPORT_V1,
37
+ docType: documents_1.PassportV1.name,
36
38
  fullText: false,
37
39
  },
38
40
  ],
@@ -40,15 +42,23 @@ const CLI_COMMAND_CONFIG = new Map([
40
42
  COMMAND_FINANCIAL,
41
43
  {
42
44
  description: "Financial Document V1 (receipt or invoice)",
43
- docType: documents_1.DOC_TYPE_FINANCIAL_V1,
45
+ docType: documents_1.FinancialDocumentV1.name,
44
46
  fullText: true,
45
47
  },
46
48
  ],
49
+ [
50
+ COMMAND_FR_ID_CARD,
51
+ {
52
+ description: "FR ID Card V1",
53
+ docType: fr_1.IdCardV1.name,
54
+ fullText: false,
55
+ },
56
+ ],
47
57
  [
48
58
  COMMAND_CUSTOM,
49
59
  {
50
60
  description: "A custom document",
51
- docType: documents_1.DOC_TYPE_CUSTOM,
61
+ docType: documents_1.CustomV1.name,
52
62
  fullText: false,
53
63
  },
54
64
  ],
@@ -95,6 +105,9 @@ async function predictCall(command, inputPath, options) {
95
105
  case COMMAND_PASSPORT:
96
106
  response = await doc.parse(documents_1.PassportV1, predictParams);
97
107
  break;
108
+ case COMMAND_FR_ID_CARD:
109
+ response = await doc.parse(fr_1.IdCardV1, predictParams);
110
+ break;
98
111
  case COMMAND_CUSTOM:
99
112
  response = await doc.parse(documents_1.CustomV1, predictParams);
100
113
  break;
package/src/client.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { InputSource, PageOptions } from "./inputs";
3
4
  import { Response } from "./api";
4
5
  import { Document, DocumentSig } from "./documents";
@@ -79,5 +80,11 @@ export declare class Client {
79
80
  * @param url
80
81
  */
81
82
  docFromUrl(url: string): DocumentClient;
83
+ /**
84
+ * Load an input document from a Buffer.
85
+ * @param buffer
86
+ * @param filename
87
+ */
88
+ docFromBuffer(buffer: Buffer, filename: string): DocumentClient;
82
89
  }
83
90
  export {};
package/src/client.js CHANGED
@@ -97,6 +97,9 @@ class Client {
97
97
  this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.CropperV1.name], new documentConfig_1.DocumentConfig(documents_1.CropperV1, [
98
98
  new api_1.StandardEndpoint("cropper", "1", this.apiKey),
99
99
  ]));
100
+ this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.fr.IdCardV1.name], new documentConfig_1.DocumentConfig(documents_1.fr.IdCardV1, [
101
+ new api_1.StandardEndpoint("idcard_fr", "1", this.apiKey),
102
+ ]));
100
103
  }
101
104
  /**
102
105
  * Add a custom endpoint to the client.
@@ -169,5 +172,17 @@ class Client {
169
172
  });
170
173
  return new DocumentClient(doc, this.docConfigs);
171
174
  }
175
+ /**
176
+ * Load an input document from a Buffer.
177
+ * @param buffer
178
+ * @param filename
179
+ */
180
+ docFromBuffer(buffer, filename) {
181
+ const doc = new inputs_1.BufferInput({
182
+ buffer: buffer,
183
+ filename: filename,
184
+ });
185
+ return new DocumentClient(doc, this.docConfigs);
186
+ }
172
187
  }
173
188
  exports.Client = Client;
@@ -1,3 +1,17 @@
1
- import { Document } from "../../document";
1
+ import { Document, DocumentConstructorProps } from "../../document";
2
+ import { Field, DateField, BaseField } from "../../../fields";
2
3
  export declare class IdCardV1 extends Document {
4
+ authority: Field;
5
+ documentSide: BaseField;
6
+ idNumber: Field;
7
+ birthDate: DateField;
8
+ expiryDate: DateField;
9
+ birthPlace: Field;
10
+ gender: Field;
11
+ mrz1: Field;
12
+ mrz2: Field;
13
+ surname: Field;
14
+ givenNames: Field[];
15
+ constructor({ prediction, orientation, extras, inputSource, pageId, }: DocumentConstructorProps);
16
+ toString(): string;
3
17
  }
@@ -2,6 +2,77 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.IdCardV1 = void 0;
4
4
  const document_1 = require("../../document");
5
+ const fields_1 = require("../../../fields");
5
6
  class IdCardV1 extends document_1.Document {
7
+ constructor({ prediction, orientation = undefined, extras = undefined, inputSource = undefined, pageId = undefined, }) {
8
+ super({
9
+ inputSource: inputSource,
10
+ pageId: pageId,
11
+ orientation: orientation,
12
+ extras: extras,
13
+ });
14
+ this.givenNames = [];
15
+ this.authority = new fields_1.Field({
16
+ prediction: prediction.authority,
17
+ pageId: pageId,
18
+ });
19
+ this.documentSide = new fields_1.BaseField({
20
+ prediction: prediction.document_side,
21
+ });
22
+ this.idNumber = new fields_1.Field({
23
+ prediction: prediction.id_number,
24
+ pageId: pageId,
25
+ });
26
+ this.birthDate = new fields_1.DateField({
27
+ prediction: prediction.birth_date,
28
+ pageId: pageId,
29
+ });
30
+ this.expiryDate = new fields_1.DateField({
31
+ prediction: prediction.expiry_date,
32
+ pageId: pageId,
33
+ });
34
+ this.birthPlace = new fields_1.Field({
35
+ prediction: prediction.birth_place,
36
+ pageId: pageId,
37
+ });
38
+ this.gender = new fields_1.Field({
39
+ prediction: prediction.gender,
40
+ pageId: pageId,
41
+ });
42
+ this.surname = new fields_1.Field({
43
+ prediction: prediction.surname,
44
+ pageId: pageId,
45
+ });
46
+ this.mrz1 = new fields_1.Field({
47
+ prediction: prediction.mrz1,
48
+ pageId: pageId,
49
+ });
50
+ this.mrz2 = new fields_1.Field({
51
+ prediction: prediction.mrz2,
52
+ pageId: pageId,
53
+ });
54
+ prediction.given_names.map((prediction) => this.givenNames.push(new fields_1.Field({
55
+ prediction: prediction,
56
+ pageId: pageId,
57
+ })));
58
+ }
59
+ toString() {
60
+ const outStr = `----- FR ID Card V1 -----
61
+ Filename: ${this.filename}
62
+ Document side: ${this.documentSide}
63
+ Authority: ${this.authority}
64
+ Given names: ${this.givenNames.map((name) => name.value).join(" ")}
65
+ Surname: ${this.surname}
66
+ Gender: ${this.gender}
67
+ ID Number: ${this.idNumber}
68
+ Birth date: ${this.birthDate}
69
+ Birth place: ${this.birthPlace}
70
+ Expiry date: ${this.expiryDate}
71
+ MRZ 1: ${this.mrz1}
72
+ MRZ 2: ${this.mrz2}
73
+ ----------------------
74
+ `;
75
+ return IdCardV1.cleanOutString(outStr);
76
+ }
6
77
  }
7
78
  exports.IdCardV1 = IdCardV1;
@@ -0,0 +1 @@
1
+ export { IdCardV1 } from "./idCard/idCardV1";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IdCardV1 = void 0;
4
+ var idCardV1_1 = require("./idCard/idCardV1");
5
+ Object.defineProperty(exports, "IdCardV1", { enumerable: true, get: function () { return idCardV1_1.IdCardV1; } });
@@ -1,16 +1,10 @@
1
- import { InvoiceV3 } from "./invoice/invoiceV3";
2
- import { ReceiptV3 } from "./receipt/receiptV3";
3
- import { ReceiptV4 } from "./receipt/receiptV4";
4
- import { PassportV1 } from "./passport/passportV1";
5
- import { FinancialDocumentV1 } from "./financialDocument/financialDocumentV1";
6
- import { CustomV1 } from "./custom";
7
- import { CropperV1 } from "./cropper/cropperV1";
1
+ export { InvoiceV3 } from "./invoice/invoiceV3";
2
+ export { ReceiptV3 } from "./receipt/receiptV3";
3
+ export { ReceiptV4 } from "./receipt/receiptV4";
4
+ export { PassportV1 } from "./passport/passportV1";
5
+ export { FinancialDocumentV1 } from "./financialDocument/financialDocumentV1";
6
+ export { CustomV1 } from "./custom";
7
+ export { CropperV1 } from "./cropper/cropperV1";
8
8
  export { Document, DocumentConstructorProps, DocumentSig } from "./document";
9
- export { ReceiptV3, ReceiptV4, InvoiceV3, FinancialDocumentV1, PassportV1, CustomV1, CropperV1, };
10
- export declare const DOC_TYPE_CUSTOM: string;
11
- export declare const DOC_TYPE_INVOICE_V3: string;
12
- export declare const DOC_TYPE_RECEIPT_V3: string;
13
- export declare const DOC_TYPE_RECEIPT_V4: string;
14
- export declare const DOC_TYPE_PASSPORT_V1: string;
15
- export declare const DOC_TYPE_FINANCIAL_V1: string;
16
- export declare const DOC_TYPE_CROPPER_V1: string;
9
+ export * as fr from "./fr";
10
+ export * as us from "./us";
@@ -1,26 +1,44 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DOC_TYPE_CROPPER_V1 = exports.DOC_TYPE_FINANCIAL_V1 = exports.DOC_TYPE_PASSPORT_V1 = exports.DOC_TYPE_RECEIPT_V4 = exports.DOC_TYPE_RECEIPT_V3 = exports.DOC_TYPE_INVOICE_V3 = exports.DOC_TYPE_CUSTOM = exports.CropperV1 = exports.CustomV1 = exports.PassportV1 = exports.FinancialDocumentV1 = exports.InvoiceV3 = exports.ReceiptV4 = exports.ReceiptV3 = exports.Document = void 0;
4
- const invoiceV3_1 = require("./invoice/invoiceV3");
26
+ exports.us = exports.fr = exports.Document = exports.CropperV1 = exports.CustomV1 = exports.FinancialDocumentV1 = exports.PassportV1 = exports.ReceiptV4 = exports.ReceiptV3 = exports.InvoiceV3 = void 0;
27
+ var invoiceV3_1 = require("./invoice/invoiceV3");
5
28
  Object.defineProperty(exports, "InvoiceV3", { enumerable: true, get: function () { return invoiceV3_1.InvoiceV3; } });
6
- const receiptV3_1 = require("./receipt/receiptV3");
29
+ var receiptV3_1 = require("./receipt/receiptV3");
7
30
  Object.defineProperty(exports, "ReceiptV3", { enumerable: true, get: function () { return receiptV3_1.ReceiptV3; } });
8
- const receiptV4_1 = require("./receipt/receiptV4");
31
+ var receiptV4_1 = require("./receipt/receiptV4");
9
32
  Object.defineProperty(exports, "ReceiptV4", { enumerable: true, get: function () { return receiptV4_1.ReceiptV4; } });
10
- const passportV1_1 = require("./passport/passportV1");
33
+ var passportV1_1 = require("./passport/passportV1");
11
34
  Object.defineProperty(exports, "PassportV1", { enumerable: true, get: function () { return passportV1_1.PassportV1; } });
12
- const financialDocumentV1_1 = require("./financialDocument/financialDocumentV1");
35
+ var financialDocumentV1_1 = require("./financialDocument/financialDocumentV1");
13
36
  Object.defineProperty(exports, "FinancialDocumentV1", { enumerable: true, get: function () { return financialDocumentV1_1.FinancialDocumentV1; } });
14
- const custom_1 = require("./custom");
37
+ var custom_1 = require("./custom");
15
38
  Object.defineProperty(exports, "CustomV1", { enumerable: true, get: function () { return custom_1.CustomV1; } });
16
- const cropperV1_1 = require("./cropper/cropperV1");
39
+ var cropperV1_1 = require("./cropper/cropperV1");
17
40
  Object.defineProperty(exports, "CropperV1", { enumerable: true, get: function () { return cropperV1_1.CropperV1; } });
18
41
  var document_1 = require("./document");
19
42
  Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return document_1.Document; } });
20
- exports.DOC_TYPE_CUSTOM = custom_1.CustomV1.name;
21
- exports.DOC_TYPE_INVOICE_V3 = invoiceV3_1.InvoiceV3.name;
22
- exports.DOC_TYPE_RECEIPT_V3 = receiptV3_1.ReceiptV3.name;
23
- exports.DOC_TYPE_RECEIPT_V4 = receiptV4_1.ReceiptV4.name;
24
- exports.DOC_TYPE_PASSPORT_V1 = passportV1_1.PassportV1.name;
25
- exports.DOC_TYPE_FINANCIAL_V1 = financialDocumentV1_1.FinancialDocumentV1.name;
26
- exports.DOC_TYPE_CROPPER_V1 = cropperV1_1.CropperV1.name;
43
+ exports.fr = __importStar(require("./fr"));
44
+ exports.us = __importStar(require("./us"));
@@ -0,0 +1 @@
1
+ export { BankCheckV1 } from "./bankCheck/bankCheckV1";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BankCheckV1 = void 0;
4
+ var bankCheckV1_1 = require("./bankCheck/bankCheckV1");
5
+ Object.defineProperty(exports, "BankCheckV1", { enumerable: true, get: function () { return bankCheckV1_1.BankCheckV1; } });
@@ -25,6 +25,7 @@ export declare class BaseField {
25
25
  * @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
26
26
  */
27
27
  constructor({ prediction, valueKey, reconstructed, }: BaseFieldConstructor);
28
+ toString(): string;
28
29
  }
29
30
  export declare class Field extends BaseField {
30
31
  /**
@@ -69,5 +70,4 @@ export declare class Field extends BaseField {
69
70
  * @returns {Number} Sum of all the Fields values in the array
70
71
  */
71
72
  static arraySum(array: any): number;
72
- toString(): string;
73
73
  }
@@ -11,10 +11,19 @@ class BaseField {
11
11
  constructor({ prediction, valueKey = "value", reconstructed = false, }) {
12
12
  this.value = undefined;
13
13
  this.reconstructed = reconstructed;
14
- if (valueKey in prediction && prediction[valueKey] !== null) {
14
+ if (prediction !== undefined &&
15
+ prediction !== null &&
16
+ valueKey in prediction &&
17
+ prediction[valueKey] !== null) {
15
18
  this.value = prediction[valueKey];
16
19
  }
17
20
  }
21
+ toString() {
22
+ if (this.value !== undefined) {
23
+ return `${this.value}`;
24
+ }
25
+ return "";
26
+ }
18
27
  }
19
28
  exports.BaseField = BaseField;
20
29
  class Field extends BaseField {
@@ -97,11 +106,5 @@ class Field extends BaseField {
97
106
  }
98
107
  return total;
99
108
  }
100
- toString() {
101
- if (this.value !== undefined) {
102
- return `${this.value}`;
103
- }
104
- return "";
105
- }
106
109
  }
107
110
  exports.Field = Field;
package/src/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { CustomV1, FinancialDocumentV1, InvoiceV3, PassportV1, ReceiptV3, ReceiptV4, CropperV1, } from "./documents";
1
+ export { CustomV1, FinancialDocumentV1, InvoiceV3, PassportV1, ReceiptV3, ReceiptV4, CropperV1, fr, us, } from "./documents";
2
2
  export { Client } from "./client";
3
3
  export { PageOptionsOperation } from "./inputs";
package/src/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PageOptionsOperation = exports.Client = exports.CropperV1 = exports.ReceiptV4 = exports.ReceiptV3 = exports.PassportV1 = exports.InvoiceV3 = exports.FinancialDocumentV1 = exports.CustomV1 = void 0;
3
+ exports.PageOptionsOperation = exports.Client = exports.us = exports.fr = exports.CropperV1 = exports.ReceiptV4 = exports.ReceiptV3 = exports.PassportV1 = exports.InvoiceV3 = exports.FinancialDocumentV1 = exports.CustomV1 = void 0;
4
4
  var documents_1 = require("./documents");
5
5
  Object.defineProperty(exports, "CustomV1", { enumerable: true, get: function () { return documents_1.CustomV1; } });
6
6
  Object.defineProperty(exports, "FinancialDocumentV1", { enumerable: true, get: function () { return documents_1.FinancialDocumentV1; } });
@@ -9,6 +9,8 @@ Object.defineProperty(exports, "PassportV1", { enumerable: true, get: function (
9
9
  Object.defineProperty(exports, "ReceiptV3", { enumerable: true, get: function () { return documents_1.ReceiptV3; } });
10
10
  Object.defineProperty(exports, "ReceiptV4", { enumerable: true, get: function () { return documents_1.ReceiptV4; } });
11
11
  Object.defineProperty(exports, "CropperV1", { enumerable: true, get: function () { return documents_1.CropperV1; } });
12
+ Object.defineProperty(exports, "fr", { enumerable: true, get: function () { return documents_1.fr; } });
13
+ Object.defineProperty(exports, "us", { enumerable: true, get: function () { return documents_1.us; } });
12
14
  var client_1 = require("./client");
13
15
  Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } });
14
16
  var inputs_1 = require("./inputs");
@@ -8,6 +8,7 @@ export declare const INPUT_TYPE_BASE64 = "base64";
8
8
  export declare const INPUT_TYPE_BYTES = "bytes";
9
9
  export declare const INPUT_TYPE_PATH = "path";
10
10
  export declare const INPUT_TYPE_URL = "URL";
11
+ export declare const INPUT_TYPE_BUFFER = "buffer";
11
12
  export declare class InputSource {
12
13
  inputType: string;
13
14
  filename: string;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.InputSource = exports.INPUT_TYPE_URL = exports.INPUT_TYPE_PATH = exports.INPUT_TYPE_BYTES = exports.INPUT_TYPE_BASE64 = exports.INPUT_TYPE_STREAM = void 0;
26
+ exports.InputSource = exports.INPUT_TYPE_BUFFER = exports.INPUT_TYPE_URL = exports.INPUT_TYPE_PATH = exports.INPUT_TYPE_BYTES = exports.INPUT_TYPE_BASE64 = exports.INPUT_TYPE_STREAM = void 0;
27
27
  const fileType = __importStar(require("file-type"));
28
28
  const path = __importStar(require("path"));
29
29
  const pdf_1 = require("../pdf");
@@ -34,6 +34,7 @@ exports.INPUT_TYPE_BASE64 = "base64";
34
34
  exports.INPUT_TYPE_BYTES = "bytes";
35
35
  exports.INPUT_TYPE_PATH = "path";
36
36
  exports.INPUT_TYPE_URL = "URL";
37
+ exports.INPUT_TYPE_BUFFER = "buffer";
37
38
  const MIMETYPES = new Map([
38
39
  [".pdf", "application/pdf"],
39
40
  [".heic", "image/heic"],
@@ -50,6 +51,7 @@ const ALLOWED_INPUT_TYPES = [
50
51
  exports.INPUT_TYPE_BYTES,
51
52
  exports.INPUT_TYPE_PATH,
52
53
  exports.INPUT_TYPE_URL,
54
+ exports.INPUT_TYPE_BUFFER,
53
55
  ];
54
56
  class InputSource {
55
57
  /**
@@ -1,3 +1,3 @@
1
1
  export { PageOptions, PageOptionsOperation } from "./pageOptions";
2
- export { Base64Input, BytesInput, PathInput, StreamInput, UrlInput, } from "./sources";
3
- export { InputSource, INPUT_TYPE_BASE64, INPUT_TYPE_BYTES, INPUT_TYPE_PATH, INPUT_TYPE_STREAM, INPUT_TYPE_URL, } from "./base";
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_URL, INPUT_TYPE_BUFFER, } from "./base";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.INPUT_TYPE_URL = exports.INPUT_TYPE_STREAM = exports.INPUT_TYPE_PATH = exports.INPUT_TYPE_BYTES = exports.INPUT_TYPE_BASE64 = exports.InputSource = exports.UrlInput = exports.StreamInput = exports.PathInput = exports.BytesInput = exports.Base64Input = exports.PageOptionsOperation = void 0;
3
+ exports.INPUT_TYPE_BUFFER = exports.INPUT_TYPE_URL = 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;
4
4
  var pageOptions_1 = require("./pageOptions");
5
5
  Object.defineProperty(exports, "PageOptionsOperation", { enumerable: true, get: function () { return pageOptions_1.PageOptionsOperation; } });
6
6
  var sources_1 = require("./sources");
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "BytesInput", { enumerable: true, get: function (
9
9
  Object.defineProperty(exports, "PathInput", { enumerable: true, get: function () { return sources_1.PathInput; } });
10
10
  Object.defineProperty(exports, "StreamInput", { enumerable: true, get: function () { return sources_1.StreamInput; } });
11
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; } });
12
13
  var base_1 = require("./base");
13
14
  Object.defineProperty(exports, "InputSource", { enumerable: true, get: function () { return base_1.InputSource; } });
14
15
  Object.defineProperty(exports, "INPUT_TYPE_BASE64", { enumerable: true, get: function () { return base_1.INPUT_TYPE_BASE64; } });
@@ -16,3 +17,4 @@ Object.defineProperty(exports, "INPUT_TYPE_BYTES", { enumerable: true, get: func
16
17
  Object.defineProperty(exports, "INPUT_TYPE_PATH", { enumerable: true, get: function () { return base_1.INPUT_TYPE_PATH; } });
17
18
  Object.defineProperty(exports, "INPUT_TYPE_STREAM", { enumerable: true, get: function () { return base_1.INPUT_TYPE_STREAM; } });
18
19
  Object.defineProperty(exports, "INPUT_TYPE_URL", { enumerable: true, get: function () { return base_1.INPUT_TYPE_URL; } });
20
+ Object.defineProperty(exports, "INPUT_TYPE_BUFFER", { enumerable: true, get: function () { return base_1.INPUT_TYPE_BUFFER; } });
@@ -52,4 +52,12 @@ export declare class UrlInput extends InputSource {
52
52
  constructor({ url }: UrlInputProps);
53
53
  init(): Promise<void>;
54
54
  }
55
+ interface BufferInputProps {
56
+ buffer: Buffer;
57
+ filename: string;
58
+ }
59
+ export declare class BufferInput extends InputSource {
60
+ constructor({ buffer, filename }: BufferInputProps);
61
+ init(): Promise<void>;
62
+ }
55
63
  export {};
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.UrlInput = exports.BytesInput = exports.StreamInput = exports.Base64Input = exports.PathInput = void 0;
26
+ exports.BufferInput = exports.UrlInput = exports.BytesInput = exports.StreamInput = exports.Base64Input = exports.PathInput = void 0;
27
27
  const fs_1 = require("fs");
28
28
  const path = __importStar(require("path"));
29
29
  const handler_1 = require("../errors/handler");
@@ -115,7 +115,19 @@ class UrlInput extends base_1.InputSource {
115
115
  handler_1.errorHandler.throw(new Error("URL must be HTTPS"));
116
116
  }
117
117
  this.fileObject = this.url;
118
- this.filename = "hello.jpg";
119
118
  }
120
119
  }
121
120
  exports.UrlInput = UrlInput;
121
+ class BufferInput extends base_1.InputSource {
122
+ constructor({ buffer, filename }) {
123
+ super({
124
+ inputType: base_1.INPUT_TYPE_BUFFER,
125
+ });
126
+ this.fileObject = buffer;
127
+ this.filename = filename;
128
+ }
129
+ async init() {
130
+ this.mimeType = await this.checkMimetype();
131
+ }
132
+ }
133
+ exports.BufferInput = BufferInput;