mindee 4.20.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.
- package/CHANGELOG.md +8 -0
- package/README.md +25 -11
- package/package.json +1 -1
- package/src/client.d.ts +3 -3
- package/src/client.js +2 -2
- package/src/http/baseEndpoint.js +2 -2
- package/src/http/endpoint.js +2 -2
- package/src/http/workflowEndpoint.js +2 -2
- package/src/imageOperations/invoiceSplitterExtractor/invoiceSplitterExtractor.d.ts +1 -1
- package/src/imageOperations/multiReceiptsExtractor/multiReceiptsExtractor.d.ts +1 -1
- package/src/input/index.d.ts +1 -2
- package/src/input/index.js +16 -15
- package/src/input/sources/base64Input.d.ts +12 -0
- package/src/input/sources/base64Input.js +22 -0
- package/src/input/sources/bufferInput.d.ts +10 -0
- package/src/input/sources/bufferInput.js +18 -0
- package/src/input/sources/bytesInput.d.ts +12 -0
- package/src/input/sources/bytesInput.js +21 -0
- package/src/input/sources/index.d.ts +8 -0
- package/src/input/sources/index.js +24 -0
- package/src/input/sources/inputSource.d.ts +16 -0
- package/src/input/sources/inputSource.js +17 -0
- package/src/input/sources/localInputSource.d.ts +20 -0
- package/src/input/{base.js → sources/localInputSource.js} +16 -26
- package/src/input/sources/pathInput.d.ts +11 -0
- package/src/input/sources/pathInput.js +27 -0
- package/src/input/sources/streamInput.d.ts +14 -0
- package/src/input/sources/streamInput.js +28 -0
- package/src/input/sources/urlInput.d.ts +32 -0
- package/src/input/sources/urlInput.js +98 -0
- package/src/product/fr/index.d.ts +0 -1
- package/src/product/fr/index.js +1 -3
- package/src/product/fr/internal.d.ts +0 -1
- package/src/product/fr/internal.js +1 -2
- package/src/input/base.d.ts +0 -36
- package/src/input/sources.d.ts +0 -59
- package/src/input/sources.js +0 -133
- package/src/product/fr/carteVitale/carteVitaleV1.d.ts +0 -16
- package/src/product/fr/carteVitale/carteVitaleV1.js +0 -27
- package/src/product/fr/carteVitale/carteVitaleV1Document.d.ts +0 -20
- package/src/product/fr/carteVitale/carteVitaleV1Document.js +0 -43
- package/src/product/fr/carteVitale/index.d.ts +0 -1
- package/src/product/fr/carteVitale/index.js +0 -5
- package/src/product/fr/carteVitale/internal.d.ts +0 -2
- package/src/product/fr/carteVitale/internal.js +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
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
|
+
|
|
3
11
|
## v4.20.0 - 2024-11-28
|
|
4
12
|
### Changes
|
|
5
13
|
* :sparkles: add support for French Health Card 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
|
|
38
|
+
A base64 encoded string:
|
|
39
39
|
```js
|
|
40
|
-
const inputSource = mindeeClient.
|
|
40
|
+
const inputSource = mindeeClient.docFromBase64(myInputString, "my-file-name.ext")
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
A
|
|
43
|
+
A byte sequence:
|
|
44
44
|
```js
|
|
45
|
-
const inputSource = mindeeClient.
|
|
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 (
|
|
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
|
-
.
|
|
102
|
-
mindee.product.
|
|
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
|
|
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
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
|
|
225
|
-
* @param inputBytes input content, as
|
|
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:
|
|
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
|
|
304
|
-
* @param inputBytes input content, as
|
|
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) {
|
package/src/http/baseEndpoint.js
CHANGED
|
@@ -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
|
|
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
|
|
21
|
+
if (inputDoc instanceof input_1.LocalInputSource && inputDoc.isPdf()) {
|
|
22
22
|
await inputDoc.cutPdf(pageOptions);
|
|
23
23
|
}
|
|
24
24
|
}
|
package/src/http/endpoint.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
3
|
+
import { LocalInputSource } from "../../input";
|
|
4
4
|
/**
|
|
5
5
|
* Extracts individual receipts from multi-receipts documents.
|
|
6
6
|
*
|
package/src/input/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export { PageOptions, PageOptionsOperation } from "./pageOptions";
|
|
2
|
-
export
|
|
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";
|
package/src/input/index.js
CHANGED
|
@@ -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.
|
|
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
|
-
|
|
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 =
|
|
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
|
|
29
|
-
const
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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 =
|
|
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 {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StreamInput = void 0;
|
|
4
|
+
const localInputSource_1 = require("./localInputSource");
|
|
5
|
+
const inputSource_1 = require("./inputSource");
|
|
6
|
+
class StreamInput extends localInputSource_1.LocalInputSource {
|
|
7
|
+
constructor({ inputStream, filename }) {
|
|
8
|
+
super({
|
|
9
|
+
inputType: inputSource_1.INPUT_TYPE_STREAM,
|
|
10
|
+
});
|
|
11
|
+
this.fileObject = Buffer.alloc(0);
|
|
12
|
+
this.filename = filename;
|
|
13
|
+
this.inputStream = inputStream;
|
|
14
|
+
}
|
|
15
|
+
async init() {
|
|
16
|
+
this.fileObject = await this.stream2buffer(this.inputStream);
|
|
17
|
+
this.mimeType = await this.checkMimetype();
|
|
18
|
+
}
|
|
19
|
+
async stream2buffer(stream) {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
const _buf = Array();
|
|
22
|
+
stream.on("data", (chunk) => _buf.push(chunk));
|
|
23
|
+
stream.on("end", () => resolve(Buffer.concat(_buf)));
|
|
24
|
+
stream.on("error", (err) => reject(`Error converting stream - ${err}`));
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.StreamInput = StreamInput;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { InputSource } from "./inputSource";
|
|
2
|
+
import { BytesInput } from "./bytesInput";
|
|
3
|
+
export declare class UrlInput extends InputSource {
|
|
4
|
+
private readonly url;
|
|
5
|
+
constructor({ url }: {
|
|
6
|
+
url: string;
|
|
7
|
+
});
|
|
8
|
+
init(): Promise<void>;
|
|
9
|
+
private fetchFileContent;
|
|
10
|
+
saveToFile(options: {
|
|
11
|
+
filepath: string;
|
|
12
|
+
filename?: string;
|
|
13
|
+
username?: string;
|
|
14
|
+
password?: string;
|
|
15
|
+
token?: string;
|
|
16
|
+
headers?: Record<string, string>;
|
|
17
|
+
maxRedirects?: number;
|
|
18
|
+
}): Promise<string>;
|
|
19
|
+
asLocalInputSource(options?: {
|
|
20
|
+
filename?: string;
|
|
21
|
+
username?: string;
|
|
22
|
+
password?: string;
|
|
23
|
+
token?: string;
|
|
24
|
+
headers?: Record<string, string>;
|
|
25
|
+
maxRedirects?: number;
|
|
26
|
+
}): Promise<BytesInput>;
|
|
27
|
+
private static extractFilenameFromUrl;
|
|
28
|
+
private static generateFileName;
|
|
29
|
+
private static getFileExtension;
|
|
30
|
+
private fillFilename;
|
|
31
|
+
private makeRequest;
|
|
32
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UrlInput = void 0;
|
|
4
|
+
const inputSource_1 = require("./inputSource");
|
|
5
|
+
const url_1 = require("url");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const crypto_1 = require("crypto");
|
|
8
|
+
const promises_1 = require("fs/promises");
|
|
9
|
+
const https_1 = require("https");
|
|
10
|
+
const bytesInput_1 = require("./bytesInput");
|
|
11
|
+
class UrlInput extends inputSource_1.InputSource {
|
|
12
|
+
constructor({ url }) {
|
|
13
|
+
super();
|
|
14
|
+
this.url = url;
|
|
15
|
+
}
|
|
16
|
+
async init() {
|
|
17
|
+
if (!this.url.toLowerCase().startsWith("https")) {
|
|
18
|
+
throw new Error("URL must be HTTPS");
|
|
19
|
+
}
|
|
20
|
+
this.fileObject = this.url;
|
|
21
|
+
}
|
|
22
|
+
async fetchFileContent(options) {
|
|
23
|
+
const { username, password, token, headers = {}, maxRedirects = 3 } = options;
|
|
24
|
+
if (token) {
|
|
25
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
26
|
+
}
|
|
27
|
+
const auth = username && password ? `${username}:${password}` : undefined;
|
|
28
|
+
return await this.makeRequest(this.url, auth, headers, 0, maxRedirects);
|
|
29
|
+
}
|
|
30
|
+
async saveToFile(options) {
|
|
31
|
+
const { filepath, filename, ...fetchOptions } = options;
|
|
32
|
+
const { content, finalUrl } = await this.fetchFileContent(fetchOptions);
|
|
33
|
+
const finalFilename = this.fillFilename(filename, finalUrl);
|
|
34
|
+
const fullPath = `${filepath}/${finalFilename}`;
|
|
35
|
+
await (0, promises_1.writeFile)(fullPath, content);
|
|
36
|
+
return fullPath;
|
|
37
|
+
}
|
|
38
|
+
async asLocalInputSource(options = {}) {
|
|
39
|
+
const { filename, ...fetchOptions } = options;
|
|
40
|
+
const { content, finalUrl } = await this.fetchFileContent(fetchOptions);
|
|
41
|
+
const finalFilename = this.fillFilename(filename, finalUrl);
|
|
42
|
+
return new bytesInput_1.BytesInput({ inputBytes: content, filename: finalFilename });
|
|
43
|
+
}
|
|
44
|
+
static extractFilenameFromUrl(uri) {
|
|
45
|
+
return (0, path_1.basename)(new url_1.URL(uri).pathname || "");
|
|
46
|
+
}
|
|
47
|
+
static generateFileName(extension = ".tmp") {
|
|
48
|
+
const randomString = (0, crypto_1.randomBytes)(4).toString("hex");
|
|
49
|
+
const timestamp = new Date().toISOString().replace(/[-:]/g, "").split(".")[0];
|
|
50
|
+
return `mindee_temp_${timestamp}_${randomString}${extension}`;
|
|
51
|
+
}
|
|
52
|
+
static getFileExtension(filename) {
|
|
53
|
+
const ext = (0, path_1.extname)(filename);
|
|
54
|
+
return ext ? ext.toLowerCase() : null;
|
|
55
|
+
}
|
|
56
|
+
fillFilename(filename, finalUrl) {
|
|
57
|
+
if (!filename) {
|
|
58
|
+
filename = finalUrl ? UrlInput.extractFilenameFromUrl(finalUrl) : UrlInput.extractFilenameFromUrl(this.url);
|
|
59
|
+
}
|
|
60
|
+
if (!filename || !(0, path_1.extname)(filename)) {
|
|
61
|
+
filename = UrlInput.generateFileName(UrlInput.getFileExtension(filename || "") || undefined);
|
|
62
|
+
}
|
|
63
|
+
return filename;
|
|
64
|
+
}
|
|
65
|
+
async makeRequest(url, auth, headers, redirects, maxRedirects) {
|
|
66
|
+
const parsedUrl = new url_1.URL(url);
|
|
67
|
+
const options = {
|
|
68
|
+
hostname: parsedUrl.hostname,
|
|
69
|
+
path: parsedUrl.pathname + parsedUrl.search,
|
|
70
|
+
method: "GET",
|
|
71
|
+
headers: headers,
|
|
72
|
+
auth: auth,
|
|
73
|
+
};
|
|
74
|
+
const response = await new Promise((resolve, reject) => {
|
|
75
|
+
const req = (0, https_1.request)(options, resolve);
|
|
76
|
+
req.on("error", reject);
|
|
77
|
+
req.end();
|
|
78
|
+
});
|
|
79
|
+
if (response.statusCode && response.statusCode >= 300 && response.statusCode < 400) {
|
|
80
|
+
if (redirects === maxRedirects) {
|
|
81
|
+
throw new Error(`Can't reach URL after ${redirects} out of ${maxRedirects} redirects, aborting operation.`);
|
|
82
|
+
}
|
|
83
|
+
if (response.headers.location) {
|
|
84
|
+
return await this.makeRequest(response.headers.location, auth, headers, redirects + 1, maxRedirects);
|
|
85
|
+
}
|
|
86
|
+
throw new Error("Redirect location not found");
|
|
87
|
+
}
|
|
88
|
+
if (!response.statusCode || response.statusCode >= 400 || response.statusCode < 200) {
|
|
89
|
+
throw new Error(`Couldn't retrieve file from server, error code ${response.statusCode}.`);
|
|
90
|
+
}
|
|
91
|
+
const chunks = [];
|
|
92
|
+
for await (const chunk of response) {
|
|
93
|
+
chunks.push(chunk);
|
|
94
|
+
}
|
|
95
|
+
return { content: Buffer.concat(chunks), finalUrl: url };
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.UrlInput = UrlInput;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { BankAccountDetailsV1 } from "./bankAccountDetails/bankAccountDetailsV1";
|
|
2
2
|
export { BankAccountDetailsV2 } from "./bankAccountDetails/bankAccountDetailsV2";
|
|
3
3
|
export { CarteGriseV1 } from "./carteGrise/carteGriseV1";
|
|
4
|
-
export { CarteVitaleV1 } from "./carteVitale/carteVitaleV1";
|
|
5
4
|
export { EnergyBillV1 } from "./energyBill/energyBillV1";
|
|
6
5
|
export { HealthCardV1 } from "./healthCard/healthCardV1";
|
|
7
6
|
export { IdCardV1 } from "./idCard/idCardV1";
|
package/src/product/fr/index.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PayslipV3 = exports.PayslipV2 = exports.IdCardV2 = exports.IdCardV1 = exports.HealthCardV1 = exports.EnergyBillV1 = exports.
|
|
3
|
+
exports.PayslipV3 = exports.PayslipV2 = exports.IdCardV2 = exports.IdCardV1 = exports.HealthCardV1 = exports.EnergyBillV1 = exports.CarteGriseV1 = exports.BankAccountDetailsV2 = exports.BankAccountDetailsV1 = void 0;
|
|
4
4
|
var bankAccountDetailsV1_1 = require("./bankAccountDetails/bankAccountDetailsV1");
|
|
5
5
|
Object.defineProperty(exports, "BankAccountDetailsV1", { enumerable: true, get: function () { return bankAccountDetailsV1_1.BankAccountDetailsV1; } });
|
|
6
6
|
var bankAccountDetailsV2_1 = require("./bankAccountDetails/bankAccountDetailsV2");
|
|
7
7
|
Object.defineProperty(exports, "BankAccountDetailsV2", { enumerable: true, get: function () { return bankAccountDetailsV2_1.BankAccountDetailsV2; } });
|
|
8
8
|
var carteGriseV1_1 = require("./carteGrise/carteGriseV1");
|
|
9
9
|
Object.defineProperty(exports, "CarteGriseV1", { enumerable: true, get: function () { return carteGriseV1_1.CarteGriseV1; } });
|
|
10
|
-
var carteVitaleV1_1 = require("./carteVitale/carteVitaleV1");
|
|
11
|
-
Object.defineProperty(exports, "CarteVitaleV1", { enumerable: true, get: function () { return carteVitaleV1_1.CarteVitaleV1; } });
|
|
12
10
|
var energyBillV1_1 = require("./energyBill/energyBillV1");
|
|
13
11
|
Object.defineProperty(exports, "EnergyBillV1", { enumerable: true, get: function () { return energyBillV1_1.EnergyBillV1; } });
|
|
14
12
|
var healthCardV1_1 = require("./healthCard/healthCardV1");
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export * as bankAccountDetails from "./bankAccountDetails/internal";
|
|
2
2
|
export * as carteGrise from "./carteGrise/internal";
|
|
3
|
-
export * as carteVitale from "./carteVitale/internal";
|
|
4
3
|
export * as energyBill from "./energyBill/internal";
|
|
5
4
|
export * as fr from "./healthCard/internal";
|
|
6
5
|
export * as idCard from "./idCard/internal";
|
|
@@ -23,10 +23,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.payslip = exports.idCard = exports.fr = exports.energyBill = exports.
|
|
26
|
+
exports.payslip = exports.idCard = exports.fr = exports.energyBill = exports.carteGrise = exports.bankAccountDetails = void 0;
|
|
27
27
|
exports.bankAccountDetails = __importStar(require("./bankAccountDetails/internal"));
|
|
28
28
|
exports.carteGrise = __importStar(require("./carteGrise/internal"));
|
|
29
|
-
exports.carteVitale = __importStar(require("./carteVitale/internal"));
|
|
30
29
|
exports.energyBill = __importStar(require("./energyBill/internal"));
|
|
31
30
|
exports.fr = __importStar(require("./healthCard/internal"));
|
|
32
31
|
exports.idCard = __importStar(require("./idCard/internal"));
|
package/src/input/base.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { PageOptions } from "./pageOptions";
|
|
2
|
-
/**
|
|
3
|
-
* @param {string} inputType - the type of input used in file ("base64", "path", "dummy").
|
|
4
|
-
* NB: dummy is only used for tests purposes
|
|
5
|
-
*/
|
|
6
|
-
interface InputConstructor {
|
|
7
|
-
inputType: string;
|
|
8
|
-
}
|
|
9
|
-
export declare const INPUT_TYPE_STREAM = "stream";
|
|
10
|
-
export declare const INPUT_TYPE_BASE64 = "base64";
|
|
11
|
-
export declare const INPUT_TYPE_BYTES = "bytes";
|
|
12
|
-
export declare const INPUT_TYPE_PATH = "path";
|
|
13
|
-
export declare const INPUT_TYPE_BUFFER = "buffer";
|
|
14
|
-
export declare abstract class InputSource {
|
|
15
|
-
fileObject: Buffer | string;
|
|
16
|
-
init(): Promise<void>;
|
|
17
|
-
}
|
|
18
|
-
export declare abstract class LocalInputSource extends InputSource {
|
|
19
|
-
inputType: string;
|
|
20
|
-
filename: string;
|
|
21
|
-
filepath?: string;
|
|
22
|
-
mimeType: string;
|
|
23
|
-
fileObject: Buffer | string;
|
|
24
|
-
/**
|
|
25
|
-
* @param {InputConstructor} constructor Constructor parameters.
|
|
26
|
-
*/
|
|
27
|
-
protected constructor({ inputType }: InputConstructor);
|
|
28
|
-
isPdf(): boolean;
|
|
29
|
-
checkMimetype(): Promise<string>;
|
|
30
|
-
/**
|
|
31
|
-
* Cut PDF pages.
|
|
32
|
-
* @param pageOptions
|
|
33
|
-
*/
|
|
34
|
-
cutPdf(pageOptions: PageOptions): Promise<void>;
|
|
35
|
-
}
|
|
36
|
-
export {};
|
package/src/input/sources.d.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { Readable } from "stream";
|
|
2
|
-
import { Buffer } from "buffer";
|
|
3
|
-
import { LocalInputSource, InputSource } from "./base";
|
|
4
|
-
interface PathInputProps {
|
|
5
|
-
inputPath: string;
|
|
6
|
-
}
|
|
7
|
-
export declare class PathInput extends LocalInputSource {
|
|
8
|
-
readonly inputPath: string;
|
|
9
|
-
fileObject: Buffer;
|
|
10
|
-
constructor({ inputPath }: PathInputProps);
|
|
11
|
-
init(): Promise<void>;
|
|
12
|
-
}
|
|
13
|
-
interface Base64InputProps {
|
|
14
|
-
inputString: string;
|
|
15
|
-
filename: string;
|
|
16
|
-
}
|
|
17
|
-
export declare class Base64Input extends LocalInputSource {
|
|
18
|
-
private inputString;
|
|
19
|
-
fileObject: Buffer;
|
|
20
|
-
constructor({ inputString, filename }: Base64InputProps);
|
|
21
|
-
init(): Promise<void>;
|
|
22
|
-
}
|
|
23
|
-
interface StreamInputProps {
|
|
24
|
-
inputStream: Readable;
|
|
25
|
-
filename: string;
|
|
26
|
-
}
|
|
27
|
-
export declare class StreamInput extends LocalInputSource {
|
|
28
|
-
private readonly inputStream;
|
|
29
|
-
fileObject: Buffer;
|
|
30
|
-
constructor({ inputStream, filename }: StreamInputProps);
|
|
31
|
-
init(): Promise<void>;
|
|
32
|
-
stream2buffer(stream: Readable): Promise<Buffer>;
|
|
33
|
-
}
|
|
34
|
-
interface BytesInputProps {
|
|
35
|
-
inputBytes: string;
|
|
36
|
-
filename: string;
|
|
37
|
-
}
|
|
38
|
-
export declare class BytesInput extends LocalInputSource {
|
|
39
|
-
private inputBytes;
|
|
40
|
-
fileObject: Buffer;
|
|
41
|
-
constructor({ inputBytes, filename }: BytesInputProps);
|
|
42
|
-
init(): Promise<void>;
|
|
43
|
-
}
|
|
44
|
-
export declare class UrlInput extends InputSource {
|
|
45
|
-
private readonly url;
|
|
46
|
-
constructor({ url }: {
|
|
47
|
-
url: string;
|
|
48
|
-
});
|
|
49
|
-
init(): Promise<void>;
|
|
50
|
-
}
|
|
51
|
-
interface BufferInputProps {
|
|
52
|
-
buffer: Buffer;
|
|
53
|
-
filename: string;
|
|
54
|
-
}
|
|
55
|
-
export declare class BufferInput extends LocalInputSource {
|
|
56
|
-
constructor({ buffer, filename }: BufferInputProps);
|
|
57
|
-
init(): Promise<void>;
|
|
58
|
-
}
|
|
59
|
-
export {};
|
package/src/input/sources.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
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
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.BufferInput = exports.UrlInput = exports.BytesInput = exports.StreamInput = exports.Base64Input = exports.PathInput = void 0;
|
|
27
|
-
const fs_1 = require("fs");
|
|
28
|
-
const path = __importStar(require("path"));
|
|
29
|
-
const buffer_1 = require("buffer");
|
|
30
|
-
const logger_1 = require("../logger");
|
|
31
|
-
const base_1 = require("./base");
|
|
32
|
-
class PathInput extends base_1.LocalInputSource {
|
|
33
|
-
constructor({ inputPath }) {
|
|
34
|
-
super({
|
|
35
|
-
inputType: base_1.INPUT_TYPE_PATH,
|
|
36
|
-
});
|
|
37
|
-
this.fileObject = buffer_1.Buffer.alloc(0);
|
|
38
|
-
this.inputPath = inputPath;
|
|
39
|
-
this.filename = path.basename(this.inputPath);
|
|
40
|
-
}
|
|
41
|
-
async init() {
|
|
42
|
-
logger_1.logger.debug(`Loading from: ${this.inputPath}`);
|
|
43
|
-
this.fileObject = buffer_1.Buffer.from(await fs_1.promises.readFile(this.inputPath));
|
|
44
|
-
this.mimeType = await this.checkMimetype();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.PathInput = PathInput;
|
|
48
|
-
class Base64Input extends base_1.LocalInputSource {
|
|
49
|
-
constructor({ inputString, filename }) {
|
|
50
|
-
super({
|
|
51
|
-
inputType: base_1.INPUT_TYPE_BASE64,
|
|
52
|
-
});
|
|
53
|
-
this.fileObject = buffer_1.Buffer.alloc(0);
|
|
54
|
-
this.filename = filename;
|
|
55
|
-
this.inputString = inputString;
|
|
56
|
-
}
|
|
57
|
-
async init() {
|
|
58
|
-
this.fileObject = buffer_1.Buffer.from(this.inputString, "base64");
|
|
59
|
-
this.mimeType = await this.checkMimetype();
|
|
60
|
-
// clear out the string
|
|
61
|
-
this.inputString = "";
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
exports.Base64Input = Base64Input;
|
|
65
|
-
class StreamInput extends base_1.LocalInputSource {
|
|
66
|
-
constructor({ inputStream, filename }) {
|
|
67
|
-
super({
|
|
68
|
-
inputType: base_1.INPUT_TYPE_STREAM,
|
|
69
|
-
});
|
|
70
|
-
this.fileObject = buffer_1.Buffer.alloc(0);
|
|
71
|
-
this.filename = filename;
|
|
72
|
-
this.inputStream = inputStream;
|
|
73
|
-
}
|
|
74
|
-
async init() {
|
|
75
|
-
this.fileObject = await this.stream2buffer(this.inputStream);
|
|
76
|
-
this.mimeType = await this.checkMimetype();
|
|
77
|
-
}
|
|
78
|
-
async stream2buffer(stream) {
|
|
79
|
-
return new Promise((resolve, reject) => {
|
|
80
|
-
const _buf = Array();
|
|
81
|
-
stream.on("data", (chunk) => _buf.push(chunk));
|
|
82
|
-
stream.on("end", () => resolve(buffer_1.Buffer.concat(_buf)));
|
|
83
|
-
stream.on("error", (err) => reject(`Error converting stream - ${err}`));
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
exports.StreamInput = StreamInput;
|
|
88
|
-
class BytesInput extends base_1.LocalInputSource {
|
|
89
|
-
constructor({ inputBytes, filename }) {
|
|
90
|
-
super({
|
|
91
|
-
inputType: base_1.INPUT_TYPE_BYTES,
|
|
92
|
-
});
|
|
93
|
-
this.fileObject = buffer_1.Buffer.alloc(0);
|
|
94
|
-
this.filename = filename;
|
|
95
|
-
this.inputBytes = inputBytes;
|
|
96
|
-
}
|
|
97
|
-
async init() {
|
|
98
|
-
this.fileObject = buffer_1.Buffer.from(this.inputBytes, "hex");
|
|
99
|
-
this.mimeType = await this.checkMimetype();
|
|
100
|
-
// clear out the string
|
|
101
|
-
this.inputBytes = "";
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
exports.BytesInput = BytesInput;
|
|
105
|
-
//
|
|
106
|
-
// URL
|
|
107
|
-
//
|
|
108
|
-
class UrlInput extends base_1.InputSource {
|
|
109
|
-
constructor({ url }) {
|
|
110
|
-
super();
|
|
111
|
-
this.url = url;
|
|
112
|
-
}
|
|
113
|
-
async init() {
|
|
114
|
-
if (!this.url.toLowerCase().startsWith("https")) {
|
|
115
|
-
throw new Error("URL must be HTTPS");
|
|
116
|
-
}
|
|
117
|
-
this.fileObject = this.url;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
exports.UrlInput = UrlInput;
|
|
121
|
-
class BufferInput extends base_1.LocalInputSource {
|
|
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;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Inference, StringDict, Page } from "../../../parsing/common";
|
|
2
|
-
import { CarteVitaleV1Document } from "./carteVitaleV1Document";
|
|
3
|
-
/**
|
|
4
|
-
* Carte Vitale API version 1 inference prediction.
|
|
5
|
-
*/
|
|
6
|
-
export declare class CarteVitaleV1 extends Inference {
|
|
7
|
-
/** The endpoint's name. */
|
|
8
|
-
endpointName: string;
|
|
9
|
-
/** The endpoint's version. */
|
|
10
|
-
endpointVersion: string;
|
|
11
|
-
/** The document-level prediction. */
|
|
12
|
-
prediction: CarteVitaleV1Document;
|
|
13
|
-
/** The document's pages. */
|
|
14
|
-
pages: Page<CarteVitaleV1Document>[];
|
|
15
|
-
constructor(rawPrediction: StringDict);
|
|
16
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CarteVitaleV1 = void 0;
|
|
4
|
-
const common_1 = require("../../../parsing/common");
|
|
5
|
-
const carteVitaleV1Document_1 = require("./carteVitaleV1Document");
|
|
6
|
-
/**
|
|
7
|
-
* Carte Vitale API version 1 inference prediction.
|
|
8
|
-
*/
|
|
9
|
-
class CarteVitaleV1 extends common_1.Inference {
|
|
10
|
-
constructor(rawPrediction) {
|
|
11
|
-
super(rawPrediction);
|
|
12
|
-
/** The endpoint's name. */
|
|
13
|
-
this.endpointName = "carte_vitale";
|
|
14
|
-
/** The endpoint's version. */
|
|
15
|
-
this.endpointVersion = "1";
|
|
16
|
-
/** The document's pages. */
|
|
17
|
-
this.pages = [];
|
|
18
|
-
this.prediction = new carteVitaleV1Document_1.CarteVitaleV1Document(rawPrediction["prediction"]);
|
|
19
|
-
rawPrediction["pages"].forEach((page) => {
|
|
20
|
-
if (page.prediction !== undefined && page.prediction !== null &&
|
|
21
|
-
Object.keys(page.prediction).length > 0) {
|
|
22
|
-
this.pages.push(new common_1.Page(carteVitaleV1Document_1.CarteVitaleV1Document, page, page["id"], page["orientation"]));
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.CarteVitaleV1 = CarteVitaleV1;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Prediction, StringDict } from "../../../parsing/common";
|
|
2
|
-
import { DateField, StringField } from "../../../parsing/standard";
|
|
3
|
-
/**
|
|
4
|
-
* Carte Vitale API version 1.1 document data.
|
|
5
|
-
*/
|
|
6
|
-
export declare class CarteVitaleV1Document implements Prediction {
|
|
7
|
-
/** The given name(s) of the card holder. */
|
|
8
|
-
givenNames: StringField[];
|
|
9
|
-
/** The date the card was issued. */
|
|
10
|
-
issuanceDate: DateField;
|
|
11
|
-
/** The Social Security Number (Numéro de Sécurité Sociale) of the card holder */
|
|
12
|
-
socialSecurity: StringField;
|
|
13
|
-
/** The surname of the card holder. */
|
|
14
|
-
surname: StringField;
|
|
15
|
-
constructor(rawPrediction: StringDict, pageId?: number);
|
|
16
|
-
/**
|
|
17
|
-
* Default string representation.
|
|
18
|
-
*/
|
|
19
|
-
toString(): string;
|
|
20
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CarteVitaleV1Document = void 0;
|
|
4
|
-
const common_1 = require("../../../parsing/common");
|
|
5
|
-
const standard_1 = require("../../../parsing/standard");
|
|
6
|
-
/**
|
|
7
|
-
* Carte Vitale API version 1.1 document data.
|
|
8
|
-
*/
|
|
9
|
-
class CarteVitaleV1Document {
|
|
10
|
-
constructor(rawPrediction, pageId) {
|
|
11
|
-
/** The given name(s) of the card holder. */
|
|
12
|
-
this.givenNames = [];
|
|
13
|
-
rawPrediction["given_names"] &&
|
|
14
|
-
rawPrediction["given_names"].map((itemPrediction) => this.givenNames.push(new standard_1.StringField({
|
|
15
|
-
prediction: itemPrediction,
|
|
16
|
-
pageId: pageId,
|
|
17
|
-
})));
|
|
18
|
-
this.issuanceDate = new standard_1.DateField({
|
|
19
|
-
prediction: rawPrediction["issuance_date"],
|
|
20
|
-
pageId: pageId,
|
|
21
|
-
});
|
|
22
|
-
this.socialSecurity = new standard_1.StringField({
|
|
23
|
-
prediction: rawPrediction["social_security"],
|
|
24
|
-
pageId: pageId,
|
|
25
|
-
});
|
|
26
|
-
this.surname = new standard_1.StringField({
|
|
27
|
-
prediction: rawPrediction["surname"],
|
|
28
|
-
pageId: pageId,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Default string representation.
|
|
33
|
-
*/
|
|
34
|
-
toString() {
|
|
35
|
-
const givenNames = this.givenNames.join("\n ");
|
|
36
|
-
const outStr = `:Given Name(s): ${givenNames}
|
|
37
|
-
:Surname: ${this.surname}
|
|
38
|
-
:Social Security Number: ${this.socialSecurity}
|
|
39
|
-
:Issuance Date: ${this.issuanceDate}`.trimEnd();
|
|
40
|
-
return (0, common_1.cleanOutString)(outStr);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.CarteVitaleV1Document = CarteVitaleV1Document;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { CarteVitaleV1 } from "./carteVitaleV1";
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CarteVitaleV1 = void 0;
|
|
4
|
-
var carteVitaleV1_1 = require("./carteVitaleV1");
|
|
5
|
-
Object.defineProperty(exports, "CarteVitaleV1", { enumerable: true, get: function () { return carteVitaleV1_1.CarteVitaleV1; } });
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CarteVitaleV1Document = exports.CarteVitaleV1 = void 0;
|
|
4
|
-
var carteVitaleV1_1 = require("./carteVitaleV1");
|
|
5
|
-
Object.defineProperty(exports, "CarteVitaleV1", { enumerable: true, get: function () { return carteVitaleV1_1.CarteVitaleV1; } });
|
|
6
|
-
var carteVitaleV1Document_1 = require("./carteVitaleV1Document");
|
|
7
|
-
Object.defineProperty(exports, "CarteVitaleV1Document", { enumerable: true, get: function () { return carteVitaleV1Document_1.CarteVitaleV1Document; } });
|