mindee 4.28.0 → 4.29.0-rc2

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 (90) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +22 -167
  3. package/package.json +7 -7
  4. package/src/cli.js +17 -7
  5. package/src/cliProducts.js +17 -7
  6. package/src/client.d.ts +3 -2
  7. package/src/client.js +9 -9
  8. package/src/clientV2.d.ts +190 -0
  9. package/src/clientV2.js +216 -0
  10. package/src/errors/mindeeError.d.ts +8 -0
  11. package/src/errors/mindeeError.js +17 -1
  12. package/src/http/apiSettings.d.ts +2 -8
  13. package/src/http/apiSettings.js +3 -41
  14. package/src/http/apiSettingsV2.d.ts +10 -0
  15. package/src/http/apiSettingsV2.js +46 -0
  16. package/src/http/baseEndpoint.d.ts +2 -2
  17. package/src/http/baseEndpoint.js +3 -3
  18. package/src/http/baseSettings.d.ts +11 -0
  19. package/src/http/baseSettings.js +59 -0
  20. package/src/http/endpoint.js +6 -6
  21. package/src/http/mindeeApiV2.d.ts +34 -0
  22. package/src/http/mindeeApiV2.js +120 -0
  23. package/src/http/workflowEndpoint.js +2 -2
  24. package/src/imageOperations/common/imageExtractor.d.ts +1 -1
  25. package/src/imageOperations/imageCompressor.d.ts +1 -1
  26. package/src/index.d.ts +2 -1
  27. package/src/index.js +20 -8
  28. package/src/input/localResponse.d.ts +13 -0
  29. package/src/input/localResponse.js +36 -7
  30. package/src/input/sources/localInputSource.d.ts +6 -0
  31. package/src/input/sources/localInputSource.js +26 -8
  32. package/src/internal.js +17 -7
  33. package/src/parsing/common/dateParser.d.ts +1 -0
  34. package/src/parsing/common/dateParser.js +12 -0
  35. package/src/parsing/common/execution.d.ts +0 -1
  36. package/src/parsing/common/execution.js +5 -9
  37. package/src/parsing/common/index.d.ts +1 -0
  38. package/src/parsing/common/index.js +20 -8
  39. package/src/parsing/index.d.ts +1 -0
  40. package/src/parsing/index.js +19 -8
  41. package/src/parsing/v2/commonResponse.d.ts +16 -0
  42. package/src/parsing/v2/commonResponse.js +19 -0
  43. package/src/parsing/v2/errorResponse.d.ts +15 -0
  44. package/src/parsing/v2/errorResponse.js +13 -0
  45. package/src/parsing/v2/field/baseField.d.ts +9 -0
  46. package/src/parsing/v2/field/baseField.js +18 -0
  47. package/src/parsing/v2/field/fieldConfidence.d.ts +9 -0
  48. package/src/parsing/v2/field/fieldConfidence.js +13 -0
  49. package/src/parsing/v2/field/fieldFactory.d.ts +8 -0
  50. package/src/parsing/v2/field/fieldFactory.js +22 -0
  51. package/src/parsing/v2/field/fieldLocation.d.ts +13 -0
  52. package/src/parsing/v2/field/fieldLocation.js +18 -0
  53. package/src/parsing/v2/field/index.d.ts +6 -0
  54. package/src/parsing/v2/field/index.js +15 -0
  55. package/src/parsing/v2/field/inferenceFields.d.ts +9 -0
  56. package/src/parsing/v2/field/inferenceFields.js +38 -0
  57. package/src/parsing/v2/field/listField.d.ts +12 -0
  58. package/src/parsing/v2/field/listField.js +36 -0
  59. package/src/parsing/v2/field/objectField.d.ts +9 -0
  60. package/src/parsing/v2/field/objectField.js +18 -0
  61. package/src/parsing/v2/field/simpleField.d.ts +7 -0
  62. package/src/parsing/v2/field/simpleField.js +17 -0
  63. package/src/parsing/v2/index.d.ts +12 -0
  64. package/src/parsing/v2/index.js +27 -0
  65. package/src/parsing/v2/inference.d.ts +24 -0
  66. package/src/parsing/v2/inference.js +26 -0
  67. package/src/parsing/v2/inferenceResponse.d.ts +10 -0
  68. package/src/parsing/v2/inferenceResponse.js +12 -0
  69. package/src/parsing/v2/inferenceResult.d.ts +15 -0
  70. package/src/parsing/v2/inferenceResult.js +25 -0
  71. package/src/parsing/v2/inferenceResultFile.d.ts +13 -0
  72. package/src/parsing/v2/inferenceResultFile.js +16 -0
  73. package/src/parsing/v2/inferenceResultModel.d.ts +8 -0
  74. package/src/parsing/v2/inferenceResultModel.js +9 -0
  75. package/src/parsing/v2/inferenceResultOptions.d.ts +9 -0
  76. package/src/parsing/v2/inferenceResultOptions.js +10 -0
  77. package/src/parsing/v2/job.d.ts +49 -0
  78. package/src/parsing/v2/job.js +29 -0
  79. package/src/parsing/v2/jobResponse.d.ts +10 -0
  80. package/src/parsing/v2/jobResponse.js +12 -0
  81. package/src/parsing/v2/jobResponseWebhook.d.ts +24 -0
  82. package/src/parsing/v2/jobResponseWebhook.js +19 -0
  83. package/src/parsing/v2/rawText.d.ts +15 -0
  84. package/src/parsing/v2/rawText.js +13 -0
  85. package/src/pdf/pdfCompressor.js +17 -7
  86. package/src/product/fr/internal.js +17 -7
  87. package/src/product/ind/internal.js +17 -7
  88. package/src/product/index.js +17 -7
  89. package/src/product/internal.js +17 -7
  90. package/src/product/us/internal.js +17 -7
