mindee 3.0.1 → 3.1.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.
- package/CHANGELOG.md +5 -0
- package/README.md +3 -3
- package/package.json +1 -1
- package/src/cli.js +12 -0
- package/src/client.d.ts +7 -0
- package/src/client.js +15 -0
- package/src/documents/fr/idCard/idCardV1.d.ts +15 -1
- package/src/documents/fr/idCard/idCardV1.js +71 -0
- package/src/documents/index.d.ts +3 -1
- package/src/documents/index.js +4 -1
- package/src/fields/field.d.ts +1 -1
- package/src/fields/field.js +10 -7
- package/src/index.d.ts +1 -1
- package/src/index.js +2 -1
- package/src/inputs/base.d.ts +1 -0
- package/src/inputs/base.js +3 -1
- package/src/inputs/index.d.ts +2 -2
- package/src/inputs/index.js +3 -1
- package/src/inputs/sources.d.ts +8 -0
- package/src/inputs/sources.js +14 -2
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ const mindee = require("mindee");
|
|
|
21
21
|
// import * as mindee from "mindee";
|
|
22
22
|
|
|
23
23
|
// Init a new client
|
|
24
|
-
const mindeeClient = new mindee.Client({apiKey: "my-api-key"});
|
|
24
|
+
const mindeeClient = new mindee.Client({ apiKey: "my-api-key" });
|
|
25
25
|
|
|
26
26
|
// Load a file from disk and parse it
|
|
27
27
|
const invoiceResponse = mindeeClient
|
|
@@ -54,7 +54,7 @@ const mindee = require("mindee");
|
|
|
54
54
|
// import * as mindee from "mindee";
|
|
55
55
|
|
|
56
56
|
// Init a new client and add your document endpoint
|
|
57
|
-
const mindeeClient = new mindee.Client({apiKey: "my-api-key"})
|
|
57
|
+
const mindeeClient = new mindee.Client({ apiKey: "my-api-key" })
|
|
58
58
|
.addEndpoint({
|
|
59
59
|
accountName: "john",
|
|
60
60
|
endpointName: "wsnine",
|
|
@@ -83,7 +83,7 @@ There's more to it than that for those that need more features, or want to
|
|
|
83
83
|
customize the experience.
|
|
84
84
|
|
|
85
85
|
All the juicy details are described in the
|
|
86
|
-
**[Official
|
|
86
|
+
**[Official Guide](https://developers.mindee.com/docs/nodejs-sdk)**.
|
|
87
87
|
|
|
88
88
|
## License
|
|
89
89
|
Copyright © Mindee
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -10,6 +10,7 @@ const COMMAND_INVOICE = "invoice";
|
|
|
10
10
|
const COMMAND_RECEIPT = "receipt";
|
|
11
11
|
const COMMAND_PASSPORT = "passport";
|
|
12
12
|
const COMMAND_FINANCIAL = "financial";
|
|
13
|
+
const COMMAND_FR_ID_CARD = "fr-id-card";
|
|
13
14
|
const COMMAND_CUSTOM = "custom";
|
|
14
15
|
const CLI_COMMAND_CONFIG = new Map([
|
|
15
16
|
[
|
|
@@ -44,6 +45,14 @@ const CLI_COMMAND_CONFIG = new Map([
|
|
|
44
45
|
fullText: true,
|
|
45
46
|
},
|
|
46
47
|
],
|
|
48
|
+
[
|
|
49
|
+
COMMAND_FR_ID_CARD,
|
|
50
|
+
{
|
|
51
|
+
description: "FR ID Card V1",
|
|
52
|
+
docType: documents_1.DOC_TYPE_IDCARD_V1,
|
|
53
|
+
fullText: false,
|
|
54
|
+
},
|
|
55
|
+
],
|
|
47
56
|
[
|
|
48
57
|
COMMAND_CUSTOM,
|
|
49
58
|
{
|
|
@@ -95,6 +104,9 @@ async function predictCall(command, inputPath, options) {
|
|
|
95
104
|
case COMMAND_PASSPORT:
|
|
96
105
|
response = await doc.parse(documents_1.PassportV1, predictParams);
|
|
97
106
|
break;
|
|
107
|
+
case COMMAND_FR_ID_CARD:
|
|
108
|
+
response = await doc.parse(documents_1.IdCardV1, predictParams);
|
|
109
|
+
break;
|
|
98
110
|
case COMMAND_CUSTOM:
|
|
99
111
|
response = await doc.parse(documents_1.CustomV1, predictParams);
|
|
100
112
|
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.IdCardV1.name], new documentConfig_1.DocumentConfig(documents_1.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;
|
package/src/documents/index.d.ts
CHANGED
|
@@ -5,8 +5,9 @@ import { PassportV1 } from "./passport/passportV1";
|
|
|
5
5
|
import { FinancialDocumentV1 } from "./financialDocument/financialDocumentV1";
|
|
6
6
|
import { CustomV1 } from "./custom";
|
|
7
7
|
import { CropperV1 } from "./cropper/cropperV1";
|
|
8
|
+
import { IdCardV1 } from "./fr/idCard/idCardV1";
|
|
8
9
|
export { Document, DocumentConstructorProps, DocumentSig } from "./document";
|
|
9
|
-
export { ReceiptV3, ReceiptV4, InvoiceV3, FinancialDocumentV1, PassportV1, CustomV1, CropperV1, };
|
|
10
|
+
export { ReceiptV3, ReceiptV4, InvoiceV3, FinancialDocumentV1, PassportV1, CustomV1, CropperV1, IdCardV1, };
|
|
10
11
|
export declare const DOC_TYPE_CUSTOM: string;
|
|
11
12
|
export declare const DOC_TYPE_INVOICE_V3: string;
|
|
12
13
|
export declare const DOC_TYPE_RECEIPT_V3: string;
|
|
@@ -14,3 +15,4 @@ export declare const DOC_TYPE_RECEIPT_V4: string;
|
|
|
14
15
|
export declare const DOC_TYPE_PASSPORT_V1: string;
|
|
15
16
|
export declare const DOC_TYPE_FINANCIAL_V1: string;
|
|
16
17
|
export declare const DOC_TYPE_CROPPER_V1: string;
|
|
18
|
+
export declare const DOC_TYPE_IDCARD_V1: string;
|
package/src/documents/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
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;
|
|
3
|
+
exports.DOC_TYPE_IDCARD_V1 = 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.IdCardV1 = exports.CropperV1 = exports.CustomV1 = exports.PassportV1 = exports.FinancialDocumentV1 = exports.InvoiceV3 = exports.ReceiptV4 = exports.ReceiptV3 = exports.Document = void 0;
|
|
4
4
|
const invoiceV3_1 = require("./invoice/invoiceV3");
|
|
5
5
|
Object.defineProperty(exports, "InvoiceV3", { enumerable: true, get: function () { return invoiceV3_1.InvoiceV3; } });
|
|
6
6
|
const receiptV3_1 = require("./receipt/receiptV3");
|
|
@@ -15,6 +15,8 @@ const custom_1 = require("./custom");
|
|
|
15
15
|
Object.defineProperty(exports, "CustomV1", { enumerable: true, get: function () { return custom_1.CustomV1; } });
|
|
16
16
|
const cropperV1_1 = require("./cropper/cropperV1");
|
|
17
17
|
Object.defineProperty(exports, "CropperV1", { enumerable: true, get: function () { return cropperV1_1.CropperV1; } });
|
|
18
|
+
const idCardV1_1 = require("./fr/idCard/idCardV1");
|
|
19
|
+
Object.defineProperty(exports, "IdCardV1", { enumerable: true, get: function () { return idCardV1_1.IdCardV1; } });
|
|
18
20
|
var document_1 = require("./document");
|
|
19
21
|
Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return document_1.Document; } });
|
|
20
22
|
exports.DOC_TYPE_CUSTOM = custom_1.CustomV1.name;
|
|
@@ -24,3 +26,4 @@ exports.DOC_TYPE_RECEIPT_V4 = receiptV4_1.ReceiptV4.name;
|
|
|
24
26
|
exports.DOC_TYPE_PASSPORT_V1 = passportV1_1.PassportV1.name;
|
|
25
27
|
exports.DOC_TYPE_FINANCIAL_V1 = financialDocumentV1_1.FinancialDocumentV1.name;
|
|
26
28
|
exports.DOC_TYPE_CROPPER_V1 = cropperV1_1.CropperV1.name;
|
|
29
|
+
exports.DOC_TYPE_IDCARD_V1 = idCardV1_1.IdCardV1.name;
|
package/src/fields/field.d.ts
CHANGED
|
@@ -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
|
}
|
package/src/fields/field.js
CHANGED
|
@@ -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 (
|
|
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, IdCardV1, } 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.IdCardV1 = 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,7 @@ 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, "IdCardV1", { enumerable: true, get: function () { return documents_1.IdCardV1; } });
|
|
12
13
|
var client_1 = require("./client");
|
|
13
14
|
Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } });
|
|
14
15
|
var inputs_1 = require("./inputs");
|
package/src/inputs/base.d.ts
CHANGED
|
@@ -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;
|
package/src/inputs/base.js
CHANGED
|
@@ -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
|
/**
|
package/src/inputs/index.d.ts
CHANGED
|
@@ -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";
|
package/src/inputs/index.js
CHANGED
|
@@ -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; } });
|
package/src/inputs/sources.d.ts
CHANGED
|
@@ -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 {};
|
package/src/inputs/sources.js
CHANGED
|
@@ -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;
|