mindee 4.12.0 → 4.13.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 +17 -0
- package/package.json +1 -1
- package/src/client.d.ts +2 -1
- package/src/client.js +20 -0
- package/src/imageOperations/{extractedImage.d.ts → common/extractedImage.d.ts} +6 -3
- package/src/imageOperations/{extractedImage.js → common/extractedImage.js} +6 -3
- package/src/imageOperations/common/imageExtractor.d.ts +9 -0
- package/src/imageOperations/common/imageExtractor.js +34 -0
- package/src/imageOperations/common/index.d.ts +2 -0
- package/src/imageOperations/common/index.js +7 -0
- package/src/imageOperations/index.d.ts +2 -4
- package/src/imageOperations/index.js +3 -5
- package/src/imageOperations/internal.d.ts +3 -5
- package/src/imageOperations/internal.js +5 -7
- package/src/imageOperations/{extractedInvoiceSplitterDocument.d.ts → invoiceSplitterExtractor/extractedInvoiceSplitterImage.d.ts} +4 -1
- package/src/imageOperations/{extractedInvoiceSplitterDocument.js → invoiceSplitterExtractor/extractedInvoiceSplitterImage.js} +4 -1
- package/src/imageOperations/invoiceSplitterExtractor/index.d.ts +2 -0
- package/src/imageOperations/invoiceSplitterExtractor/index.js +7 -0
- package/src/imageOperations/{invoiceSplitterExtractor.d.ts → invoiceSplitterExtractor/invoiceSplitterExtractor.d.ts} +3 -3
- package/src/imageOperations/{invoiceSplitterExtractor.js → invoiceSplitterExtractor/invoiceSplitterExtractor.js} +4 -4
- package/src/imageOperations/{extractedMultiReceiptImage.d.ts → multiReceiptsExtractor/extractedMultiReceiptImage.d.ts} +4 -1
- package/src/imageOperations/{extractedMultiReceiptImage.js → multiReceiptsExtractor/extractedMultiReceiptImage.js} +5 -2
- package/src/imageOperations/multiReceiptsExtractor/index.d.ts +2 -0
- package/src/imageOperations/multiReceiptsExtractor/index.js +7 -0
- package/src/imageOperations/{multiReceiptsExtractor.d.ts → multiReceiptsExtractor/multiReceiptsExtractor.d.ts} +3 -3
- package/src/imageOperations/{multiReceiptsExtractor.js → multiReceiptsExtractor/multiReceiptsExtractor.js} +22 -25
- package/src/index.d.ts +1 -1
- package/src/index.js +2 -1
- package/src/input/index.d.ts +1 -0
- package/src/input/index.js +3 -1
- package/src/input/localResponse.d.ts +33 -0
- package/src/input/localResponse.js +103 -0
- package/src/parsing/standard/base.d.ts +1 -1
- package/src/parsing/standard/boolean.d.ts +17 -0
- package/src/parsing/standard/boolean.js +22 -0
- package/src/parsing/standard/index.d.ts +1 -0
- package/src/parsing/standard/index.js +3 -1
- package/src/parsing/standard/locale.js +1 -1
- package/src/product/us/index.d.ts +1 -0
- package/src/product/us/index.js +3 -1
- package/src/product/us/internal.d.ts +2 -0
- package/src/product/us/internal.js +3 -1
- package/src/product/us/usMail/internal.d.ts +4 -0
- package/src/product/us/usMail/internal.js +11 -0
- package/src/product/us/usMail/usMailV2.d.ts +16 -0
- package/src/product/us/usMail/usMailV2.js +27 -0
- package/src/product/us/usMail/usMailV2Document.d.ts +22 -0
- package/src/product/us/usMail/usMailV2Document.js +62 -0
- package/src/product/us/usMail/usMailV2RecipientAddress.d.ts +40 -0
- package/src/product/us/usMail/usMailV2RecipientAddress.js +116 -0
- package/src/product/us/usMail/usMailV2SenderAddress.d.ts +36 -0
- package/src/product/us/usMail/usMailV2SenderAddress.js +92 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## v4.13.1 - 2024-06-10
|
|
4
|
+
### Fixes
|
|
5
|
+
* :recycle: refactored image extraction module to allow for more generic manipulations
|
|
6
|
+
* :recycle: add tests for multipage receipts extraction
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## v4.13.0 - 2024-05-28
|
|
10
|
+
### Changes
|
|
11
|
+
* :sparkles: add support for local response loading
|
|
12
|
+
* :sparkles: add support for HMAC validation for webhooks
|
|
13
|
+
* :sparkles: add support for US Mail V2
|
|
14
|
+
* :sparkles: add support for boolean fields
|
|
15
|
+
|
|
16
|
+
### Fixes
|
|
17
|
+
* :recycle: fixed Locale display
|
|
18
|
+
|
|
19
|
+
|
|
3
20
|
## v4.12.0 - 2024-05-16
|
|
4
21
|
### Changes
|
|
5
22
|
* :sparkles: update receipt to 5.2 and financial document to 1.7 (#270)
|
package/package.json
CHANGED
package/src/client.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
4
|
import { Readable } from "stream";
|
|
5
|
-
import { Base64Input, BytesInput, InputSource, PathInput, StreamInput, PageOptions, UrlInput, BufferInput } from "./input";
|
|
5
|
+
import { Base64Input, BytesInput, InputSource, PathInput, StreamInput, PageOptions, UrlInput, BufferInput, LocalResponse } from "./input";
|
|
6
6
|
import { Endpoint } from "./http";
|
|
7
7
|
import { AsyncPredictResponse, FeedbackResponse, Inference, PredictResponse, StringDict } from "./parsing/common";
|
|
8
8
|
/**
|
|
@@ -111,6 +111,7 @@ export declare class Client {
|
|
|
111
111
|
* parsing is complete.
|
|
112
112
|
*/
|
|
113
113
|
parseQueued<T extends Inference>(productClass: new (httpResponse: StringDict) => T, queueId: string, params?: PredictOptions): Promise<AsyncPredictResponse<T>>;
|
|
114
|
+
loadPrediction<T extends Inference>(productClass: new (httpResponse: StringDict) => T, localResponse: LocalResponse): Promise<AsyncPredictResponse<T> | PredictResponse<T>>;
|
|
114
115
|
/**
|
|
115
116
|
* Fetch prediction results from a document already processed.
|
|
116
117
|
*
|
package/src/client.js
CHANGED
|
@@ -15,6 +15,7 @@ const logger_1 = require("./logger");
|
|
|
15
15
|
const inference_1 = require("./parsing/common/inference");
|
|
16
16
|
const product_1 = require("./product");
|
|
17
17
|
const promises_1 = require("node:timers/promises");
|
|
18
|
+
const errors_1 = require("./errors");
|
|
18
19
|
/**
|
|
19
20
|
* Mindee Client class that centralizes most basic operations.
|
|
20
21
|
*
|
|
@@ -103,6 +104,25 @@ class Client {
|
|
|
103
104
|
const docResponse = await endpoint.getQueuedDocument(queueId);
|
|
104
105
|
return new common_1.AsyncPredictResponse(productClass, docResponse.data);
|
|
105
106
|
}
|
|
107
|
+
async loadPrediction(productClass, localResponse) {
|
|
108
|
+
/**
|
|
109
|
+
* Load a prediction.
|
|
110
|
+
*
|
|
111
|
+
* @param productClass Product class to use for calling the API and parsing the response.
|
|
112
|
+
* @param localResponse Local response to load.
|
|
113
|
+
* @category Asynchronous
|
|
114
|
+
* @returns A valid prediction
|
|
115
|
+
*/
|
|
116
|
+
try {
|
|
117
|
+
if (Object.prototype.hasOwnProperty.call(localResponse.asDict(), "job")) {
|
|
118
|
+
return new common_1.AsyncPredictResponse(productClass, localResponse.asDict());
|
|
119
|
+
}
|
|
120
|
+
return new common_1.PredictResponse(productClass, localResponse.asDict());
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
throw new errors_1.MindeeError("No prediction found in local response.");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
106
126
|
/**
|
|
107
127
|
* Fetch prediction results from a document already processed.
|
|
108
128
|
*
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Buffer } from "node:buffer";
|
|
3
|
-
import { BufferInput } from "
|
|
4
|
-
|
|
3
|
+
import { BufferInput } from "../../input";
|
|
4
|
+
/**
|
|
5
|
+
* Generic class for image extraction
|
|
6
|
+
*/
|
|
7
|
+
export declare class ExtractedImage {
|
|
5
8
|
buffer: Buffer;
|
|
6
9
|
protected internalFileName: string;
|
|
7
|
-
constructor(buffer: Uint8Array, fileName: string);
|
|
10
|
+
protected constructor(buffer: Uint8Array, fileName: string);
|
|
8
11
|
/**
|
|
9
12
|
* Saves the document to a file.
|
|
10
13
|
*
|
|
@@ -5,11 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ExtractedImage = void 0;
|
|
7
7
|
const node_buffer_1 = require("node:buffer");
|
|
8
|
-
const errors_1 = require("
|
|
8
|
+
const errors_1 = require("../../errors");
|
|
9
9
|
const node_fs_1 = require("node:fs");
|
|
10
10
|
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
-
const logger_1 = require("
|
|
12
|
-
const input_1 = require("
|
|
11
|
+
const logger_1 = require("../../logger");
|
|
12
|
+
const input_1 = require("../../input");
|
|
13
|
+
/**
|
|
14
|
+
* Generic class for image extraction
|
|
15
|
+
*/
|
|
13
16
|
class ExtractedImage {
|
|
14
17
|
constructor(buffer, fileName) {
|
|
15
18
|
this.buffer = node_buffer_1.Buffer.from(buffer);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PDFPage } from "pdf-lib";
|
|
2
|
+
import { Polygon } from "../../geometry";
|
|
3
|
+
/**
|
|
4
|
+
* Extracts elements from a page based off of a list of bounding boxes.
|
|
5
|
+
*
|
|
6
|
+
* @param pdfPage PDF Page to extract from.
|
|
7
|
+
* @param polygons List of coordinates to pull the elements from.
|
|
8
|
+
*/
|
|
9
|
+
export declare function extractFromPage(pdfPage: PDFPage, polygons: Polygon[]): Promise<Uint8Array[]>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractFromPage = void 0;
|
|
4
|
+
const pdf_lib_1 = require("pdf-lib");
|
|
5
|
+
const geometry_1 = require("../../geometry");
|
|
6
|
+
/**
|
|
7
|
+
* Extracts elements from a page based off of a list of bounding boxes.
|
|
8
|
+
*
|
|
9
|
+
* @param pdfPage PDF Page to extract from.
|
|
10
|
+
* @param polygons List of coordinates to pull the elements from.
|
|
11
|
+
*/
|
|
12
|
+
async function extractFromPage(pdfPage, polygons) {
|
|
13
|
+
const { width, height } = pdfPage.getSize();
|
|
14
|
+
const extractedElements = [];
|
|
15
|
+
for (const polygon of polygons) {
|
|
16
|
+
const tempPdf = await pdf_lib_1.PDFDocument.create();
|
|
17
|
+
const newWidth = width * ((0, geometry_1.getMinMaxX)(polygon).max - (0, geometry_1.getMinMaxX)(polygon).min);
|
|
18
|
+
const newHeight = height * ((0, geometry_1.getMinMaxY)(polygon).max - (0, geometry_1.getMinMaxY)(polygon).min);
|
|
19
|
+
const cropped = await tempPdf.embedPage(pdfPage, {
|
|
20
|
+
left: (0, geometry_1.getMinMaxX)(polygon).min * width,
|
|
21
|
+
right: (0, geometry_1.getMinMaxX)(polygon).max * width,
|
|
22
|
+
top: height - ((0, geometry_1.getMinMaxY)(polygon).min * height),
|
|
23
|
+
bottom: height - ((0, geometry_1.getMinMaxY)(polygon).max * height),
|
|
24
|
+
});
|
|
25
|
+
const samplePage = tempPdf.addPage([newWidth, newHeight]);
|
|
26
|
+
samplePage.drawPage(cropped, {
|
|
27
|
+
width: newWidth,
|
|
28
|
+
height: newHeight,
|
|
29
|
+
});
|
|
30
|
+
extractedElements.push(await tempPdf.save());
|
|
31
|
+
}
|
|
32
|
+
return extractedElements;
|
|
33
|
+
}
|
|
34
|
+
exports.extractFromPage = extractFromPage;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractFromPage = exports.ExtractedImage = void 0;
|
|
4
|
+
var extractedImage_1 = require("./extractedImage");
|
|
5
|
+
Object.defineProperty(exports, "ExtractedImage", { enumerable: true, get: function () { return extractedImage_1.ExtractedImage; } });
|
|
6
|
+
var imageExtractor_1 = require("./imageExtractor");
|
|
7
|
+
Object.defineProperty(exports, "extractFromPage", { enumerable: true, get: function () { return imageExtractor_1.extractFromPage; } });
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
export { extractReceipts } from "./multiReceiptsExtractor";
|
|
2
|
-
export { extractInvoices } from "./invoiceSplitterExtractor";
|
|
3
|
-
export { ExtractedMultiReceiptImage } from "./extractedMultiReceiptImage";
|
|
4
|
-
export { ExtractedInvoiceSplitterImage } from "./extractedInvoiceSplitterDocument";
|
|
1
|
+
export { extractReceipts, ExtractedMultiReceiptImage } from "./multiReceiptsExtractor";
|
|
2
|
+
export { extractInvoices, ExtractedInvoiceSplitterImage } from "./invoiceSplitterExtractor";
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ExtractedInvoiceSplitterImage = exports.
|
|
3
|
+
exports.ExtractedInvoiceSplitterImage = exports.extractInvoices = exports.ExtractedMultiReceiptImage = exports.extractReceipts = void 0;
|
|
4
4
|
var multiReceiptsExtractor_1 = require("./multiReceiptsExtractor");
|
|
5
5
|
Object.defineProperty(exports, "extractReceipts", { enumerable: true, get: function () { return multiReceiptsExtractor_1.extractReceipts; } });
|
|
6
|
+
Object.defineProperty(exports, "ExtractedMultiReceiptImage", { enumerable: true, get: function () { return multiReceiptsExtractor_1.ExtractedMultiReceiptImage; } });
|
|
6
7
|
var invoiceSplitterExtractor_1 = require("./invoiceSplitterExtractor");
|
|
7
8
|
Object.defineProperty(exports, "extractInvoices", { enumerable: true, get: function () { return invoiceSplitterExtractor_1.extractInvoices; } });
|
|
8
|
-
|
|
9
|
-
Object.defineProperty(exports, "ExtractedMultiReceiptImage", { enumerable: true, get: function () { return extractedMultiReceiptImage_1.ExtractedMultiReceiptImage; } });
|
|
10
|
-
var extractedInvoiceSplitterDocument_1 = require("./extractedInvoiceSplitterDocument");
|
|
11
|
-
Object.defineProperty(exports, "ExtractedInvoiceSplitterImage", { enumerable: true, get: function () { return extractedInvoiceSplitterDocument_1.ExtractedInvoiceSplitterImage; } });
|
|
9
|
+
Object.defineProperty(exports, "ExtractedInvoiceSplitterImage", { enumerable: true, get: function () { return invoiceSplitterExtractor_1.ExtractedInvoiceSplitterImage; } });
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export { extractReceipts } from "./multiReceiptsExtractor";
|
|
2
|
-
export { extractInvoices } from "./invoiceSplitterExtractor";
|
|
3
|
-
export {
|
|
4
|
-
export { ExtractedInvoiceSplitterImage } from "./extractedInvoiceSplitterDocument";
|
|
5
|
-
export { ExtractedImage } from "./extractedImage";
|
|
1
|
+
export { extractReceipts, ExtractedMultiReceiptImage } from "./multiReceiptsExtractor";
|
|
2
|
+
export { extractInvoices, ExtractedInvoiceSplitterImage } from "./invoiceSplitterExtractor";
|
|
3
|
+
export { ExtractedImage } from "./common";
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ExtractedImage = exports.ExtractedInvoiceSplitterImage = exports.
|
|
3
|
+
exports.ExtractedImage = exports.ExtractedInvoiceSplitterImage = exports.extractInvoices = exports.ExtractedMultiReceiptImage = exports.extractReceipts = void 0;
|
|
4
4
|
var multiReceiptsExtractor_1 = require("./multiReceiptsExtractor");
|
|
5
5
|
Object.defineProperty(exports, "extractReceipts", { enumerable: true, get: function () { return multiReceiptsExtractor_1.extractReceipts; } });
|
|
6
|
+
Object.defineProperty(exports, "ExtractedMultiReceiptImage", { enumerable: true, get: function () { return multiReceiptsExtractor_1.ExtractedMultiReceiptImage; } });
|
|
6
7
|
var invoiceSplitterExtractor_1 = require("./invoiceSplitterExtractor");
|
|
7
8
|
Object.defineProperty(exports, "extractInvoices", { enumerable: true, get: function () { return invoiceSplitterExtractor_1.extractInvoices; } });
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Object.defineProperty(exports, "ExtractedInvoiceSplitterImage", { enumerable: true, get: function () { return extractedInvoiceSplitterDocument_1.ExtractedInvoiceSplitterImage; } });
|
|
12
|
-
var extractedImage_1 = require("./extractedImage");
|
|
13
|
-
Object.defineProperty(exports, "ExtractedImage", { enumerable: true, get: function () { return extractedImage_1.ExtractedImage; } });
|
|
9
|
+
Object.defineProperty(exports, "ExtractedInvoiceSplitterImage", { enumerable: true, get: function () { return invoiceSplitterExtractor_1.ExtractedInvoiceSplitterImage; } });
|
|
10
|
+
var common_1 = require("./common");
|
|
11
|
+
Object.defineProperty(exports, "ExtractedImage", { enumerable: true, get: function () { return common_1.ExtractedImage; } });
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { ExtractedImage } from "
|
|
1
|
+
import { ExtractedImage } from "../common/extractedImage";
|
|
2
|
+
/**
|
|
3
|
+
* Wrapper class for extracted invoice pages.
|
|
4
|
+
*/
|
|
2
5
|
export declare class ExtractedInvoiceSplitterImage extends ExtractedImage {
|
|
3
6
|
readonly pageIdMin: number;
|
|
4
7
|
readonly pageIdMax: number;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ExtractedInvoiceSplitterImage = void 0;
|
|
4
|
-
const extractedImage_1 = require("
|
|
4
|
+
const extractedImage_1 = require("../common/extractedImage");
|
|
5
|
+
/**
|
|
6
|
+
* Wrapper class for extracted invoice pages.
|
|
7
|
+
*/
|
|
5
8
|
class ExtractedInvoiceSplitterImage extends extractedImage_1.ExtractedImage {
|
|
6
9
|
constructor(buffer, pageIndices) {
|
|
7
10
|
super(buffer, `invoice_p_${pageIndices[0]}-${pageIndices[1]}.pdf`);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExtractedInvoiceSplitterImage = exports.extractInvoices = void 0;
|
|
4
|
+
var invoiceSplitterExtractor_1 = require("./invoiceSplitterExtractor");
|
|
5
|
+
Object.defineProperty(exports, "extractInvoices", { enumerable: true, get: function () { return invoiceSplitterExtractor_1.extractInvoices; } });
|
|
6
|
+
var extractedInvoiceSplitterImage_1 = require("./extractedInvoiceSplitterImage");
|
|
7
|
+
Object.defineProperty(exports, "ExtractedInvoiceSplitterImage", { enumerable: true, get: function () { return extractedInvoiceSplitterImage_1.ExtractedInvoiceSplitterImage; } });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { InvoiceSplitterV1 } from "
|
|
2
|
-
import { LocalInputSource } from "
|
|
3
|
-
import { ExtractedInvoiceSplitterImage } from "./
|
|
1
|
+
import { InvoiceSplitterV1 } from "../../product";
|
|
2
|
+
import { LocalInputSource } from "../../input/base";
|
|
3
|
+
import { ExtractedInvoiceSplitterImage } from "./extractedInvoiceSplitterImage";
|
|
4
4
|
/**
|
|
5
5
|
* Extracts & cuts the pages of a main document invoice according to the provided indexes.
|
|
6
6
|
*
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extractInvoices = void 0;
|
|
4
4
|
const pdf_lib_1 = require("pdf-lib");
|
|
5
|
-
const errors_1 = require("
|
|
6
|
-
const product_1 = require("
|
|
7
|
-
const
|
|
5
|
+
const errors_1 = require("../../errors");
|
|
6
|
+
const product_1 = require("../../product");
|
|
7
|
+
const extractedInvoiceSplitterImage_1 = require("./extractedInvoiceSplitterImage");
|
|
8
8
|
async function splitPdf(pdfDoc, invoicePageGroups) {
|
|
9
9
|
if (invoicePageGroups.length === 0) {
|
|
10
10
|
return [];
|
|
@@ -21,7 +21,7 @@ async function splitPdf(pdfDoc, invoicePageGroups) {
|
|
|
21
21
|
subdocument.addPage(page);
|
|
22
22
|
});
|
|
23
23
|
const subdocumentBytes = await subdocument.save();
|
|
24
|
-
generatedPdfs.push(new
|
|
24
|
+
generatedPdfs.push(new extractedInvoiceSplitterImage_1.ExtractedInvoiceSplitterImage(subdocumentBytes, [invoicePageGroups[i][0], invoicePageGroups[i][invoicePageGroups[i].length - 1]]));
|
|
25
25
|
}
|
|
26
26
|
return generatedPdfs;
|
|
27
27
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { ExtractedImage } from "
|
|
1
|
+
import { ExtractedImage } from "../common";
|
|
2
|
+
/**
|
|
3
|
+
* Wrapper class for extracted multiple-receipts images.
|
|
4
|
+
*/
|
|
2
5
|
export declare class ExtractedMultiReceiptImage extends ExtractedImage {
|
|
3
6
|
readonly receiptId: number;
|
|
4
7
|
readonly pageId: number;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ExtractedMultiReceiptImage = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
4
|
+
const common_1 = require("../common");
|
|
5
|
+
/**
|
|
6
|
+
* Wrapper class for extracted multiple-receipts images.
|
|
7
|
+
*/
|
|
8
|
+
class ExtractedMultiReceiptImage extends common_1.ExtractedImage {
|
|
6
9
|
constructor(buffer, pageId, receiptId) {
|
|
7
10
|
super(buffer, `receipt_p${pageId}_${receiptId}.pdf`);
|
|
8
11
|
this.pageId = pageId;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExtractedMultiReceiptImage = exports.extractReceipts = void 0;
|
|
4
|
+
var multiReceiptsExtractor_1 = require("./multiReceiptsExtractor");
|
|
5
|
+
Object.defineProperty(exports, "extractReceipts", { enumerable: true, get: function () { return multiReceiptsExtractor_1.extractReceipts; } });
|
|
6
|
+
var extractedMultiReceiptImage_1 = require("./extractedMultiReceiptImage");
|
|
7
|
+
Object.defineProperty(exports, "ExtractedMultiReceiptImage", { enumerable: true, get: function () { return extractedMultiReceiptImage_1.ExtractedMultiReceiptImage; } });
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { MultiReceiptsDetectorV1 } from "
|
|
1
|
+
import { MultiReceiptsDetectorV1 } from "../../product";
|
|
2
2
|
import { ExtractedMultiReceiptImage } from "./extractedMultiReceiptImage";
|
|
3
|
-
import { LocalInputSource } from "
|
|
3
|
+
import { LocalInputSource } from "../../input/base";
|
|
4
4
|
/**
|
|
5
5
|
* Extracts individual receipts from multi-receipts documents.
|
|
6
6
|
*
|
|
7
7
|
* @param inputFile File to extract sub-receipts from.
|
|
8
8
|
* @param inference Results of the inference.
|
|
9
|
-
* @returns Individual extracted receipts as an array of
|
|
9
|
+
* @returns Individual extracted receipts as an array of ExtractedMultiReceiptImage.
|
|
10
10
|
*/
|
|
11
11
|
export declare function extractReceipts(inputFile: LocalInputSource, inference: MultiReceiptsDetectorV1): Promise<ExtractedMultiReceiptImage[]>;
|
|
@@ -2,27 +2,25 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extractReceipts = void 0;
|
|
4
4
|
const pdf_lib_1 = require("pdf-lib");
|
|
5
|
-
const errors_1 = require("
|
|
6
|
-
const geometry_1 = require("../geometry");
|
|
5
|
+
const errors_1 = require("../../errors");
|
|
7
6
|
const extractedMultiReceiptImage_1 = require("./extractedMultiReceiptImage");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return new extractedMultiReceiptImage_1.ExtractedMultiReceiptImage(receiptBytes, pageId, receiptId);
|
|
7
|
+
const common_1 = require("../common");
|
|
8
|
+
/**
|
|
9
|
+
* Given a page and a set of coordinates, extracts & assigns individual receipts to an ExtractedMultiReceiptImage
|
|
10
|
+
* object.
|
|
11
|
+
*
|
|
12
|
+
* @param pdfPage PDF Page to extract from.
|
|
13
|
+
* @param boundingBoxes A set of coordinates delimiting the position of each receipt.
|
|
14
|
+
* @param pageId Id of the page the receipt is extracted from. Caution: this starts at 0, unlike the numbering in PDF
|
|
15
|
+
* pages.
|
|
16
|
+
*/
|
|
17
|
+
async function extractReceiptsFromPage(pdfPage, boundingBoxes, pageId) {
|
|
18
|
+
const extractedReceiptsRaw = await (0, common_1.extractFromPage)(pdfPage, boundingBoxes);
|
|
19
|
+
const extractedReceipts = [];
|
|
20
|
+
for (let i = 0; i < extractedReceiptsRaw.length; i++) {
|
|
21
|
+
extractedReceipts.push(new extractedMultiReceiptImage_1.ExtractedMultiReceiptImage(extractedReceiptsRaw[i], pageId, i));
|
|
22
|
+
}
|
|
23
|
+
return extractedReceipts;
|
|
26
24
|
}
|
|
27
25
|
async function loadPdfDoc(inputFile) {
|
|
28
26
|
let pdfDoc;
|
|
@@ -52,7 +50,7 @@ async function loadPdfDoc(inputFile) {
|
|
|
52
50
|
*
|
|
53
51
|
* @param inputFile File to extract sub-receipts from.
|
|
54
52
|
* @param inference Results of the inference.
|
|
55
|
-
* @returns Individual extracted receipts as an array of
|
|
53
|
+
* @returns Individual extracted receipts as an array of ExtractedMultiReceiptImage.
|
|
56
54
|
*/
|
|
57
55
|
async function extractReceipts(inputFile, inference) {
|
|
58
56
|
const images = [];
|
|
@@ -62,10 +60,9 @@ async function extractReceipts(inputFile, inference) {
|
|
|
62
60
|
const pdfDoc = await loadPdfDoc(inputFile);
|
|
63
61
|
for (let pageId = 0; pageId < pdfDoc.getPageCount(); pageId++) {
|
|
64
62
|
const [page] = await pdfDoc.copyPages(pdfDoc, [pageId]);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
63
|
+
const receiptPositions = inference.pages[pageId].prediction.receipts.map((receipt) => receipt.boundingBox);
|
|
64
|
+
const extractedReceipts = await extractReceiptsFromPage(page, receiptPositions, pageId);
|
|
65
|
+
images.push(...extractedReceipts);
|
|
69
66
|
}
|
|
70
67
|
return images;
|
|
71
68
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * as product from "./product";
|
|
2
2
|
export { Client, PredictOptions } from "./client";
|
|
3
3
|
export { AsyncPredictResponse, PredictResponse, Inference, Prediction, Document, Page, } from "./parsing/common";
|
|
4
|
-
export { InputSource, PageOptionsOperation } from "./input";
|
|
4
|
+
export { InputSource, PageOptionsOperation, LocalResponse } from "./input";
|
|
5
5
|
export * as internal from "./internal";
|
|
6
6
|
export * as imageOperations from "./imageOperations";
|
package/src/index.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.imageOperations = exports.internal = exports.PageOptionsOperation = exports.InputSource = exports.Page = exports.Document = exports.Prediction = exports.Inference = exports.PredictResponse = exports.AsyncPredictResponse = exports.Client = exports.product = void 0;
|
|
26
|
+
exports.imageOperations = exports.internal = exports.LocalResponse = exports.PageOptionsOperation = exports.InputSource = exports.Page = exports.Document = exports.Prediction = exports.Inference = exports.PredictResponse = exports.AsyncPredictResponse = exports.Client = exports.product = void 0;
|
|
27
27
|
exports.product = __importStar(require("./product"));
|
|
28
28
|
var client_1 = require("./client");
|
|
29
29
|
Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } });
|
|
@@ -37,5 +37,6 @@ Object.defineProperty(exports, "Page", { enumerable: true, get: function () { re
|
|
|
37
37
|
var input_1 = require("./input");
|
|
38
38
|
Object.defineProperty(exports, "InputSource", { enumerable: true, get: function () { return input_1.InputSource; } });
|
|
39
39
|
Object.defineProperty(exports, "PageOptionsOperation", { enumerable: true, get: function () { return input_1.PageOptionsOperation; } });
|
|
40
|
+
Object.defineProperty(exports, "LocalResponse", { enumerable: true, get: function () { return input_1.LocalResponse; } });
|
|
40
41
|
exports.internal = __importStar(require("./internal"));
|
|
41
42
|
exports.imageOperations = __importStar(require("./imageOperations"));
|
package/src/input/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { PageOptions, PageOptionsOperation } from "./pageOptions";
|
|
2
2
|
export { Base64Input, BytesInput, PathInput, StreamInput, UrlInput, BufferInput, } from "./sources";
|
|
3
3
|
export { InputSource, INPUT_TYPE_BASE64, INPUT_TYPE_BYTES, INPUT_TYPE_PATH, INPUT_TYPE_STREAM, INPUT_TYPE_BUFFER, } from "./base";
|
|
4
|
+
export { LocalResponse } from "./localResponse";
|
package/src/input/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.INPUT_TYPE_BUFFER = exports.INPUT_TYPE_STREAM = exports.INPUT_TYPE_PATH = exports.INPUT_TYPE_BYTES = exports.INPUT_TYPE_BASE64 = exports.InputSource = exports.BufferInput = exports.UrlInput = exports.StreamInput = exports.PathInput = exports.BytesInput = exports.Base64Input = exports.PageOptionsOperation = void 0;
|
|
3
|
+
exports.LocalResponse = exports.INPUT_TYPE_BUFFER = exports.INPUT_TYPE_STREAM = exports.INPUT_TYPE_PATH = exports.INPUT_TYPE_BYTES = exports.INPUT_TYPE_BASE64 = exports.InputSource = exports.BufferInput = exports.UrlInput = exports.StreamInput = exports.PathInput = exports.BytesInput = exports.Base64Input = exports.PageOptionsOperation = void 0;
|
|
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");
|
|
@@ -17,3 +17,5 @@ Object.defineProperty(exports, "INPUT_TYPE_BYTES", { enumerable: true, get: func
|
|
|
17
17
|
Object.defineProperty(exports, "INPUT_TYPE_PATH", { enumerable: true, get: function () { return base_1.INPUT_TYPE_PATH; } });
|
|
18
18
|
Object.defineProperty(exports, "INPUT_TYPE_STREAM", { enumerable: true, get: function () { return base_1.INPUT_TYPE_STREAM; } });
|
|
19
19
|
Object.defineProperty(exports, "INPUT_TYPE_BUFFER", { enumerable: true, get: function () { return base_1.INPUT_TYPE_BUFFER; } });
|
|
20
|
+
var localResponse_1 = require("./localResponse");
|
|
21
|
+
Object.defineProperty(exports, "LocalResponse", { enumerable: true, get: function () { return localResponse_1.LocalResponse; } });
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { StringDict } from "../parsing/common";
|
|
3
|
+
import { Buffer } from "buffer";
|
|
4
|
+
/**
|
|
5
|
+
* Local response loaded from a file.
|
|
6
|
+
*/
|
|
7
|
+
export declare class LocalResponse {
|
|
8
|
+
private file;
|
|
9
|
+
private readonly inputHandle;
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of LocalResponse.
|
|
12
|
+
*/
|
|
13
|
+
constructor(inputFile: Buffer | string);
|
|
14
|
+
init(): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Returns the dictionary representation of the file.
|
|
17
|
+
* @returns A JSON-like object.
|
|
18
|
+
*/
|
|
19
|
+
asDict(): StringDict;
|
|
20
|
+
/**
|
|
21
|
+
* Returns the HMAC signature of the local response, from the secret key provided.
|
|
22
|
+
* @param secretKey - Secret key, either a string or a byte/byte array.
|
|
23
|
+
* @returns The HMAC signature of the local response.
|
|
24
|
+
*/
|
|
25
|
+
getHmacSignature(secretKey: string | Buffer | Uint8Array): string;
|
|
26
|
+
/**
|
|
27
|
+
* Checks if the HMAC signature of the local response is valid.
|
|
28
|
+
* @param secretKey - Secret key, either a string or a byte/byte array.
|
|
29
|
+
* @param signature - The signature to be compared with.
|
|
30
|
+
* @returns True if the HMAC signature is valid.
|
|
31
|
+
*/
|
|
32
|
+
isValidHmacSignature(secretKey: string | Buffer | Uint8Array, signature: string): boolean;
|
|
33
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
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.LocalResponse = void 0;
|
|
27
|
+
const crypto = __importStar(require("crypto"));
|
|
28
|
+
const fs = __importStar(require("node:fs/promises"));
|
|
29
|
+
const errors_1 = require("../errors");
|
|
30
|
+
const buffer_1 = require("buffer");
|
|
31
|
+
/**
|
|
32
|
+
* Local response loaded from a file.
|
|
33
|
+
*/
|
|
34
|
+
class LocalResponse {
|
|
35
|
+
/**
|
|
36
|
+
* Creates an instance of LocalResponse.
|
|
37
|
+
*/
|
|
38
|
+
constructor(inputFile) {
|
|
39
|
+
this.file = buffer_1.Buffer.alloc(0);
|
|
40
|
+
this.inputHandle = inputFile;
|
|
41
|
+
}
|
|
42
|
+
async init() {
|
|
43
|
+
/**
|
|
44
|
+
* @param inputFile - The input file, which can be a Buffer, string, or PathLike.
|
|
45
|
+
*/
|
|
46
|
+
if (buffer_1.Buffer.isBuffer(this.inputHandle)) {
|
|
47
|
+
this.file = this.inputHandle;
|
|
48
|
+
}
|
|
49
|
+
else if (typeof this.inputHandle === "string") {
|
|
50
|
+
let fileContents;
|
|
51
|
+
try {
|
|
52
|
+
await fs.access(this.inputHandle);
|
|
53
|
+
fileContents = await fs.readFile(this.inputHandle, { encoding: "utf-8" });
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
fileContents = this.inputHandle;
|
|
57
|
+
}
|
|
58
|
+
this.file = buffer_1.Buffer.from(fileContents.replace(/\r/g, "").replace(/\n/g, ""), "utf-8");
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
throw new errors_1.MindeeError("Incompatible type for input.");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Returns the dictionary representation of the file.
|
|
66
|
+
* @returns A JSON-like object.
|
|
67
|
+
*/
|
|
68
|
+
asDict() {
|
|
69
|
+
try {
|
|
70
|
+
const content = this.file.toString("utf-8");
|
|
71
|
+
return JSON.parse(content);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
throw new errors_1.MindeeError("File is not a valid dictionary.");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Returns the HMAC signature of the local response, from the secret key provided.
|
|
79
|
+
* @param secretKey - Secret key, either a string or a byte/byte array.
|
|
80
|
+
* @returns The HMAC signature of the local response.
|
|
81
|
+
*/
|
|
82
|
+
getHmacSignature(secretKey) {
|
|
83
|
+
const algorithm = "sha256";
|
|
84
|
+
try {
|
|
85
|
+
const hmac = crypto.createHmac(algorithm, secretKey);
|
|
86
|
+
hmac.update(this.file);
|
|
87
|
+
return hmac.digest("hex");
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
throw new errors_1.MindeeError("Could not get HMAC signature from payload.");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Checks if the HMAC signature of the local response is valid.
|
|
95
|
+
* @param secretKey - Secret key, either a string or a byte/byte array.
|
|
96
|
+
* @param signature - The signature to be compared with.
|
|
97
|
+
* @returns True if the HMAC signature is valid.
|
|
98
|
+
*/
|
|
99
|
+
isValidHmacSignature(secretKey, signature) {
|
|
100
|
+
return signature === this.getHmacSignature(secretKey);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.LocalResponse = LocalResponse;
|
|
@@ -16,7 +16,7 @@ export interface BaseFieldConstructor {
|
|
|
16
16
|
*/
|
|
17
17
|
export declare class BaseField {
|
|
18
18
|
/** The value. */
|
|
19
|
-
value?: string | number;
|
|
19
|
+
value?: string | number | boolean;
|
|
20
20
|
/** `true` when the field was reconstructed or computed using other fields. */
|
|
21
21
|
reconstructed: boolean;
|
|
22
22
|
/** Page ID for multi-page document. */
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { StringDict } from "../common";
|
|
2
|
+
import { Field } from "./field";
|
|
3
|
+
export interface FieldConstructor {
|
|
4
|
+
prediction: StringDict;
|
|
5
|
+
valueKey?: string;
|
|
6
|
+
reconstructed?: boolean;
|
|
7
|
+
pageId?: number | undefined;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A field containing a text value.
|
|
11
|
+
*/
|
|
12
|
+
export declare class BooleanField extends Field {
|
|
13
|
+
/** The value. */
|
|
14
|
+
value?: boolean;
|
|
15
|
+
constructor({ prediction, valueKey, reconstructed, pageId, }: FieldConstructor);
|
|
16
|
+
toString(): string;
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BooleanField = void 0;
|
|
4
|
+
const field_1 = require("./field");
|
|
5
|
+
/**
|
|
6
|
+
* A field containing a text value.
|
|
7
|
+
*/
|
|
8
|
+
class BooleanField extends field_1.Field {
|
|
9
|
+
constructor({ prediction = {}, valueKey = "value", reconstructed = false, pageId, }) {
|
|
10
|
+
super({ prediction, valueKey, reconstructed, pageId });
|
|
11
|
+
}
|
|
12
|
+
toString() {
|
|
13
|
+
if (this.value === true) {
|
|
14
|
+
return "True";
|
|
15
|
+
}
|
|
16
|
+
else if (this.value === false) {
|
|
17
|
+
return "False";
|
|
18
|
+
}
|
|
19
|
+
return "";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.BooleanField = BooleanField;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { ClassificationField } from "./classification";
|
|
2
2
|
export { Taxes, TaxField } from "./tax";
|
|
3
3
|
export { PaymentDetailsField } from "./paymentDetails";
|
|
4
|
+
export { BooleanField } from "./boolean";
|
|
4
5
|
export { LocaleField } from "./locale";
|
|
5
6
|
export { AmountField, floatToString } from "./amount";
|
|
6
7
|
export { DateField } from "./date";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Field = exports.StringField = exports.PositionField = exports.CompanyRegistrationField = exports.BaseField = exports.DateField = exports.floatToString = exports.AmountField = exports.LocaleField = exports.PaymentDetailsField = exports.TaxField = exports.Taxes = exports.ClassificationField = void 0;
|
|
3
|
+
exports.Field = exports.StringField = exports.PositionField = exports.CompanyRegistrationField = exports.BaseField = exports.DateField = exports.floatToString = exports.AmountField = exports.LocaleField = exports.BooleanField = exports.PaymentDetailsField = exports.TaxField = exports.Taxes = exports.ClassificationField = void 0;
|
|
4
4
|
var classification_1 = require("./classification");
|
|
5
5
|
Object.defineProperty(exports, "ClassificationField", { enumerable: true, get: function () { return classification_1.ClassificationField; } });
|
|
6
6
|
var tax_1 = require("./tax");
|
|
@@ -8,6 +8,8 @@ Object.defineProperty(exports, "Taxes", { enumerable: true, get: function () { r
|
|
|
8
8
|
Object.defineProperty(exports, "TaxField", { enumerable: true, get: function () { return tax_1.TaxField; } });
|
|
9
9
|
var paymentDetails_1 = require("./paymentDetails");
|
|
10
10
|
Object.defineProperty(exports, "PaymentDetailsField", { enumerable: true, get: function () { return paymentDetails_1.PaymentDetailsField; } });
|
|
11
|
+
var boolean_1 = require("./boolean");
|
|
12
|
+
Object.defineProperty(exports, "BooleanField", { enumerable: true, get: function () { return boolean_1.BooleanField; } });
|
|
11
13
|
var locale_1 = require("./locale");
|
|
12
14
|
Object.defineProperty(exports, "LocaleField", { enumerable: true, get: function () { return locale_1.LocaleField; } });
|
|
13
15
|
var amount_1 = require("./amount");
|
|
@@ -10,7 +10,7 @@ class LocaleField extends base_1.BaseField {
|
|
|
10
10
|
* @param {BaseFieldConstructor} constructor Constructor parameters.
|
|
11
11
|
*/
|
|
12
12
|
constructor({ prediction = {}, reconstructed = false, pageId = undefined, }) {
|
|
13
|
-
const valueKey = prediction["value"]
|
|
13
|
+
const valueKey = prediction["value"] ? "value" : "language";
|
|
14
14
|
super({ prediction, valueKey, reconstructed, pageId });
|
|
15
15
|
this.confidence = prediction["confidence"] ? prediction["confidence"] : 0.0;
|
|
16
16
|
this.language =
|
package/src/product/us/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.W9V1 = exports.DriverLicenseV1 = exports.BankCheckV1 = void 0;
|
|
3
|
+
exports.UsMailV2 = exports.W9V1 = exports.DriverLicenseV1 = exports.BankCheckV1 = void 0;
|
|
4
4
|
var bankCheckV1_1 = require("./bankCheck/bankCheckV1");
|
|
5
5
|
Object.defineProperty(exports, "BankCheckV1", { enumerable: true, get: function () { return bankCheckV1_1.BankCheckV1; } });
|
|
6
6
|
var driverLicenseV1_1 = require("./driverLicense/driverLicenseV1");
|
|
7
7
|
Object.defineProperty(exports, "DriverLicenseV1", { enumerable: true, get: function () { return driverLicenseV1_1.DriverLicenseV1; } });
|
|
8
8
|
var w9V1_1 = require("./w9/w9V1");
|
|
9
9
|
Object.defineProperty(exports, "W9V1", { enumerable: true, get: function () { return w9V1_1.W9V1; } });
|
|
10
|
+
var usMailV2_1 = require("./usMail/usMailV2");
|
|
11
|
+
Object.defineProperty(exports, "UsMailV2", { enumerable: true, get: function () { return usMailV2_1.UsMailV2; } });
|
|
@@ -23,6 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.driverLicense = exports.bankCheck = void 0;
|
|
26
|
+
exports.w9 = exports.usMail = exports.driverLicense = exports.bankCheck = void 0;
|
|
27
27
|
exports.bankCheck = __importStar(require("./bankCheck/internal"));
|
|
28
28
|
exports.driverLicense = __importStar(require("./driverLicense/internal"));
|
|
29
|
+
exports.usMail = __importStar(require("./usMail/internal"));
|
|
30
|
+
exports.w9 = __importStar(require("./w9/internal"));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UsMailV2SenderAddress = exports.UsMailV2RecipientAddress = exports.UsMailV2Document = exports.UsMailV2 = void 0;
|
|
4
|
+
var usMailV2_1 = require("./usMailV2");
|
|
5
|
+
Object.defineProperty(exports, "UsMailV2", { enumerable: true, get: function () { return usMailV2_1.UsMailV2; } });
|
|
6
|
+
var usMailV2Document_1 = require("./usMailV2Document");
|
|
7
|
+
Object.defineProperty(exports, "UsMailV2Document", { enumerable: true, get: function () { return usMailV2Document_1.UsMailV2Document; } });
|
|
8
|
+
var usMailV2RecipientAddress_1 = require("./usMailV2RecipientAddress");
|
|
9
|
+
Object.defineProperty(exports, "UsMailV2RecipientAddress", { enumerable: true, get: function () { return usMailV2RecipientAddress_1.UsMailV2RecipientAddress; } });
|
|
10
|
+
var usMailV2SenderAddress_1 = require("./usMailV2SenderAddress");
|
|
11
|
+
Object.defineProperty(exports, "UsMailV2SenderAddress", { enumerable: true, get: function () { return usMailV2SenderAddress_1.UsMailV2SenderAddress; } });
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Inference, StringDict, Page } from "../../../parsing/common";
|
|
2
|
+
import { UsMailV2Document } from "./usMailV2Document";
|
|
3
|
+
/**
|
|
4
|
+
* US Mail API version 2 inference prediction.
|
|
5
|
+
*/
|
|
6
|
+
export declare class UsMailV2 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: UsMailV2Document;
|
|
13
|
+
/** The document's pages. */
|
|
14
|
+
pages: Page<UsMailV2Document>[];
|
|
15
|
+
constructor(rawPrediction: StringDict);
|
|
16
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UsMailV2 = void 0;
|
|
4
|
+
const common_1 = require("../../../parsing/common");
|
|
5
|
+
const usMailV2Document_1 = require("./usMailV2Document");
|
|
6
|
+
/**
|
|
7
|
+
* US Mail API version 2 inference prediction.
|
|
8
|
+
*/
|
|
9
|
+
class UsMailV2 extends common_1.Inference {
|
|
10
|
+
constructor(rawPrediction) {
|
|
11
|
+
super(rawPrediction);
|
|
12
|
+
/** The endpoint's name. */
|
|
13
|
+
this.endpointName = "us_mail";
|
|
14
|
+
/** The endpoint's version. */
|
|
15
|
+
this.endpointVersion = "2";
|
|
16
|
+
/** The document's pages. */
|
|
17
|
+
this.pages = [];
|
|
18
|
+
this.prediction = new usMailV2Document_1.UsMailV2Document(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(usMailV2Document_1.UsMailV2Document, page, page["id"], page["orientation"]));
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.UsMailV2 = UsMailV2;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Prediction, StringDict } from "../../../parsing/common";
|
|
2
|
+
import { UsMailV2SenderAddress } from "./usMailV2SenderAddress";
|
|
3
|
+
import { UsMailV2RecipientAddress } from "./usMailV2RecipientAddress";
|
|
4
|
+
import { StringField } from "../../../parsing/standard";
|
|
5
|
+
/**
|
|
6
|
+
* US Mail API version 2.0 document data.
|
|
7
|
+
*/
|
|
8
|
+
export declare class UsMailV2Document implements Prediction {
|
|
9
|
+
/** The addresses of the recipients. */
|
|
10
|
+
recipientAddresses: UsMailV2RecipientAddress[];
|
|
11
|
+
/** The names of the recipients. */
|
|
12
|
+
recipientNames: StringField[];
|
|
13
|
+
/** The address of the sender. */
|
|
14
|
+
senderAddress: UsMailV2SenderAddress;
|
|
15
|
+
/** The name of the sender. */
|
|
16
|
+
senderName: StringField;
|
|
17
|
+
constructor(rawPrediction: StringDict, pageId?: number);
|
|
18
|
+
/**
|
|
19
|
+
* Default string representation.
|
|
20
|
+
*/
|
|
21
|
+
toString(): string;
|
|
22
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UsMailV2Document = void 0;
|
|
4
|
+
const common_1 = require("../../../parsing/common");
|
|
5
|
+
const usMailV2SenderAddress_1 = require("./usMailV2SenderAddress");
|
|
6
|
+
const usMailV2RecipientAddress_1 = require("./usMailV2RecipientAddress");
|
|
7
|
+
const standard_1 = require("../../../parsing/standard");
|
|
8
|
+
/**
|
|
9
|
+
* US Mail API version 2.0 document data.
|
|
10
|
+
*/
|
|
11
|
+
class UsMailV2Document {
|
|
12
|
+
constructor(rawPrediction, pageId) {
|
|
13
|
+
/** The addresses of the recipients. */
|
|
14
|
+
this.recipientAddresses = [];
|
|
15
|
+
/** The names of the recipients. */
|
|
16
|
+
this.recipientNames = [];
|
|
17
|
+
rawPrediction["recipient_addresses"] &&
|
|
18
|
+
rawPrediction["recipient_addresses"].map((itemPrediction) => this.recipientAddresses.push(new usMailV2RecipientAddress_1.UsMailV2RecipientAddress({
|
|
19
|
+
prediction: itemPrediction,
|
|
20
|
+
pageId: pageId,
|
|
21
|
+
})));
|
|
22
|
+
rawPrediction["recipient_names"] &&
|
|
23
|
+
rawPrediction["recipient_names"].map((itemPrediction) => this.recipientNames.push(new standard_1.StringField({
|
|
24
|
+
prediction: itemPrediction,
|
|
25
|
+
pageId: pageId,
|
|
26
|
+
})));
|
|
27
|
+
this.senderAddress = new usMailV2SenderAddress_1.UsMailV2SenderAddress({
|
|
28
|
+
prediction: rawPrediction["sender_address"],
|
|
29
|
+
pageId: pageId,
|
|
30
|
+
});
|
|
31
|
+
this.senderName = new standard_1.StringField({
|
|
32
|
+
prediction: rawPrediction["sender_name"],
|
|
33
|
+
pageId: pageId,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Default string representation.
|
|
38
|
+
*/
|
|
39
|
+
toString() {
|
|
40
|
+
const recipientNames = this.recipientNames.join("\n ");
|
|
41
|
+
let recipientAddressesSummary = "";
|
|
42
|
+
if (this.recipientAddresses && this.recipientAddresses.length > 0) {
|
|
43
|
+
const recipientAddressesColSizes = [17, 37, 19, 13, 24, 7, 27];
|
|
44
|
+
recipientAddressesSummary += "\n" + (0, common_1.lineSeparator)(recipientAddressesColSizes, "-") + "\n ";
|
|
45
|
+
recipientAddressesSummary += "| City ";
|
|
46
|
+
recipientAddressesSummary += "| Complete Address ";
|
|
47
|
+
recipientAddressesSummary += "| Is Address Change ";
|
|
48
|
+
recipientAddressesSummary += "| Postal Code ";
|
|
49
|
+
recipientAddressesSummary += "| Private Mailbox Number ";
|
|
50
|
+
recipientAddressesSummary += "| State ";
|
|
51
|
+
recipientAddressesSummary += "| Street ";
|
|
52
|
+
recipientAddressesSummary += "|\n" + (0, common_1.lineSeparator)(recipientAddressesColSizes, "=");
|
|
53
|
+
recipientAddressesSummary += this.recipientAddresses.map((item) => "\n " + item.toTableLine() + "\n" + (0, common_1.lineSeparator)(recipientAddressesColSizes, "-")).join("");
|
|
54
|
+
}
|
|
55
|
+
const outStr = `:Sender Name: ${this.senderName}
|
|
56
|
+
:Sender Address: ${this.senderAddress.toFieldList()}
|
|
57
|
+
:Recipient Names: ${recipientNames}
|
|
58
|
+
:Recipient Addresses: ${recipientAddressesSummary}`.trimEnd();
|
|
59
|
+
return (0, common_1.cleanOutString)(outStr);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.UsMailV2Document = UsMailV2Document;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { StringDict } from "../../../parsing/common";
|
|
2
|
+
import { Polygon } from "../../../geometry";
|
|
3
|
+
/**
|
|
4
|
+
* The addresses of the recipients.
|
|
5
|
+
*/
|
|
6
|
+
export declare class UsMailV2RecipientAddress {
|
|
7
|
+
#private;
|
|
8
|
+
/** The city of the recipient's address. */
|
|
9
|
+
city: string | undefined;
|
|
10
|
+
/** The complete address of the recipient. */
|
|
11
|
+
complete: string | undefined;
|
|
12
|
+
/** Indicates if the recipient's address is a change of address. */
|
|
13
|
+
isAddressChange: boolean | undefined;
|
|
14
|
+
/** The postal code of the recipient's address. */
|
|
15
|
+
postalCode: string | undefined;
|
|
16
|
+
/** The private mailbox number of the recipient's address. */
|
|
17
|
+
privateMailboxNumber: string | undefined;
|
|
18
|
+
/** Second part of the ISO 3166-2 code, consisting of two letters indicating the US State. */
|
|
19
|
+
state: string | undefined;
|
|
20
|
+
/** The street of the recipient's address. */
|
|
21
|
+
street: string | undefined;
|
|
22
|
+
/** Confidence score */
|
|
23
|
+
confidence: number;
|
|
24
|
+
/** The document page on which the information was found. */
|
|
25
|
+
pageId: number;
|
|
26
|
+
/**
|
|
27
|
+
* Contains the relative vertices coordinates (points) of a polygon containing
|
|
28
|
+
* the field in the document.
|
|
29
|
+
*/
|
|
30
|
+
polygon: Polygon;
|
|
31
|
+
constructor({ prediction }: StringDict);
|
|
32
|
+
/**
|
|
33
|
+
* Default string representation.
|
|
34
|
+
*/
|
|
35
|
+
toString(): string;
|
|
36
|
+
/**
|
|
37
|
+
* Output in a format suitable for inclusion in an rST table.
|
|
38
|
+
*/
|
|
39
|
+
toTableLine(): string;
|
|
40
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var _UsMailV2RecipientAddress_instances, _UsMailV2RecipientAddress_printableValues;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.UsMailV2RecipientAddress = void 0;
|
|
10
|
+
/**
|
|
11
|
+
* The addresses of the recipients.
|
|
12
|
+
*/
|
|
13
|
+
class UsMailV2RecipientAddress {
|
|
14
|
+
constructor({ prediction = {} }) {
|
|
15
|
+
_UsMailV2RecipientAddress_instances.add(this);
|
|
16
|
+
/** Confidence score */
|
|
17
|
+
this.confidence = 0.0;
|
|
18
|
+
/**
|
|
19
|
+
* Contains the relative vertices coordinates (points) of a polygon containing
|
|
20
|
+
* the field in the document.
|
|
21
|
+
*/
|
|
22
|
+
this.polygon = [];
|
|
23
|
+
this.city = prediction["city"];
|
|
24
|
+
this.complete = prediction["complete"];
|
|
25
|
+
this.isAddressChange = prediction["is_address_change"];
|
|
26
|
+
this.postalCode = prediction["postal_code"];
|
|
27
|
+
this.privateMailboxNumber = prediction["private_mailbox_number"];
|
|
28
|
+
this.state = prediction["state"];
|
|
29
|
+
this.street = prediction["street"];
|
|
30
|
+
this.pageId = prediction["page_id"];
|
|
31
|
+
this.confidence = prediction["confidence"] ? prediction.confidence : 0.0;
|
|
32
|
+
if (prediction["polygon"]) {
|
|
33
|
+
this.polygon = prediction.polygon;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Default string representation.
|
|
38
|
+
*/
|
|
39
|
+
toString() {
|
|
40
|
+
const printable = __classPrivateFieldGet(this, _UsMailV2RecipientAddress_instances, "m", _UsMailV2RecipientAddress_printableValues).call(this);
|
|
41
|
+
return ("City: " +
|
|
42
|
+
printable.city +
|
|
43
|
+
", Complete Address: " +
|
|
44
|
+
printable.complete +
|
|
45
|
+
", Is Address Change: " +
|
|
46
|
+
printable.isAddressChange +
|
|
47
|
+
", Postal Code: " +
|
|
48
|
+
printable.postalCode +
|
|
49
|
+
", Private Mailbox Number: " +
|
|
50
|
+
printable.privateMailboxNumber +
|
|
51
|
+
", State: " +
|
|
52
|
+
printable.state +
|
|
53
|
+
", Street: " +
|
|
54
|
+
printable.street);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Output in a format suitable for inclusion in an rST table.
|
|
58
|
+
*/
|
|
59
|
+
toTableLine() {
|
|
60
|
+
const printable = __classPrivateFieldGet(this, _UsMailV2RecipientAddress_instances, "m", _UsMailV2RecipientAddress_printableValues).call(this);
|
|
61
|
+
return ("| " +
|
|
62
|
+
printable.city.padEnd(15) +
|
|
63
|
+
" | " +
|
|
64
|
+
printable.complete.padEnd(35) +
|
|
65
|
+
" | " +
|
|
66
|
+
printable.isAddressChange.padEnd(17) +
|
|
67
|
+
" | " +
|
|
68
|
+
printable.postalCode.padEnd(11) +
|
|
69
|
+
" | " +
|
|
70
|
+
printable.privateMailboxNumber.padEnd(22) +
|
|
71
|
+
" | " +
|
|
72
|
+
printable.state.padEnd(5) +
|
|
73
|
+
" | " +
|
|
74
|
+
printable.street.padEnd(25) +
|
|
75
|
+
" |");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.UsMailV2RecipientAddress = UsMailV2RecipientAddress;
|
|
79
|
+
_UsMailV2RecipientAddress_instances = new WeakSet(), _UsMailV2RecipientAddress_printableValues = function _UsMailV2RecipientAddress_printableValues() {
|
|
80
|
+
return {
|
|
81
|
+
city: this.city ?
|
|
82
|
+
this.city.length <= 15 ?
|
|
83
|
+
this.city :
|
|
84
|
+
this.city.slice(0, 12) + "..." :
|
|
85
|
+
"",
|
|
86
|
+
complete: this.complete ?
|
|
87
|
+
this.complete.length <= 35 ?
|
|
88
|
+
this.complete :
|
|
89
|
+
this.complete.slice(0, 32) + "..." :
|
|
90
|
+
"",
|
|
91
|
+
isAddressChange: this.isAddressChange === true ?
|
|
92
|
+
"True" : this.isAddressChange === false ?
|
|
93
|
+
"False" :
|
|
94
|
+
"",
|
|
95
|
+
postalCode: this.postalCode ?
|
|
96
|
+
this.postalCode.length <= 11 ?
|
|
97
|
+
this.postalCode :
|
|
98
|
+
this.postalCode.slice(0, 8) + "..." :
|
|
99
|
+
"",
|
|
100
|
+
privateMailboxNumber: this.privateMailboxNumber ?
|
|
101
|
+
this.privateMailboxNumber.length <= 22 ?
|
|
102
|
+
this.privateMailboxNumber :
|
|
103
|
+
this.privateMailboxNumber.slice(0, 19) + "..." :
|
|
104
|
+
"",
|
|
105
|
+
state: this.state ?
|
|
106
|
+
this.state.length <= 5 ?
|
|
107
|
+
this.state :
|
|
108
|
+
this.state.slice(0, 2) + "..." :
|
|
109
|
+
"",
|
|
110
|
+
street: this.street ?
|
|
111
|
+
this.street.length <= 25 ?
|
|
112
|
+
this.street :
|
|
113
|
+
this.street.slice(0, 22) + "..." :
|
|
114
|
+
"",
|
|
115
|
+
};
|
|
116
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { StringDict } from "../../../parsing/common";
|
|
2
|
+
import { Polygon } from "../../../geometry";
|
|
3
|
+
/**
|
|
4
|
+
* The address of the sender.
|
|
5
|
+
*/
|
|
6
|
+
export declare class UsMailV2SenderAddress {
|
|
7
|
+
#private;
|
|
8
|
+
/** The city of the sender's address. */
|
|
9
|
+
city: string | undefined;
|
|
10
|
+
/** The complete address of the sender. */
|
|
11
|
+
complete: string | undefined;
|
|
12
|
+
/** The postal code of the sender's address. */
|
|
13
|
+
postalCode: string | undefined;
|
|
14
|
+
/** Second part of the ISO 3166-2 code, consisting of two letters indicating the US State. */
|
|
15
|
+
state: string | undefined;
|
|
16
|
+
/** The street of the sender's address. */
|
|
17
|
+
street: string | undefined;
|
|
18
|
+
/** Confidence score */
|
|
19
|
+
confidence: number;
|
|
20
|
+
/** The document page on which the information was found. */
|
|
21
|
+
pageId: number;
|
|
22
|
+
/**
|
|
23
|
+
* Contains the relative vertices coordinates (points) of a polygon containing
|
|
24
|
+
* the field in the document.
|
|
25
|
+
*/
|
|
26
|
+
polygon: Polygon;
|
|
27
|
+
constructor({ prediction }: StringDict);
|
|
28
|
+
/**
|
|
29
|
+
* Default string representation.
|
|
30
|
+
*/
|
|
31
|
+
toString(): string;
|
|
32
|
+
/**
|
|
33
|
+
* Output in a format suitable for inclusion in a field list.
|
|
34
|
+
*/
|
|
35
|
+
toFieldList(): string;
|
|
36
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var _UsMailV2SenderAddress_instances, _UsMailV2SenderAddress_printableValues;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.UsMailV2SenderAddress = void 0;
|
|
10
|
+
/**
|
|
11
|
+
* The address of the sender.
|
|
12
|
+
*/
|
|
13
|
+
class UsMailV2SenderAddress {
|
|
14
|
+
constructor({ prediction = {} }) {
|
|
15
|
+
_UsMailV2SenderAddress_instances.add(this);
|
|
16
|
+
/** Confidence score */
|
|
17
|
+
this.confidence = 0.0;
|
|
18
|
+
/**
|
|
19
|
+
* Contains the relative vertices coordinates (points) of a polygon containing
|
|
20
|
+
* the field in the document.
|
|
21
|
+
*/
|
|
22
|
+
this.polygon = [];
|
|
23
|
+
this.city = prediction["city"];
|
|
24
|
+
this.complete = prediction["complete"];
|
|
25
|
+
this.postalCode = prediction["postal_code"];
|
|
26
|
+
this.state = prediction["state"];
|
|
27
|
+
this.street = prediction["street"];
|
|
28
|
+
this.pageId = prediction["page_id"];
|
|
29
|
+
this.confidence = prediction["confidence"] ? prediction.confidence : 0.0;
|
|
30
|
+
if (prediction["polygon"]) {
|
|
31
|
+
this.polygon = prediction.polygon;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Default string representation.
|
|
36
|
+
*/
|
|
37
|
+
toString() {
|
|
38
|
+
const printable = __classPrivateFieldGet(this, _UsMailV2SenderAddress_instances, "m", _UsMailV2SenderAddress_printableValues).call(this);
|
|
39
|
+
return ("City: " +
|
|
40
|
+
printable.city +
|
|
41
|
+
", Complete Address: " +
|
|
42
|
+
printable.complete +
|
|
43
|
+
", Postal Code: " +
|
|
44
|
+
printable.postalCode +
|
|
45
|
+
", State: " +
|
|
46
|
+
printable.state +
|
|
47
|
+
", Street: " +
|
|
48
|
+
printable.street);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Output in a format suitable for inclusion in a field list.
|
|
52
|
+
*/
|
|
53
|
+
toFieldList() {
|
|
54
|
+
const printable = __classPrivateFieldGet(this, _UsMailV2SenderAddress_instances, "m", _UsMailV2SenderAddress_printableValues).call(this);
|
|
55
|
+
return `
|
|
56
|
+
:City: ${printable.city}
|
|
57
|
+
:Complete Address: ${printable.complete}
|
|
58
|
+
:Postal Code: ${printable.postalCode}
|
|
59
|
+
:State: ${printable.state}
|
|
60
|
+
:Street: ${printable.street}`.trimEnd();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.UsMailV2SenderAddress = UsMailV2SenderAddress;
|
|
64
|
+
_UsMailV2SenderAddress_instances = new WeakSet(), _UsMailV2SenderAddress_printableValues = function _UsMailV2SenderAddress_printableValues() {
|
|
65
|
+
return {
|
|
66
|
+
city: this.city ?
|
|
67
|
+
this.city.length <= 15 ?
|
|
68
|
+
this.city :
|
|
69
|
+
this.city.slice(0, 12) + "..." :
|
|
70
|
+
"",
|
|
71
|
+
complete: this.complete ?
|
|
72
|
+
this.complete.length <= 35 ?
|
|
73
|
+
this.complete :
|
|
74
|
+
this.complete.slice(0, 32) + "..." :
|
|
75
|
+
"",
|
|
76
|
+
postalCode: this.postalCode ?
|
|
77
|
+
this.postalCode.length <= 11 ?
|
|
78
|
+
this.postalCode :
|
|
79
|
+
this.postalCode.slice(0, 8) + "..." :
|
|
80
|
+
"",
|
|
81
|
+
state: this.state ?
|
|
82
|
+
this.state.length <= 5 ?
|
|
83
|
+
this.state :
|
|
84
|
+
this.state.slice(0, 2) + "..." :
|
|
85
|
+
"",
|
|
86
|
+
street: this.street ?
|
|
87
|
+
this.street.length <= 25 ?
|
|
88
|
+
this.street :
|
|
89
|
+
this.street.slice(0, 22) + "..." :
|
|
90
|
+
"",
|
|
91
|
+
};
|
|
92
|
+
};
|