@@ -0,0 +1,120 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ var _MindeeApiV2_instances, _MindeeApiV2_processResponse, _MindeeApiV2_documentEnqueuePost, _MindeeApiV2_inferenceResultReqGet;
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MindeeApiV2 = void 0;
13
+ const apiSettingsV2_1 = require("./apiSettingsV2");
14
+ const v2_1 = require("../parsing/v2");
15
+ const form_data_1 = __importDefault(require("form-data"));
16
+ const baseEndpoint_1 = require("./baseEndpoint");
17
+ const mindeeError_1 = require("../errors/mindeeError");
18
+ const logger_1 = require("../logger");
19
+ class MindeeApiV2 {
20
+ constructor(apiKey) {
21
+ _MindeeApiV2_instances.add(this);
22
+ this.settings = new apiSettingsV2_1.ApiSettingsV2({ apiKey: apiKey });
23
+ }
24
+ /**
25
+ * Sends a file to the inference queue.
26
+ * @param inputDoc Local file loaded as an input.
27
+ * @param params {InferenceParameters} parameters relating to the enqueueing options.
28
+ * @category V2
29
+ * @throws Error if the server's response contains one.
30
+ * @returns a `Promise` containing a job response.
31
+ */
32
+ async reqPostInferenceEnqueue(inputDoc, params) {
33
+ await inputDoc.init();
34
+ if (params.modelId === undefined || params.modelId === null || params.modelId === "") {
35
+ throw new Error("Model ID must be provided");
36
+ }
37
+ const result = await __classPrivateFieldGet(this, _MindeeApiV2_instances, "m", _MindeeApiV2_documentEnqueuePost).call(this, inputDoc, params);
38
+ if (result.data.error?.code !== undefined) {
39
+ throw new mindeeError_1.MindeeHttpErrorV2(result.data.error.code, result.data.error.message ?? "Unknown error.");
40
+ }
41
+ return __classPrivateFieldGet(this, _MindeeApiV2_instances, "m", _MindeeApiV2_processResponse).call(this, result, v2_1.JobResponse);
42
+ }
43
+ /**
44
+ * Requests the job of a queued document from the API.
45
+ * Throws an error if the server's response contains one.
46
+ * @param inferenceId The document's ID in the queue.
47
+ * @category Asynchronous
48
+ * @returns a `Promise` containing either the parsed result, or information on the queue.
49
+ */
50
+ async reqGetInference(inferenceId) {
51
+ const queueResponse = await __classPrivateFieldGet(this, _MindeeApiV2_instances, "m", _MindeeApiV2_inferenceResultReqGet).call(this, inferenceId, "inferences");
52
+ return __classPrivateFieldGet(this, _MindeeApiV2_instances, "m", _MindeeApiV2_processResponse).call(this, queueResponse, v2_1.InferenceResponse);
53
+ }
54
+ /**
55
+ * Requests the results of a queued document from the API.
56
+ * Throws an error if the server's response contains one.
57
+ * @param jobId The document's ID in the queue.
58
+ * @category Asynchronous
59
+ * @returns a `Promise` containing either the parsed result, or information on the queue.
60
+ */
61
+ async reqGetJob(jobId) {
62
+ const queueResponse = await __classPrivateFieldGet(this, _MindeeApiV2_instances, "m", _MindeeApiV2_inferenceResultReqGet).call(this, jobId, "jobs");
63
+ return __classPrivateFieldGet(this, _MindeeApiV2_instances, "m", _MindeeApiV2_processResponse).call(this, queueResponse, v2_1.JobResponse);
64
+ }
65
+ }
66
+ exports.MindeeApiV2 = MindeeApiV2;
67
+ _MindeeApiV2_instances = new WeakSet(), _MindeeApiV2_processResponse = function _MindeeApiV2_processResponse(result, responseType) {
68
+ if (result.messageObj?.statusCode && (result.messageObj?.statusCode > 399 || result.messageObj?.statusCode < 200)) {
69
+ if (result.data?.status !== null) {
70
+ throw new mindeeError_1.MindeeHttpErrorV2(result.data?.status, result.data?.detail ?? "Unknown error.");
71
+ }
72
+ throw new mindeeError_1.MindeeHttpErrorV2(result.messageObj?.statusCode ?? -1, result.data?.statusMessage ?? "Unknown error.");
73
+ }
74
+ try {
75
+ return new responseType(result.data);
76
+ }
77
+ catch (e) {
78
+ logger_1.logger.error(`Raised '${e}' Couldn't deserialize response object:\n${JSON.stringify(result.data)}`);
79
+ throw new mindeeError_1.MindeeApiV2Error("Couldn't deserialize response object.");
80
+ }
81
+ }, _MindeeApiV2_documentEnqueuePost = function _MindeeApiV2_documentEnqueuePost(inputDoc, params) {
82
+ const form = new form_data_1.default();
83
+ form.append("model_id", params.modelId);
84
+ if (params.rag) {
85
+ form.append("rag", "true");
86
+ }
87
+ if (params.webhookIds && params.webhookIds.length > 0) {
88
+ form.append("webhook_ids", params.webhookIds.join(","));
89
+ }
90
+ form.append("file", inputDoc.fileObject, {
91
+ filename: inputDoc.filename,
92
+ });
93
+ const path = "/v2/inferences/enqueue";
94
+ const headers = { ...this.settings.baseHeaders, ...form.getHeaders() };
95
+ const options = {
96
+ method: "POST",
97
+ headers: headers,
98
+ hostname: this.settings.hostname,
99
+ path: path,
100
+ timeout: this.settings.timeout,
101
+ };
102
+ return new Promise((resolve, reject) => {
103
+ const req = baseEndpoint_1.BaseEndpoint.readResponse(options, resolve, reject);
104
+ form.pipe(req);
105
+ // potential ECONNRESET if we don't end the request.
106
+ req.end();
107
+ });
108
+ }, _MindeeApiV2_inferenceResultReqGet = function _MindeeApiV2_inferenceResultReqGet(queueId, slug) {
109
+ return new Promise((resolve, reject) => {
110
+ const options = {
111
+ method: "GET",
112
+ headers: this.settings.baseHeaders,
113
+ hostname: this.settings.hostname,
114
+ path: `/v2/${slug}/${queueId}`,
115
+ };
116
+ const req = baseEndpoint_1.BaseEndpoint.readResponse(options, resolve, reject);
117
+ // potential ECONNRESET if we don't end the request.
118
+ req.end();
119
+ });
120
+ };
@@ -34,7 +34,7 @@ class WorkflowEndpoint extends baseEndpoint_1.BaseEndpoint {
34
34
  async executeWorkflow(params) {
35
35
  await params.inputDoc.init();
36
36
  if (params.pageOptions !== undefined) {
37
- await super.cutDocPages(params.inputDoc, params.pageOptions);
37
+ await baseEndpoint_1.BaseEndpoint.cutDocPages(params.inputDoc, params.pageOptions);
38
38
  }
39
39
  const response = await __classPrivateFieldGet(this, _WorkflowEndpoint_instances, "m", _WorkflowEndpoint_workflowReqPost).call(this, params);
40
40
  if (!(0, responseValidation_1.isValidSyncResponse)(response)) {
@@ -90,7 +90,7 @@ class WorkflowEndpoint extends baseEndpoint_1.BaseEndpoint {
90
90
  path: path,
91
91
  timeout: this.settings.timeout,
92
92
  };
93
- const req = this.readResponse(options, resolve, reject);
93
+ const req = baseEndpoint_1.BaseEndpoint.readResponse(options, resolve, reject);
94
94
  form.pipe(req);
95
95
  // potential ECONNRESET if we don't end the request.
96
96
  req.end();
@@ -6,4 +6,4 @@ import { Polygon } from "../../geometry";
6
6
  * @param pdfPage PDF Page to extract from.
7
7
  * @param polygons List of coordinates to pull the elements from.
8
8
  */
9
- export declare function extractFromPage(pdfPage: PDFPage, polygons: Polygon[]): Promise<Uint8Array[]>;
9
+ export declare function extractFromPage(pdfPage: PDFPage, polygons: Polygon[]): Promise<Uint8Array<ArrayBufferLike>[]>;
@@ -6,4 +6,4 @@
6
6
  * @param maxWidth Maximum bound for width.
7
7
  * @param maxHeight Maximum bound for height.
8
8
  */
9
- export declare function compressImage(imageBuffer: Buffer, quality?: number, maxWidth?: number | null, maxHeight?: number | null): Promise<Buffer>;
9
+ export declare function compressImage(imageBuffer: Buffer, quality?: number, maxWidth?: number | null, maxHeight?: number | null): Promise<Buffer<ArrayBufferLike>>;
package/src/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * as product from "./product";
2
2
  export { Client, PredictOptions } from "./client";
3
+ export { ClientV2, InferenceParameters, PollingOptions } from "./clientV2";
3
4
  export { AsyncPredictResponse, PredictResponse, Inference, Prediction, Document, Page, } from "./parsing/common";
4
- export { InputSource, PageOptionsOperation, LocalResponse } from "./input";
5
+ export { InputSource, PageOptions, PageOptionsOperation, LocalResponse } from "./input";
5
6
  export * as internal from "./internal";
6
7
  export * as imageOperations from "./imageOperations";
package/src/index.js CHANGED
@@ -15,18 +15,30 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
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;
36
+ exports.imageOperations = exports.internal = exports.LocalResponse = exports.PageOptionsOperation = exports.InputSource = exports.Page = exports.Document = exports.Prediction = exports.Inference = exports.PredictResponse = exports.AsyncPredictResponse = exports.ClientV2 = exports.Client = exports.product = void 0;
27
37
  exports.product = __importStar(require("./product"));
28
38
  var client_1 = require("./client");
29
39
  Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } });
40
+ var clientV2_1 = require("./clientV2");
41
+ Object.defineProperty(exports, "ClientV2", { enumerable: true, get: function () { return clientV2_1.ClientV2; } });
30
42
  var common_1 = require("./parsing/common");
31
43
  Object.defineProperty(exports, "AsyncPredictResponse", { enumerable: true, get: function () { return common_1.AsyncPredictResponse; } });
32
44
  Object.defineProperty(exports, "PredictResponse", { enumerable: true, get: function () { return common_1.PredictResponse; } });
@@ -1,5 +1,6 @@
1
1
  import { StringDict } from "../parsing/common";
2
2
  import { Buffer } from "buffer";
3
+ import { CommonResponse } from "../parsing/v2";
3
4
  /**
4
5
  * Local response loaded from a file.
5
6
  * Note: Has to be initialized through init() before use.
@@ -30,4 +31,16 @@ export declare class LocalResponse {
30
31
  * @returns True if the HMAC signature is valid.
31
32
  */
32
33
  isValidHmacSignature(secretKey: string | Buffer | Uint8Array, signature: string): boolean;
34
+ /**
35
+ * Deserialize the loaded local response into the requested CommonResponse`-derived class.
36
+ *
37
+ * Typically used when dealing with V2 webhook callbacks.
38
+ *
39
+ * @typeParam ResponseT - A class that extends `CommonResponse`.
40
+ * @param responseClass - The constructor of the class into which
41
+ * the payload should be deserialized.
42
+ * @returns An instance of `responseClass` populated with the file content.
43
+ * @throws MindeeError If the provided class cannot be instantiated.
44
+ */
45
+ deserializeResponse<ResponseT extends CommonResponse>(responseClass: new (serverResponse: StringDict) => ResponseT): ResponseT;
33
46
  }
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.LocalResponse = void 0;
27
37
  const crypto = __importStar(require("crypto"));
