mindee 4.20.0 → 4.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +25 -11
  3. package/package.json +1 -1
  4. package/src/cli.js +2 -2
  5. package/src/client.d.ts +3 -3
  6. package/src/client.js +4 -4
  7. package/src/http/baseEndpoint.js +2 -2
  8. package/src/http/endpoint.js +2 -2
  9. package/src/http/workflowEndpoint.js +2 -2
  10. package/src/imageOperations/invoiceSplitterExtractor/invoiceSplitterExtractor.d.ts +1 -1
  11. package/src/imageOperations/multiReceiptsExtractor/multiReceiptsExtractor.d.ts +1 -1
  12. package/src/input/index.d.ts +1 -2
  13. package/src/input/index.js +16 -15
  14. package/src/input/sources/base64Input.d.ts +12 -0
  15. package/src/input/sources/base64Input.js +22 -0
  16. package/src/input/sources/bufferInput.d.ts +10 -0
  17. package/src/input/sources/bufferInput.js +18 -0
  18. package/src/input/sources/bytesInput.d.ts +12 -0
  19. package/src/input/sources/bytesInput.js +21 -0
  20. package/src/input/sources/index.d.ts +8 -0
  21. package/src/input/sources/index.js +24 -0
  22. package/src/input/sources/inputSource.d.ts +16 -0
  23. package/src/input/sources/inputSource.js +17 -0
  24. package/src/input/sources/localInputSource.d.ts +20 -0
  25. package/src/input/{base.js → sources/localInputSource.js} +16 -26
  26. package/src/input/sources/pathInput.d.ts +11 -0
  27. package/src/input/sources/pathInput.js +27 -0
  28. package/src/input/sources/streamInput.d.ts +14 -0
  29. package/src/input/sources/streamInput.js +28 -0
  30. package/src/input/sources/urlInput.d.ts +32 -0
  31. package/src/input/sources/urlInput.js +98 -0
  32. package/src/product/fr/index.d.ts +0 -1
  33. package/src/product/fr/index.js +1 -3
  34. package/src/product/fr/internal.d.ts +0 -1
  35. package/src/product/fr/internal.js +1 -2
  36. package/src/product/ind/indianPassport/indianPassportV1Document.d.ts +1 -1
  37. package/src/product/ind/indianPassport/indianPassportV1Document.js +1 -1
  38. package/src/product/us/index.d.ts +1 -0
  39. package/src/product/us/index.js +3 -1
  40. package/src/product/us/usMail/index.d.ts +1 -0
  41. package/src/product/us/usMail/index.js +3 -1
  42. package/src/product/us/usMail/internal.d.ts +4 -0
  43. package/src/product/us/usMail/internal.js +9 -1
  44. package/src/product/{fr/carteVitale/carteVitaleV1.d.ts → us/usMail/usMailV3.d.ts} +5 -5
  45. package/src/product/us/usMail/usMailV3.js +27 -0
  46. package/src/product/us/usMail/usMailV3Document.d.ts +24 -0
  47. package/src/product/us/usMail/usMailV3Document.js +68 -0
  48. package/src/product/us/usMail/usMailV3RecipientAddress.d.ts +42 -0
  49. package/src/product/us/usMail/usMailV3RecipientAddress.js +128 -0
  50. package/src/product/us/usMail/usMailV3SenderAddress.d.ts +36 -0
  51. package/src/product/us/usMail/usMailV3SenderAddress.js +72 -0
  52. package/src/input/base.d.ts +0 -36
  53. package/src/input/sources.d.ts +0 -59
  54. package/src/input/sources.js +0 -133
  55. package/src/product/fr/carteVitale/carteVitaleV1.js +0 -27
  56. package/src/product/fr/carteVitale/carteVitaleV1Document.d.ts +0 -20
  57. package/src/product/fr/carteVitale/carteVitaleV1Document.js +0 -43
  58. package/src/product/fr/carteVitale/index.d.ts +0 -1
  59. package/src/product/fr/carteVitale/index.js +0 -5
  60. package/src/product/fr/carteVitale/internal.d.ts +0 -2
  61. package/src/product/fr/carteVitale/internal.js +0 -7