@@ -100,5 +110,24 @@ class LocalResponse {
100
110
  isValidHmacSignature(secretKey, signature) {
101
111
  return signature === this.getHmacSignature(secretKey);
102
112
  }
113
+ /**
114
+ * Deserialize the loaded local response into the requested CommonResponse`-derived class.
115
+ *
116
+ * Typically used when dealing with V2 webhook callbacks.
117
+ *
118
+ * @typeParam ResponseT - A class that extends `CommonResponse`.
119
+ * @param responseClass - The constructor of the class into which
120
+ * the payload should be deserialized.
121
+ * @returns An instance of `responseClass` populated with the file content.
122
+ * @throws MindeeError If the provided class cannot be instantiated.
123
+ */
124
+ deserializeResponse(responseClass) {
125
+ try {
126
+ return new responseClass(this.asDict());
127
+ }
128
+ catch {
129
+ throw new errors_1.MindeeError("Invalid class specified for deserialization.");
130
+ }
131
+ }
103
132
  }
104
133
  exports.LocalResponse = LocalResponse;
@@ -16,6 +16,12 @@ export declare abstract class LocalInputSource extends InputSource {
16
16
  * Cut PDF pages.
17
17
  * @param pageOptions
18
18
  */
19
+ applyPageOptions(pageOptions: PageOptions): Promise<void>;
20
+ /**
21
+ * Cut PDF pages.
22
+ * @param pageOptions
23
+ * @deprecated Deprecated in favor of {@link LocalInputSource.applyPageOptions applyPageOptions()}.
24
+ */
19
25
  cutPdf(pageOptions: PageOptions): Promise<void>;
20
26
  /**
21
27
  * Compresses the file object, either as a PDF or an image.
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
@@ -101,13 +111,21 @@ class LocalInputSource extends inputSource_1.InputSource {
101
111
  * Cut PDF pages.
102
112
  * @param pageOptions
103
113
  */
104
- async cutPdf(pageOptions) {
114
+ async applyPageOptions(pageOptions) {
105
115
  if (!(this.fileObject instanceof Buffer)) {
106
116
  throw new Error(`Cannot modify an input source of type ${this.inputType}.`);
107
117
  }
108
118
  const processedPdf = await (0, pdf_2.extractPages)(this.fileObject, pageOptions);
109
119
  this.fileObject = processedPdf.file;
110
120
  }
121
+ /**
122
+ * Cut PDF pages.
123
+ * @param pageOptions
124
+ * @deprecated Deprecated in favor of {@link LocalInputSource.applyPageOptions applyPageOptions()}.
125
+ */
126
+ async cutPdf(pageOptions) {
127
+ return this.applyPageOptions(pageOptions);
128
+ }
111
129
  /**
112
130
  * Compresses the file object, either as a PDF or an image.
113
131
  *
package/src/internal.js CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.product = exports.pdf = exports.parsing = exports.imageOperations = exports.http = exports.geometry = exports.input = void 0;
27
37
  exports.input = __importStar(require("./input"));
@@ -0,0 +1 @@
1
+ export declare function parseDate(dateString: string | null): Date | null;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseDate = parseDate;
4
+ function parseDate(dateString) {
5
+ if (!dateString) {
6
+ return null;
7
+ }
8
+ if (!/Z$/.test(dateString) && !/[+-][0-9]{2}:[0-9]{2}$/.test(dateString)) {
9
+ dateString += "Z";
10
+ }
11
+ return new Date(dateString);
12
+ }
@@ -35,5 +35,4 @@ export declare class Execution<T extends Inference> {
35
35
  /** Identifier for the workflow. */
36
36
  workflowId: string;
37
37
  constructor(inferenceClass: new (serverResponse: StringDict) => T, jsonResponse: StringDict);
38
- private parseDate;
39
38
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Execution = void 0;
4
4
  const generatedV1Document_1 = require("../../product/generated/generatedV1Document");
5
+ const dateParser_1 = require("./dateParser");
5
6
  /**
6
7
  * Representation of an execution for a workflow.
7
8
  * @category Workflow
@@ -9,24 +10,19 @@ const generatedV1Document_1 = require("../../product/generated/generatedV1Docume
9
10
  class Execution {
10
11
  constructor(inferenceClass, jsonResponse) {
11
12
  this.batchName = jsonResponse["batch_name"];
12
- this.createdAt = jsonResponse["created_at"] ? this.parseDate(jsonResponse["created_at"]) : null;
13
+ this.createdAt = (0, dateParser_1.parseDate)(jsonResponse["created_at"]);
13
14
  this.file = jsonResponse["file"];
14
15
  this.id = jsonResponse["id"];
15
16
  this.inference = jsonResponse["inference"] ? new inferenceClass(jsonResponse["inference"]) : null;
16
17
  this.priority = jsonResponse["priority"];
17
- this.reviewedAt = this.parseDate(jsonResponse["reviewed_at"]);
18
- this.availableAt = this.parseDate(jsonResponse["available_at"]);
18
+ this.reviewedAt = (0, dateParser_1.parseDate)(jsonResponse["reviewed_at"]);
19
+ this.availableAt = (0, dateParser_1.parseDate)(jsonResponse["available_at"]);
19
20
  this.reviewedPrediction = jsonResponse["reviewed_prediction"] ?
20
21
  new generatedV1Document_1.GeneratedV1Document(jsonResponse["reviewed_prediction"]) : null;
21
22
  this.status = jsonResponse["status"];
22
23
  this.type = jsonResponse["type"];
23
- this.uploadedAt = this.parseDate(jsonResponse["uploaded_at"]);
24
+ this.uploadedAt = (0, dateParser_1.parseDate)(jsonResponse["uploaded_at"]);
24
25
  this.workflowId = jsonResponse["workflow_id"];
25
26
  }
26
- parseDate(dateString) {
27
- if (!dateString)
28
- return null;
29
- return new Date(dateString);
30
- }
31
27
  }
32
28
  exports.Execution = Execution;
@@ -13,3 +13,4 @@ export { Page } from "./page";
13
13
  export { cleanOutString, lineSeparator } from "./summaryHelper";
14
14
  export * as extras from "./extras";
15
15
  export { floatToString, cleanSpecialChars } from "./summaryHelper";
16
+ export { parseDate } from "./dateParser";
@@ -15,15 +15,25 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.cleanSpecialChars = exports.floatToString = exports.extras = exports.lineSeparator = exports.cleanOutString = exports.Page = exports.Prediction = exports.PredictResponse = exports.AsyncPredictResponse = exports.OrientationField = exports.FeedbackResponse = exports.Inference = exports.ExecutionPriority = exports.ExecutionFile = exports.Execution = exports.Document = void 0;
36
+ exports.parseDate = exports.cleanSpecialChars = exports.floatToString = exports.extras = exports.lineSeparator = exports.cleanOutString = exports.Page = exports.Prediction = exports.PredictResponse = exports.AsyncPredictResponse = exports.OrientationField = exports.FeedbackResponse = exports.Inference = exports.ExecutionPriority = exports.ExecutionFile = exports.Execution = exports.Document = void 0;
27
37
  var document_1 = require("./document");
28
38
  Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return document_1.Document; } });
29
39
  var execution_1 = require("./execution");
@@ -53,3 +63,5 @@ exports.extras = __importStar(require("./extras"));
53
63
  var summaryHelper_2 = require("./summaryHelper");
54
64
  Object.defineProperty(exports, "floatToString", { enumerable: true, get: function () { return summaryHelper_2.floatToString; } });
55
65
  Object.defineProperty(exports, "cleanSpecialChars", { enumerable: true, get: function () { return summaryHelper_2.cleanSpecialChars; } });
66
+ var dateParser_1 = require("./dateParser");
67
+ Object.defineProperty(exports, "parseDate", { enumerable: true, get: function () { return dateParser_1.parseDate; } });
@@ -2,3 +2,4 @@ export * as common from "./common";
2
2
  export * as custom from "./custom";
3
3
  export * as standard from "./standard";
4
4
  export * as generated from "./generated";
5
+ export * as v2 from "./v2";
@@ -15,16 +15,27 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.generated = exports.standard = exports.custom = exports.common = void 0;
36
+ exports.v2 = exports.generated = exports.standard = exports.custom = exports.common = void 0;
27
37
  exports.common = __importStar(require("./common"));
28
38
  exports.custom = __importStar(require("./custom"));
29
39
  exports.standard = __importStar(require("./standard"));
30
40
  exports.generated = __importStar(require("./generated"));
41
+ exports.v2 = __importStar(require("./v2"));
@@ -0,0 +1,16 @@
1
+ import { StringDict } from "../common";
2
+ export declare abstract class CommonResponse {
3
+ /**
4
+ * Raw text representation of the API's response.
5
+ */
6
+ private readonly rawHttp;
7
+ /**
8
+ * @param serverResponse JSON response from the server.
9
+ */
10
+ protected constructor(serverResponse: StringDict);
11
+ /**
12
+ * Raw HTTP request sent from server, as a JSON-like structure
13
+ * @returns The HTTP request
14
+ */
15
+ getRawHttp(): StringDict;
16
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommonResponse = void 0;
4
+ class CommonResponse {
5
+ /**
6
+ * @param serverResponse JSON response from the server.
7
+ */
8
+ constructor(serverResponse) {
9
+ this.rawHttp = serverResponse;
10
+ }
11
+ /**
12
+ * Raw HTTP request sent from server, as a JSON-like structure
13
+ * @returns The HTTP request
14
+ */
15
+ getRawHttp() {
16
+ return this.rawHttp;
17
+ }
18
+ }
19
+ exports.CommonResponse = CommonResponse;
@@ -0,0 +1,15 @@
1
+ import { StringDict } from "../common";
2
+ export declare class ErrorResponse {
3
+ /**
4
+ * The HTTP code status.
5
+ */
6
+ status: number;
7
+ /**
8
+ * The detail on the error.
9
+ */
10
+ detail: string;
11
+ /**
12
+ * @param serverResponse JSON response from the server.
13
+ */
14
+ constructor(serverResponse: StringDict);
15
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ErrorResponse = void 0;
4
+ class ErrorResponse {
5
+ /**
6
+ * @param serverResponse JSON response from the server.
7
+ */
8
+ constructor(serverResponse) {
9
+ this.status = serverResponse["status"];
10
+ this.detail = serverResponse["detail"];
11
+ }
12
+ }
13
+ exports.ErrorResponse = ErrorResponse;
@@ -0,0 +1,9 @@
1
+ import { FieldConfidence } from "./fieldConfidence";
2
+ import { FieldLocation } from "./fieldLocation";
3
+ import { StringDict } from "../../common";
4
+ export declare abstract class BaseField {
5
+ protected _indentLevel: number;
6
+ locations: Array<FieldLocation> | undefined;
7
+ confidence: FieldConfidence | undefined;
8
+ protected constructor(rawResponse: StringDict, indentLevel?: number);
9
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseField = void 0;
4
+ const fieldLocation_1 = require("./fieldLocation");
5
+ class BaseField {
6
+ constructor(rawResponse, indentLevel = 0) {
7
+ this._indentLevel = indentLevel;
8
+ if (rawResponse["locations"]) {
9
+ this.locations = rawResponse["locations"].map((location) => {
10
+ return location ? new fieldLocation_1.FieldLocation(location) : "";
11
+ });
12
+ }
13
+ if (rawResponse["confidence"] !== undefined) {
14
+ this.confidence = rawResponse["confidence"];
15
+ }
16
+ }
17
+ }
18
+ exports.BaseField = BaseField;