@@ -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";
@@ -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.CarteVitaleV1 = exports.CarteGriseV1 = exports.BankAccountDetailsV2 = exports.BankAccountDetailsV1 = void 0;
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.carteVitale = exports.carteGrise = exports.bankAccountDetails = void 0;
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"));
@@ -1,7 +1,7 @@
1
1
  import { Prediction, StringDict } from "../../../parsing/common";
2
2
  import { ClassificationField, DateField, StringField } from "../../../parsing/standard";
3
3
  /**
4
- * Passport - India API version 1.1 document data.
4
+ * Passport - India API version 1.2 document data.
5
5
  */
6
6
  export declare class IndianPassportV1Document implements Prediction {
7
7
  /** The first line of the address of the passport holder. */
@@ -4,7 +4,7 @@ exports.IndianPassportV1Document = void 0;
4
4
  const common_1 = require("../../../parsing/common");
5
5
  const standard_1 = require("../../../parsing/standard");
6
6
  /**
7
- * Passport - India API version 1.1 document data.
7
+ * Passport - India API version 1.2 document data.
8
8
  */
9
9
  class IndianPassportV1Document {
10
10
  constructor(rawPrediction, pageId) {
@@ -2,4 +2,5 @@ export { BankCheckV1 } from "./bankCheck/bankCheckV1";
2
2
  export { DriverLicenseV1 } from "./driverLicense/driverLicenseV1";
3
3
  export { HealthcareCardV1 } from "./healthcareCard/healthcareCardV1";
4
4
  export { UsMailV2 } from "./usMail/usMailV2";
5
+ export { UsMailV3 } from "./usMail/usMailV3";
5
6
  export { W9V1 } from "./w9/w9V1";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.W9V1 = exports.UsMailV2 = exports.HealthcareCardV1 = exports.DriverLicenseV1 = exports.BankCheckV1 = void 0;
3
+ exports.W9V1 = exports.UsMailV3 = exports.UsMailV2 = exports.HealthcareCardV1 = 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");
@@ -9,5 +9,7 @@ var healthcareCardV1_1 = require("./healthcareCard/healthcareCardV1");
9
9
  Object.defineProperty(exports, "HealthcareCardV1", { enumerable: true, get: function () { return healthcareCardV1_1.HealthcareCardV1; } });
10
10
  var usMailV2_1 = require("./usMail/usMailV2");
11
11
  Object.defineProperty(exports, "UsMailV2", { enumerable: true, get: function () { return usMailV2_1.UsMailV2; } });
12
+ var usMailV3_1 = require("./usMail/usMailV3");
13
+ Object.defineProperty(exports, "UsMailV3", { enumerable: true, get: function () { return usMailV3_1.UsMailV3; } });
12
14
  var w9V1_1 = require("./w9/w9V1");
13
15
  Object.defineProperty(exports, "W9V1", { enumerable: true, get: function () { return w9V1_1.W9V1; } });
@@ -1 +1,2 @@
1
1
  export { UsMailV2 } from "./usMailV2";
2
+ export { UsMailV3 } from "./usMailV3";
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UsMailV2 = void 0;
3
+ exports.UsMailV3 = exports.UsMailV2 = void 0;
4
4
  var usMailV2_1 = require("./usMailV2");
5
5
  Object.defineProperty(exports, "UsMailV2", { enumerable: true, get: function () { return usMailV2_1.UsMailV2; } });
6
+ var usMailV3_1 = require("./usMailV3");
7
+ Object.defineProperty(exports, "UsMailV3", { enumerable: true, get: function () { return usMailV3_1.UsMailV3; } });
@@ -2,3 +2,7 @@ export { UsMailV2 } from "./usMailV2";
2
2
  export { UsMailV2Document } from "./usMailV2Document";
3
3
  export { UsMailV2RecipientAddress } from "./usMailV2RecipientAddress";
4
4
  export { UsMailV2SenderAddress } from "./usMailV2SenderAddress";
5
+ export { UsMailV3 } from "./usMailV3";
6
+ export { UsMailV3Document } from "./usMailV3Document";
7
+ export { UsMailV3RecipientAddress } from "./usMailV3RecipientAddress";
8
+ export { UsMailV3SenderAddress } from "./usMailV3SenderAddress";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UsMailV2SenderAddress = exports.UsMailV2RecipientAddress = exports.UsMailV2Document = exports.UsMailV2 = void 0;
3
+ exports.UsMailV3SenderAddress = exports.UsMailV3RecipientAddress = exports.UsMailV3Document = exports.UsMailV3 = exports.UsMailV2SenderAddress = exports.UsMailV2RecipientAddress = exports.UsMailV2Document = exports.UsMailV2 = void 0;
4
4
  var usMailV2_1 = require("./usMailV2");
5
5
  Object.defineProperty(exports, "UsMailV2", { enumerable: true, get: function () { return usMailV2_1.UsMailV2; } });
6
6
  var usMailV2Document_1 = require("./usMailV2Document");
@@ -9,3 +9,11 @@ var usMailV2RecipientAddress_1 = require("./usMailV2RecipientAddress");
9
9
  Object.defineProperty(exports, "UsMailV2RecipientAddress", { enumerable: true, get: function () { return usMailV2RecipientAddress_1.UsMailV2RecipientAddress; } });
10
10
  var usMailV2SenderAddress_1 = require("./usMailV2SenderAddress");
11
11
  Object.defineProperty(exports, "UsMailV2SenderAddress", { enumerable: true, get: function () { return usMailV2SenderAddress_1.UsMailV2SenderAddress; } });
12
+ var usMailV3_1 = require("./usMailV3");
13
+ Object.defineProperty(exports, "UsMailV3", { enumerable: true, get: function () { return usMailV3_1.UsMailV3; } });
14
+ var usMailV3Document_1 = require("./usMailV3Document");
15
+ Object.defineProperty(exports, "UsMailV3Document", { enumerable: true, get: function () { return usMailV3Document_1.UsMailV3Document; } });
16
+ var usMailV3RecipientAddress_1 = require("./usMailV3RecipientAddress");
17
+ Object.defineProperty(exports, "UsMailV3RecipientAddress", { enumerable: true, get: function () { return usMailV3RecipientAddress_1.UsMailV3RecipientAddress; } });
18
+ var usMailV3SenderAddress_1 = require("./usMailV3SenderAddress");
19
+ Object.defineProperty(exports, "UsMailV3SenderAddress", { enumerable: true, get: function () { return usMailV3SenderAddress_1.UsMailV3SenderAddress; } });
@@ -1,16 +1,16 @@
1
1
  import { Inference, StringDict, Page } from "../../../parsing/common";
2
- import { CarteVitaleV1Document } from "./carteVitaleV1Document";
2
+ import { UsMailV3Document } from "./usMailV3Document";
3
3
  /**
4
- * Carte Vitale API version 1 inference prediction.
4
+ * US Mail API version 3 inference prediction.
5
5
  */
6
- export declare class CarteVitaleV1 extends Inference {
6
+ export declare class UsMailV3 extends Inference {
7
7
  /** The endpoint's name. */
8
8
  endpointName: string;
9
9
  /** The endpoint's version. */
10
10
  endpointVersion: string;
11
11
  /** The document-level prediction. */
12
- prediction: CarteVitaleV1Document;
12
+ prediction: UsMailV3Document;
13
13
  /** The document's pages. */
14
- pages: Page<CarteVitaleV1Document>[];
14
+ pages: Page<UsMailV3Document>[];
15
15
  constructor(rawPrediction: StringDict);
16
16
  }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UsMailV3 = void 0;
4
+ const common_1 = require("../../../parsing/common");
5
+ const usMailV3Document_1 = require("./usMailV3Document");
6
+ /**
7
+ * US Mail API version 3 inference prediction.
8
+ */
9
+ class UsMailV3 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 = "3";
16
+ /** The document's pages. */
17
+ this.pages = [];
18
+ this.prediction = new usMailV3Document_1.UsMailV3Document(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(usMailV3Document_1.UsMailV3Document, page, page["id"], page["orientation"]));
23
+ }
24
+ });
25
+ }
26
+ }
27
+ exports.UsMailV3 = UsMailV3;
@@ -0,0 +1,24 @@
1
+ import { Prediction, StringDict } from "../../../parsing/common";
2
+ import { UsMailV3SenderAddress } from "./usMailV3SenderAddress";
3
+ import { UsMailV3RecipientAddress } from "./usMailV3RecipientAddress";
4
+ import { BooleanField, StringField } from "../../../parsing/standard";
5
+ /**
6
+ * US Mail API version 3.0 document data.
7
+ */
8
+ export declare class UsMailV3Document implements Prediction {
9
+ /** Whether the mailing is marked as return to sender. */
10
+ isReturnToSender: BooleanField;
11
+ /** The addresses of the recipients. */
12
+ recipientAddresses: UsMailV3RecipientAddress[];
13
+ /** The names of the recipients. */
14
+ recipientNames: StringField[];
15
+ /** The address of the sender. */
16
+ senderAddress: UsMailV3SenderAddress;
17
+ /** The name of the sender. */
18
+ senderName: StringField;
19
+ constructor(rawPrediction: StringDict, pageId?: number);
20
+ /**
21
+ * Default string representation.
22
+ */
23
+ toString(): string;
24
+ }
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UsMailV3Document = void 0;
4
+ const common_1 = require("../../../parsing/common");
5
+ const usMailV3SenderAddress_1 = require("./usMailV3SenderAddress");
6
+ const usMailV3RecipientAddress_1 = require("./usMailV3RecipientAddress");
7
+ const standard_1 = require("../../../parsing/standard");
8
+ /**
9
+ * US Mail API version 3.0 document data.
10
+ */
11
+ class UsMailV3Document {
12
+ constructor(rawPrediction, pageId) {
13
+ /** The addresses of the recipients. */
14
+ this.recipientAddresses = [];
15
+ /** The names of the recipients. */
16
+ this.recipientNames = [];
17
+ this.isReturnToSender = new standard_1.BooleanField({
18
+ prediction: rawPrediction["is_return_to_sender"],
19
+ pageId: pageId,
20
+ });
21
+ rawPrediction["recipient_addresses"] &&
22
+ rawPrediction["recipient_addresses"].map((itemPrediction) => this.recipientAddresses.push(new usMailV3RecipientAddress_1.UsMailV3RecipientAddress({
23
+ prediction: itemPrediction,
24
+ pageId: pageId,
25
+ })));
26
+ rawPrediction["recipient_names"] &&
27
+ rawPrediction["recipient_names"].map((itemPrediction) => this.recipientNames.push(new standard_1.StringField({
28
+ prediction: itemPrediction,
29
+ pageId: pageId,
30
+ })));
31
+ this.senderAddress = new usMailV3SenderAddress_1.UsMailV3SenderAddress({
32
+ prediction: rawPrediction["sender_address"],
33
+ pageId: pageId,
34
+ });
35
+ this.senderName = new standard_1.StringField({
36
+ prediction: rawPrediction["sender_name"],
37
+ pageId: pageId,
38
+ });
39
+ }
40
+ /**
41
+ * Default string representation.
42
+ */
43
+ toString() {
44
+ const recipientNames = this.recipientNames.join("\n ");
45
+ let recipientAddressesSummary = "";
46
+ if (this.recipientAddresses && this.recipientAddresses.length > 0) {
47
+ const recipientAddressesColSizes = [17, 37, 19, 13, 24, 7, 27, 17];
48
+ recipientAddressesSummary += "\n" + (0, common_1.lineSeparator)(recipientAddressesColSizes, "-") + "\n ";
49
+ recipientAddressesSummary += "| City ";
50
+ recipientAddressesSummary += "| Complete Address ";
51
+ recipientAddressesSummary += "| Is Address Change ";
52
+ recipientAddressesSummary += "| Postal Code ";
53
+ recipientAddressesSummary += "| Private Mailbox Number ";
54
+ recipientAddressesSummary += "| State ";
55
+ recipientAddressesSummary += "| Street ";
56
+ recipientAddressesSummary += "| Unit ";
57
+ recipientAddressesSummary += "|\n" + (0, common_1.lineSeparator)(recipientAddressesColSizes, "=");
58
+ recipientAddressesSummary += this.recipientAddresses.map((item) => "\n " + item.toTableLine() + "\n" + (0, common_1.lineSeparator)(recipientAddressesColSizes, "-")).join("");
59
+ }
60
+ const outStr = `:Sender Name: ${this.senderName}
61
+ :Sender Address: ${this.senderAddress.toFieldList()}
62
+ :Recipient Names: ${recipientNames}
63
+ :Recipient Addresses: ${recipientAddressesSummary}
64
+ :Return to Sender: ${this.isReturnToSender}`.trimEnd();
65
+ return (0, common_1.cleanOutString)(outStr);
66
+ }
67
+ }
68
+ exports.UsMailV3Document = UsMailV3Document;
@@ -0,0 +1,42 @@
1
+ import { StringDict } from "../../../parsing/common";
2
+ import { Polygon } from "../../../geometry";
3
+ /**
4
+ * The addresses of the recipients.
5
+ */
6
+ export declare class UsMailV3RecipientAddress {
7
+ #private;
8
+ /** The city of the recipient's address. */
9
+ city: string | null;
10
+ /** The complete address of the recipient. */
11
+ complete: string | null;
12
+ /** Indicates if the recipient's address is a change of address. */
13
+ isAddressChange: boolean | null;
14
+ /** The postal code of the recipient's address. */
15
+ postalCode: string | null;
16
+ /** The private mailbox number of the recipient's address. */
17
+ privateMailboxNumber: string | null;
18
+ /** Second part of the ISO 3166-2 code, consisting of two letters indicating the US State. */
19
+ state: string | null;
20
+ /** The street of the recipient's address. */
21
+ street: string | null;
22
+ /** The unit number of the recipient's address. */
23
+ unit: string | null;
24
+ /** Confidence score */
25
+ confidence: number;
26
+ /** The document page on which the information was found. */
27
+ pageId: number;
28
+ /**
29
+ * Contains the relative vertices coordinates (points) of a polygon containing
30
+ * the field in the document.
31
+ */
32
+ polygon: Polygon;
33
+ constructor({ prediction }: StringDict);
34
+ /**
35
+ * Default string representation.
36
+ */
37
+ toString(): string;
38
+ /**
39
+ * Output in a format suitable for inclusion in an rST table.
40
+ */
41
+ toTableLine(): string;
42
+ }
@@ -0,0 +1,128 @@
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 _UsMailV3RecipientAddress_instances, _UsMailV3RecipientAddress_printableValues;
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.UsMailV3RecipientAddress = void 0;
10
+ const common_1 = require("../../../parsing/common");
11
+ /**
12
+ * The addresses of the recipients.
13
+ */
14
+ class UsMailV3RecipientAddress {
15
+ constructor({ prediction = {} }) {
16
+ _UsMailV3RecipientAddress_instances.add(this);
17
+ /** Confidence score */
18
+ this.confidence = 0.0;
19
+ /**
20
+ * Contains the relative vertices coordinates (points) of a polygon containing
21
+ * the field in the document.
22
+ */
23
+ this.polygon = [];
24
+ this.city = prediction["city"];
25
+ this.complete = prediction["complete"];
26
+ this.isAddressChange = prediction["is_address_change"];
27
+ this.postalCode = prediction["postal_code"];
28
+ this.privateMailboxNumber = prediction["private_mailbox_number"];
29
+ this.state = prediction["state"];
30
+ this.street = prediction["street"];
31
+ this.unit = prediction["unit"];
32
+ this.pageId = prediction["page_id"];
33
+ this.confidence = prediction["confidence"] ? prediction.confidence : 0.0;
34
+ if (prediction["polygon"]) {
35
+ this.polygon = prediction.polygon;
36
+ }
37
+ }
38
+ /**
39
+ * Default string representation.
40
+ */
41
+ toString() {
42
+ const printable = __classPrivateFieldGet(this, _UsMailV3RecipientAddress_instances, "m", _UsMailV3RecipientAddress_printableValues).call(this);
43
+ return ("City: " +
44
+ printable.city +
45
+ ", Complete Address: " +
46
+ printable.complete +
47
+ ", Is Address Change: " +
48
+ printable.isAddressChange +
49
+ ", Postal Code: " +
50
+ printable.postalCode +
51
+ ", Private Mailbox Number: " +
52
+ printable.privateMailboxNumber +
53
+ ", State: " +
54
+ printable.state +
55
+ ", Street: " +
56
+ printable.street +
57
+ ", Unit: " +
58
+ printable.unit);
59
+ }
60
+ /**
61
+ * Output in a format suitable for inclusion in an rST table.
62
+ */
63
+ toTableLine() {
64
+ const printable = __classPrivateFieldGet(this, _UsMailV3RecipientAddress_instances, "m", _UsMailV3RecipientAddress_printableValues).call(this);
65
+ return ("| " +
66
+ printable.city.padEnd(15) +
67
+ " | " +
68
+ printable.complete.padEnd(35) +
69
+ " | " +
70
+ printable.isAddressChange.padEnd(17) +
71
+ " | " +
72
+ printable.postalCode.padEnd(11) +
73
+ " | " +
74
+ printable.privateMailboxNumber.padEnd(22) +
75
+ " | " +
76
+ printable.state.padEnd(5) +
77
+ " | " +
78
+ printable.street.padEnd(25) +
79
+ " | " +
80
+ printable.unit.padEnd(15) +
81
+ " |");
82
+ }
83
+ }
84
+ exports.UsMailV3RecipientAddress = UsMailV3RecipientAddress;
85
+ _UsMailV3RecipientAddress_instances = new WeakSet(), _UsMailV3RecipientAddress_printableValues = function _UsMailV3RecipientAddress_printableValues() {
86
+ return {
87
+ city: this.city ?
88
+ this.city.length <= 15 ?
89
+ (0, common_1.cleanSpecialChars)(this.city) :
90
+ (0, common_1.cleanSpecialChars)(this.city).slice(0, 12) + "..." :
91
+ "",
92
+ complete: this.complete ?
93
+ this.complete.length <= 35 ?
94
+ (0, common_1.cleanSpecialChars)(this.complete) :
95
+ (0, common_1.cleanSpecialChars)(this.complete).slice(0, 32) + "..." :
96
+ "",
97
+ isAddressChange: this.isAddressChange === true ?
98
+ "True" :
99
+ this.isAddressChange === false ?
100
+ "False" :
101
+ "",
102
+ postalCode: this.postalCode ?
103
+ this.postalCode.length <= 11 ?
104
+ (0, common_1.cleanSpecialChars)(this.postalCode) :
105
+ (0, common_1.cleanSpecialChars)(this.postalCode).slice(0, 8) + "..." :
106
+ "",
107
+ privateMailboxNumber: this.privateMailboxNumber ?
108
+ this.privateMailboxNumber.length <= 22 ?
109
+ (0, common_1.cleanSpecialChars)(this.privateMailboxNumber) :
110
+ (0, common_1.cleanSpecialChars)(this.privateMailboxNumber).slice(0, 19) + "..." :
111
+ "",
112
+ state: this.state ?
113
+ this.state.length <= 5 ?
114
+ (0, common_1.cleanSpecialChars)(this.state) :
115
+ (0, common_1.cleanSpecialChars)(this.state).slice(0, 2) + "..." :
116
+ "",
117
+ street: this.street ?
118
+ this.street.length <= 25 ?
119
+ (0, common_1.cleanSpecialChars)(this.street) :
120
+ (0, common_1.cleanSpecialChars)(this.street).slice(0, 22) + "..." :
121
+ "",
122
+ unit: this.unit ?
123
+ this.unit.length <= 15 ?
124
+ (0, common_1.cleanSpecialChars)(this.unit) :
125
+ (0, common_1.cleanSpecialChars)(this.unit).slice(0, 12) + "..." :
126
+ "",
127
+ };
128
+ };
@@ -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 UsMailV3SenderAddress {
7
+ #private;
8
+ /** The city of the sender's address. */
9
+ city: string | null;
10
+ /** The complete address of the sender. */
11
+ complete: string | null;
12
+ /** The postal code of the sender's address. */
13
+ postalCode: string | null;
14
+ /** Second part of the ISO 3166-2 code, consisting of two letters indicating the US State. */
15
+ state: string | null;
16
+ /** The street of the sender's address. */
17
+ street: string | null;
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
+ }