mindee 5.8.0 → 5.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/package.json +103 -95
- package/src/geometry/bbox.d.ts +18 -6
- package/src/geometry/bbox.js +7 -3
- package/src/geometry/boundingBox.d.ts +3 -1
- package/src/geometry/boundingBox.js +3 -1
- package/src/geometry/boundingBoxUtils.d.ts +4 -4
- package/src/geometry/boundingBoxUtils.js +7 -7
- package/src/geometry/minMax.d.ts +9 -3
- package/src/geometry/point.d.ts +3 -1
- package/src/geometry/polygon.d.ts +3 -1
- package/src/geometry/polygon.js +3 -1
- package/src/http/apiCore.js +1 -1
- package/src/http/baseSettings.d.ts +15 -5
- package/src/http/baseSettings.js +4 -2
- package/src/http/dispatcher.js +4 -2
- package/src/image/extractedImage.d.ts +13 -5
- package/src/image/extractedImage.js +3 -3
- package/src/image/extractedImages.d.ts +4 -2
- package/src/image/extractedImages.js +3 -1
- package/src/image/imageCompressor.d.ts +1 -0
- package/src/image/imageCompressor.js +2 -2
- package/src/image/imageExtractor.d.ts +2 -2
- package/src/image/imageExtractor.js +14 -14
- package/src/input/base64Input.d.ts +9 -3
- package/src/input/base64Input.js +9 -3
- package/src/input/bufferInput.d.ts +7 -2
- package/src/input/bufferInput.js +6 -2
- package/src/input/bytesInput.d.ts +10 -3
- package/src/input/bytesInput.js +10 -3
- package/src/input/inputSource.d.ts +4 -2
- package/src/input/inputSource.js +3 -2
- package/src/input/localInputSource.d.ts +20 -7
- package/src/input/localInputSource.js +12 -5
- package/src/input/pageOptions.d.ts +9 -3
- package/src/input/pageOptions.js +6 -2
- package/src/input/pathInput.d.ts +12 -4
- package/src/input/pathInput.js +11 -5
- package/src/input/streamInput.d.ts +14 -5
- package/src/input/streamInput.js +13 -4
- package/src/input/urlInput.d.ts +19 -7
- package/src/input/urlInput.js +20 -12
- package/src/parsing/baseLocalResponse.d.ts +8 -4
- package/src/parsing/baseLocalResponse.js +15 -11
- package/src/parsing/stringDict.d.ts +3 -1
- package/src/pdf/extractedPdf.d.ts +16 -6
- package/src/pdf/extractedPdf.js +5 -3
- package/src/pdf/extractedPdfs.d.ts +4 -2
- package/src/pdf/extractedPdfs.js +3 -1
- package/src/pdf/pdfCompressor.js +14 -14
- package/src/pdf/pdfExtractor.d.ts +1 -1
- package/src/pdf/pdfExtractor.js +3 -3
- package/src/pdf/pdfOperation.d.ts +9 -3
- package/src/pdf/pdfOperation.js +14 -14
- package/src/pdf/pdfUtils.js +1 -1
- package/src/v1/cli.js +1 -1
- package/src/v1/client.d.ts +42 -14
- package/src/v1/client.js +8 -8
- package/src/v1/extraction/invoiceSplitterExtractor/extractedInvoiceSplitterImage.d.ts +6 -2
- package/src/v1/extraction/invoiceSplitterExtractor/invoiceSplitterExtractor.d.ts +2 -2
- package/src/v1/extraction/invoiceSplitterExtractor/invoiceSplitterExtractor.js +6 -6
- package/src/v1/extraction/multiReceiptsExtractor/extractedMultiReceiptImage.d.ts +6 -2
- package/src/v1/extraction/multiReceiptsExtractor/multiReceiptsExtractor.d.ts +2 -2
- package/src/v1/extraction/multiReceiptsExtractor/multiReceiptsExtractor.js +3 -3
- package/src/v1/http/apiSettingsV1.d.ts +15 -5
- package/src/v1/http/apiSettingsV1.js +12 -4
- package/src/v1/http/baseEndpoint.d.ts +7 -3
- package/src/v1/http/endpoint.d.ts +10 -4
- package/src/v1/http/endpoint.js +2 -2
- package/src/v1/http/errors.d.ts +9 -3
- package/src/v1/http/errors.js +6 -2
- package/src/v1/http/httpParams.d.ts +37 -13
- package/src/v1/http/workflowEndpoint.d.ts +2 -2
- package/src/v1/http/workflowEndpoint.js +2 -2
- package/src/v1/parsing/common/apiRequest.d.ts +15 -5
- package/src/v1/parsing/common/apiResponse.d.ts +6 -2
- package/src/v1/parsing/common/asyncPredictResponse.d.ts +21 -7
- package/src/v1/parsing/common/document.d.ts +18 -6
- package/src/v1/parsing/common/document.js +2 -2
- package/src/v1/parsing/common/execution.d.ts +40 -14
- package/src/v1/parsing/common/execution.js +1 -1
- package/src/v1/parsing/common/executionFile.d.ts +6 -2
- package/src/v1/parsing/common/executionPriority.d.ts +12 -4
- package/src/v1/parsing/common/executionPriority.js +12 -4
- package/src/v1/parsing/common/extras/cropperExtra.d.ts +7 -3
- package/src/v1/parsing/common/extras/cropperExtra.js +7 -4
- package/src/v1/parsing/common/extras/extras.d.ts +9 -3
- package/src/v1/parsing/common/extras/extras.js +6 -2
- package/src/v1/parsing/common/extras/fullTextOcrExtra.d.ts +9 -3
- package/src/v1/parsing/common/extras/fullTextOcrExtra.js +3 -1
- package/src/v1/parsing/common/extras/ragExtra.d.ts +3 -1
- package/src/v1/parsing/common/extras/ragExtra.js +3 -1
- package/src/v1/parsing/common/feedback/feedbackResponse.d.ts +3 -1
- package/src/v1/parsing/common/feedback/feedbackResponse.js +0 -1
- package/src/v1/parsing/common/inference.d.ts +24 -8
- package/src/v1/parsing/common/inference.js +6 -2
- package/src/v1/parsing/common/mvisionV1.d.ts +3 -1
- package/src/v1/parsing/common/mvisionV1.js +3 -1
- package/src/v1/parsing/common/ocr.d.ts +3 -1
- package/src/v1/parsing/common/ocrPage.d.ts +7 -3
- package/src/v1/parsing/common/ocrPage.js +7 -3
- package/src/v1/parsing/common/orientation.d.ts +7 -3
- package/src/v1/parsing/common/orientation.js +1 -1
- package/src/v1/parsing/common/page.d.ts +12 -4
- package/src/v1/parsing/common/predictResponse.d.ts +3 -1
- package/src/v1/parsing/common/prediction.d.ts +3 -1
- package/src/v1/parsing/common/prediction.js +3 -1
- package/src/v1/parsing/generated/generatedList.d.ts +7 -3
- package/src/v1/parsing/generated/generatedList.js +1 -1
- package/src/v1/parsing/generated/generatedObject.d.ts +26 -10
- package/src/v1/parsing/generated/generatedObject.js +14 -8
- package/src/v1/parsing/localResponse.d.ts +4 -2
- package/src/v1/parsing/localResponse.js +4 -2
- package/src/v1/parsing/standard/addressField.d.ts +24 -8
- package/src/v1/parsing/standard/amount.d.ts +3 -1
- package/src/v1/parsing/standard/amount.js +4 -2
- package/src/v1/parsing/standard/base.d.ts +27 -9
- package/src/v1/parsing/standard/base.js +6 -2
- package/src/v1/parsing/standard/boolean.d.ts +3 -1
- package/src/v1/parsing/standard/classification.d.ts +6 -2
- package/src/v1/parsing/standard/companyRegistration.d.ts +9 -3
- package/src/v1/parsing/standard/companyRegistration.js +4 -2
- package/src/v1/parsing/standard/date.d.ts +12 -4
- package/src/v1/parsing/standard/date.js +3 -1
- package/src/v1/parsing/standard/field.d.ts +7 -5
- package/src/v1/parsing/standard/field.js +4 -4
- package/src/v1/parsing/standard/locale.d.ts +15 -5
- package/src/v1/parsing/standard/paymentDetails.d.ts +15 -5
- package/src/v1/parsing/standard/position.d.ts +15 -5
- package/src/v1/parsing/standard/tax.d.ts +19 -7
- package/src/v1/parsing/standard/tax.js +16 -6
- package/src/v1/parsing/standard/text.d.ts +6 -2
- package/src/v1/parsing/standard/word.d.ts +9 -3
- package/src/v1/parsing/standard/word.js +3 -1
- package/src/v1/product/barcodeReader/barcodeReaderV1.d.ts +13 -5
- package/src/v1/product/barcodeReader/barcodeReaderV1.js +10 -4
- package/src/v1/product/barcodeReader/barcodeReaderV1Document.d.ts +8 -4
- package/src/v1/product/barcodeReader/barcodeReaderV1Document.js +8 -4
- package/src/v1/product/cliProducts.d.ts +2 -2
- package/src/v1/product/cliProducts.js +1 -1
- package/src/v1/product/cropper/cropperV1.d.ts +13 -5
- package/src/v1/product/cropper/cropperV1.js +10 -4
- package/src/v1/product/cropper/cropperV1Document.d.ts +1 -1
- package/src/v1/product/cropper/cropperV1Page.d.ts +5 -3
- package/src/v1/product/cropper/cropperV1Page.js +5 -3
- package/src/v1/product/driverLicense/driverLicenseV1.d.ts +13 -5
- package/src/v1/product/driverLicense/driverLicenseV1.js +10 -4
- package/src/v1/product/driverLicense/driverLicenseV1Document.d.ts +41 -15
- package/src/v1/product/driverLicense/driverLicenseV1Document.js +2 -2
- package/src/v1/product/financialDocument/financialDocumentV1.d.ts +13 -5
- package/src/v1/product/financialDocument/financialDocumentV1.js +10 -4
- package/src/v1/product/financialDocument/financialDocumentV1Document.d.ts +98 -34
- package/src/v1/product/financialDocument/financialDocumentV1Document.js +17 -7
- package/src/v1/product/financialDocument/financialDocumentV1LineItem.d.ts +30 -10
- package/src/v1/product/financialDocument/financialDocumentV1LineItem.js +4 -2
- package/src/v1/product/fr/bankAccountDetails/bankAccountDetailsV1.d.ts +13 -5
- package/src/v1/product/fr/bankAccountDetails/bankAccountDetailsV1.js +10 -4
- package/src/v1/product/fr/bankAccountDetails/bankAccountDetailsV1Document.d.ts +11 -5
- package/src/v1/product/fr/bankAccountDetails/bankAccountDetailsV1Document.js +2 -2
- package/src/v1/product/fr/bankAccountDetails/bankAccountDetailsV2.d.ts +13 -5
- package/src/v1/product/fr/bankAccountDetails/bankAccountDetailsV2.js +10 -4
- package/src/v1/product/fr/bankAccountDetails/bankAccountDetailsV2Bban.d.ts +18 -6
- package/src/v1/product/fr/bankAccountDetails/bankAccountDetailsV2Bban.js +3 -1
- package/src/v1/product/fr/bankAccountDetails/bankAccountDetailsV2Document.d.ts +14 -6
- package/src/v1/product/fr/bankAccountDetails/bankAccountDetailsV2Document.js +2 -2
- package/src/v1/product/fr/carteGrise/carteGriseV1.d.ts +13 -5
- package/src/v1/product/fr/carteGrise/carteGriseV1.js +10 -4
- package/src/v1/product/fr/carteGrise/carteGriseV1Document.d.ts +125 -43
- package/src/v1/product/fr/carteGrise/carteGriseV1Document.js +2 -2
- package/src/v1/product/fr/idCard/idCardV2.d.ts +13 -5
- package/src/v1/product/fr/idCard/idCardV2.js +10 -4
- package/src/v1/product/fr/idCard/idCardV2Document.d.ts +47 -17
- package/src/v1/product/fr/idCard/idCardV2Document.js +5 -3
- package/src/v1/product/fr/idCard/idCardV2Page.d.ts +8 -4
- package/src/v1/product/fr/idCard/idCardV2Page.js +2 -2
- package/src/v1/product/generated/generatedV1.d.ts +13 -5
- package/src/v1/product/generated/generatedV1.js +10 -4
- package/src/v1/product/generated/generatedV1Document.js +2 -2
- package/src/v1/product/generated/generatedV1Page.js +2 -2
- package/src/v1/product/generated/generatedV1Prediction.d.ts +9 -5
- package/src/v1/product/generated/generatedV1Prediction.js +6 -4
- package/src/v1/product/internationalId/internationalIdV2.d.ts +13 -5
- package/src/v1/product/internationalId/internationalIdV2.js +10 -4
- package/src/v1/product/internationalId/internationalIdV2Document.d.ts +53 -19
- package/src/v1/product/internationalId/internationalIdV2Document.js +8 -4
- package/src/v1/product/invoice/invoiceV4.d.ts +13 -5
- package/src/v1/product/invoice/invoiceV4.js +10 -4
- package/src/v1/product/invoice/invoiceV4Document.d.ts +89 -31
- package/src/v1/product/invoice/invoiceV4Document.js +17 -7
- package/src/v1/product/invoice/invoiceV4LineItem.d.ts +30 -10
- package/src/v1/product/invoice/invoiceV4LineItem.js +4 -2
- package/src/v1/product/invoiceSplitter/invoiceSplitterV1.d.ts +13 -5
- package/src/v1/product/invoiceSplitter/invoiceSplitterV1.js +10 -4
- package/src/v1/product/invoiceSplitter/invoiceSplitterV1Document.d.ts +4 -2
- package/src/v1/product/invoiceSplitter/invoiceSplitterV1Document.js +4 -2
- package/src/v1/product/invoiceSplitter/invoiceSplitterV1InvoicePageGroup.d.ts +9 -3
- package/src/v1/product/invoiceSplitter/invoiceSplitterV1InvoicePageGroup.js +3 -1
- package/src/v1/product/multiReceiptsDetector/multiReceiptsDetectorV1.d.ts +13 -5
- package/src/v1/product/multiReceiptsDetector/multiReceiptsDetectorV1.js +10 -4
- package/src/v1/product/multiReceiptsDetector/multiReceiptsDetectorV1Document.d.ts +5 -3
- package/src/v1/product/multiReceiptsDetector/multiReceiptsDetectorV1Document.js +5 -3
- package/src/v1/product/passport/passportV1.d.ts +13 -5
- package/src/v1/product/passport/passportV1.js +10 -4
- package/src/v1/product/passport/passportV1Document.d.ts +35 -13
- package/src/v1/product/passport/passportV1Document.js +5 -3
- package/src/v1/product/receipt/receiptV5.d.ts +13 -5
- package/src/v1/product/receipt/receiptV5.js +10 -4
- package/src/v1/product/receipt/receiptV5Document.d.ts +53 -19
- package/src/v1/product/receipt/receiptV5Document.js +8 -4
- package/src/v1/product/receipt/receiptV5LineItem.d.ts +18 -6
- package/src/v1/product/receipt/receiptV5LineItem.js +4 -2
- package/src/v1/product/resume/resumeV1.d.ts +13 -5
- package/src/v1/product/resume/resumeV1.js +10 -4
- package/src/v1/product/resume/resumeV1Certificate.d.ts +18 -6
- package/src/v1/product/resume/resumeV1Certificate.js +4 -2
- package/src/v1/product/resume/resumeV1Document.d.ts +53 -19
- package/src/v1/product/resume/resumeV1Document.js +29 -11
- package/src/v1/product/resume/resumeV1Education.d.ts +27 -9
- package/src/v1/product/resume/resumeV1Education.js +4 -2
- package/src/v1/product/resume/resumeV1Language.d.ts +12 -4
- package/src/v1/product/resume/resumeV1Language.js +4 -2
- package/src/v1/product/resume/resumeV1ProfessionalExperience.d.ts +33 -11
- package/src/v1/product/resume/resumeV1ProfessionalExperience.js +4 -2
- package/src/v1/product/resume/resumeV1SocialNetworksUrl.d.ts +12 -4
- package/src/v1/product/resume/resumeV1SocialNetworksUrl.js +4 -2
- package/src/v1/product/us/bankCheck/bankCheckV1.d.ts +13 -5
- package/src/v1/product/us/bankCheck/bankCheckV1.js +10 -4
- package/src/v1/product/us/bankCheck/bankCheckV1Document.d.ts +20 -8
- package/src/v1/product/us/bankCheck/bankCheckV1Document.js +5 -3
- package/src/v1/product/us/bankCheck/bankCheckV1Page.d.ts +8 -4
- package/src/v1/product/us/bankCheck/bankCheckV1Page.js +5 -3
- package/src/v2/cli.js +2 -2
- package/src/v2/client.d.ts +103 -21
- package/src/v2/client.js +171 -27
- package/src/v2/clientOptions/baseAnnotationParameters.d.ts +23 -0
- package/src/v2/clientOptions/baseAnnotationParameters.js +17 -0
- package/src/v2/clientOptions/baseProductParameters.js +3 -2
- package/src/v2/clientOptions/baseRagDocumentUploadParameters.d.ts +23 -0
- package/src/v2/clientOptions/baseRagDocumentUploadParameters.js +24 -0
- package/src/v2/clientOptions/index.d.ts +2 -0
- package/src/v2/clientOptions/index.js +2 -0
- package/src/v2/clientOptions/pollingOptions.d.ts +30 -10
- package/src/v2/clientOptions/pollingOptions.js +6 -2
- package/src/v2/fileOperations/crop.d.ts +1 -1
- package/src/v2/http/errors.d.ts +1 -1
- package/src/v2/http/mindeeApiV2.d.ts +36 -7
- package/src/v2/http/mindeeApiV2.js +80 -4
- package/src/v2/parsing/baseRagAnnotationResponse.d.ts +28 -0
- package/src/v2/parsing/baseRagAnnotationResponse.js +14 -0
- package/src/v2/parsing/baseResponse.d.ts +6 -2
- package/src/v2/parsing/baseResponse.js +3 -1
- package/src/v2/parsing/error/errorDetails.d.ts +3 -1
- package/src/v2/parsing/error/errorResponse.d.ts +1 -1
- package/src/v2/parsing/error/errorResponse.js +1 -1
- package/src/v2/parsing/index.d.ts +2 -0
- package/src/v2/parsing/index.js +1 -0
- package/src/v2/parsing/inference/baseInference.d.ts +6 -2
- package/src/v2/parsing/inference/baseInference.js +6 -2
- package/src/v2/parsing/inference/failedInferenceResponse.d.ts +2 -2
- package/src/v2/parsing/inference/failedInferenceResponse.js +2 -2
- package/src/v2/parsing/inference/field/baseField.d.ts +9 -3
- package/src/v2/parsing/inference/field/fieldConfidence.d.ts +12 -4
- package/src/v2/parsing/inference/field/fieldConfidence.js +12 -4
- package/src/v2/parsing/inference/field/fieldLocation.d.ts +9 -3
- package/src/v2/parsing/inference/field/fieldLocation.js +3 -1
- package/src/v2/parsing/inference/field/inferenceFields.d.ts +15 -5
- package/src/v2/parsing/inference/field/inferenceFields.js +12 -4
- package/src/v2/parsing/inference/field/listField.d.ts +6 -2
- package/src/v2/parsing/inference/field/listField.js +6 -2
- package/src/v2/parsing/inference/field/objectField.d.ts +19 -11
- package/src/v2/parsing/inference/field/objectField.js +22 -34
- package/src/v2/parsing/inference/field/ragMetadata.d.ts +3 -1
- package/src/v2/parsing/inference/field/ragMetadata.js +3 -1
- package/src/v2/parsing/inference/field/rawText.d.ts +6 -2
- package/src/v2/parsing/inference/field/rawText.js +6 -2
- package/src/v2/parsing/inference/field/simpleField.d.ts +6 -2
- package/src/v2/parsing/inference/field/simpleField.js +8 -4
- package/src/v2/parsing/inference/inferenceFile.d.ts +6 -2
- package/src/v2/parsing/inference/inferenceFile.js +6 -2
- package/src/v2/parsing/inference/inferenceModel.d.ts +6 -2
- package/src/v2/parsing/inference/inferenceModel.js +6 -2
- package/src/v2/parsing/job/job.d.ts +8 -8
- package/src/v2/parsing/job/job.js +1 -1
- package/src/v2/parsing/job/jobResponse.d.ts +1 -1
- package/src/v2/parsing/job/jobResponse.js +1 -1
- package/src/v2/parsing/job/jobWebhook.d.ts +1 -1
- package/src/v2/parsing/job/jobWebhook.js +1 -1
- package/src/v2/parsing/search/baseSearchResponse.d.ts +1 -1
- package/src/v2/parsing/search/baseSearchResponse.js +1 -1
- package/src/v2/parsing/search/searchModels.d.ts +1 -1
- package/src/v2/parsing/search/searchModels.js +1 -1
- package/src/v2/parsing/search/searchRagDocuments.d.ts +1 -1
- package/src/v2/parsing/search/searchRagDocuments.js +1 -1
- package/src/v2/parsing/search/searchResponse.d.ts +1 -1
- package/src/v2/parsing/search/searchResponse.js +1 -1
- package/src/v2/product/baseProduct.d.ts +26 -6
- package/src/v2/product/baseProduct.js +31 -7
- package/src/v2/product/classification/classification.d.ts +10 -4
- package/src/v2/product/classification/classification.js +10 -4
- package/src/v2/product/classification/classificationClassifier.d.ts +7 -3
- package/src/v2/product/classification/classificationClassifier.js +7 -3
- package/src/v2/product/classification/classificationInference.d.ts +7 -3
- package/src/v2/product/classification/classificationInference.js +7 -3
- package/src/v2/product/classification/classificationResponse.d.ts +4 -2
- package/src/v2/product/classification/classificationResponse.js +4 -2
- package/src/v2/product/classification/classificationResult.d.ts +6 -2
- package/src/v2/product/classification/classificationResult.js +6 -2
- package/src/v2/product/classification/params/classificationParameters.d.ts +1 -1
- package/src/v2/product/classification/params/classificationParameters.js +1 -1
- package/src/v2/product/crop/crop.d.ts +10 -4
- package/src/v2/product/crop/crop.js +10 -4
- package/src/v2/product/crop/cropInference.d.ts +8 -4
- package/src/v2/product/crop/cropInference.js +8 -4
- package/src/v2/product/crop/cropItem.d.ts +8 -4
- package/src/v2/product/crop/cropItem.js +9 -5
- package/src/v2/product/crop/cropResponse.d.ts +4 -2
- package/src/v2/product/crop/cropResponse.js +4 -2
- package/src/v2/product/crop/cropResult.d.ts +7 -3
- package/src/v2/product/crop/cropResult.js +8 -4
- package/src/v2/product/crop/params/cropParameters.d.ts +1 -1
- package/src/v2/product/crop/params/cropParameters.js +1 -1
- package/src/v2/product/extraction/dataSchemaActiveOption.d.ts +3 -1
- package/src/v2/product/extraction/dataSchemaActiveOption.js +3 -1
- package/src/v2/product/extraction/extraction.d.ts +25 -5
- package/src/v2/product/extraction/extraction.js +32 -6
- package/src/v2/product/extraction/extractionActiveOptions.d.ts +6 -2
- package/src/v2/product/extraction/extractionActiveOptions.js +6 -2
- package/src/v2/product/extraction/extractionInference.d.ts +7 -3
- package/src/v2/product/extraction/extractionInference.js +7 -3
- package/src/v2/product/extraction/extractionResponse.d.ts +4 -2
- package/src/v2/product/extraction/extractionResponse.js +4 -2
- package/src/v2/product/extraction/extractionResult.d.ts +9 -5
- package/src/v2/product/extraction/extractionResult.js +9 -5
- package/src/v2/product/extraction/index.d.ts +1 -0
- package/src/v2/product/extraction/index.js +1 -0
- package/src/v2/product/extraction/params/dataSchema.d.ts +12 -4
- package/src/v2/product/extraction/params/dataSchema.js +6 -2
- package/src/v2/product/extraction/params/dataSchemaField.d.ts +39 -13
- package/src/v2/product/extraction/params/dataSchemaField.js +9 -3
- package/src/v2/product/extraction/params/dataSchemaReplace.d.ts +12 -4
- package/src/v2/product/extraction/params/dataSchemaReplace.js +6 -2
- package/src/v2/product/extraction/params/extractionParameters.d.ts +1 -1
- package/src/v2/product/extraction/params/extractionParameters.js +4 -4
- package/src/v2/product/extraction/ragDocuments/annotatedBaseField.d.ts +20 -0
- package/src/v2/product/extraction/ragDocuments/annotatedBaseField.js +15 -0
- package/src/v2/product/extraction/ragDocuments/annotatedFields.d.ts +27 -0
- package/src/v2/product/extraction/ragDocuments/annotatedFields.js +57 -0
- package/src/v2/product/extraction/ragDocuments/annotatedListField.d.ts +26 -0
- package/src/v2/product/extraction/ragDocuments/annotatedListField.js +69 -0
- package/src/v2/product/extraction/ragDocuments/annotatedObjectField.d.ts +43 -0
- package/src/v2/product/extraction/ragDocuments/annotatedObjectField.js +47 -0
- package/src/v2/product/extraction/ragDocuments/annotatedSimpleField.d.ts +15 -0
- package/src/v2/product/extraction/ragDocuments/annotatedSimpleField.js +13 -0
- package/src/v2/product/extraction/ragDocuments/extractionRagAnnotationResponse.d.ts +25 -0
- package/src/v2/product/extraction/ragDocuments/extractionRagAnnotationResponse.js +17 -0
- package/src/v2/product/extraction/ragDocuments/fieldFactory.d.ts +12 -0
- package/src/v2/product/extraction/ragDocuments/fieldFactory.js +23 -0
- package/src/v2/product/extraction/ragDocuments/index.d.ts +7 -0
- package/src/v2/product/extraction/ragDocuments/index.js +7 -0
- package/src/v2/product/extraction/ragDocuments/params/index.d.ts +2 -0
- package/src/v2/product/extraction/ragDocuments/params/index.js +2 -0
- package/src/v2/product/extraction/ragDocuments/params/ragDocumentAnnotationParameters.d.ts +27 -0
- package/src/v2/product/extraction/ragDocuments/params/ragDocumentAnnotationParameters.js +43 -0
- package/src/v2/product/extraction/ragDocuments/params/ragDocumentUploadParameters.d.ts +7 -0
- package/src/v2/product/extraction/ragDocuments/params/ragDocumentUploadParameters.js +9 -0
- package/src/v2/product/extraction/ragDocuments/ragAnnotation.d.ts +12 -0
- package/src/v2/product/extraction/ragDocuments/ragAnnotation.js +9 -0
- package/src/v2/product/ocr/ocr.d.ts +10 -4
- package/src/v2/product/ocr/ocr.js +10 -4
- package/src/v2/product/ocr/ocrInference.d.ts +8 -4
- package/src/v2/product/ocr/ocrInference.js +8 -4
- package/src/v2/product/ocr/ocrPage.d.ts +6 -2
- package/src/v2/product/ocr/ocrPage.js +6 -2
- package/src/v2/product/ocr/ocrResponse.d.ts +4 -2
- package/src/v2/product/ocr/ocrResponse.js +4 -2
- package/src/v2/product/ocr/ocrResult.d.ts +3 -1
- package/src/v2/product/ocr/ocrResult.js +3 -1
- package/src/v2/product/ocr/ocrWord.d.ts +6 -2
- package/src/v2/product/ocr/ocrWord.js +6 -2
- package/src/v2/product/ocr/params/ocrParameters.d.ts +1 -1
- package/src/v2/product/ocr/params/ocrParameters.js +1 -1
- package/src/v2/product/split/params/splitParameters.d.ts +1 -1
- package/src/v2/product/split/params/splitParameters.js +1 -1
- package/src/v2/product/split/split.d.ts +10 -4
- package/src/v2/product/split/split.js +10 -4
- package/src/v2/product/split/splitInference.d.ts +7 -3
- package/src/v2/product/split/splitInference.js +7 -3
- package/src/v2/product/split/splitRange.d.ts +4 -2
- package/src/v2/product/split/splitRange.js +5 -3
- package/src/v2/product/split/splitResponse.d.ts +4 -2
- package/src/v2/product/split/splitResponse.js +4 -2
- package/src/v2/product/split/splitResult.d.ts +3 -1
- package/src/v2/product/split/splitResult.js +4 -2
- package/src/v2/search/baseSearch.d.ts +11 -5
- package/src/v2/search/baseSearch.js +9 -3
- package/src/v2/search/models/modelSearch.d.ts +12 -6
- package/src/v2/search/models/modelSearch.js +12 -6
- package/src/v2/search/models/modelSearchParameters.d.ts +4 -2
- package/src/v2/search/models/modelSearchParameters.js +4 -2
- package/src/v2/search/models/modelSearchResponse.d.ts +2 -2
- package/src/v2/search/models/modelSearchResponse.js +2 -2
- package/src/v2/search/ragDocuments/ragDocumentSearch.d.ts +12 -6
- package/src/v2/search/ragDocuments/ragDocumentSearch.js +12 -6
- package/src/v2/search/ragDocuments/ragDocumentSearchParameters.d.ts +4 -2
- package/src/v2/search/ragDocuments/ragDocumentSearchParameters.js +4 -2
- package/src/v2/search/ragDocuments/ragDocumentSearchResponse.d.ts +2 -2
- package/src/v2/search/ragDocuments/ragDocumentSearchResponse.js +2 -2
package/src/input/urlInput.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { randomBytes } from "crypto";
|
|
5
|
-
import { writeFile } from "fs/promises";
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { randomBytes } from "node:crypto";
|
|
3
|
+
import { writeFile } from "node:fs/promises";
|
|
6
4
|
import { request } from "undici";
|
|
5
|
+
import { URL } from "node:url";
|
|
6
|
+
import { InputSource } from "./inputSource.js";
|
|
7
7
|
import { logger } from "../logger.js";
|
|
8
8
|
import { MindeeInputSourceError } from "../errors/index.js";
|
|
9
9
|
import { resolveDefaultDispatcher } from "../http/dispatcher.js";
|
|
10
10
|
import { BytesInput } from "./bytesInput.js";
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* Remote input source represented by a validated HTTPS URL.
|
|
13
|
+
*/
|
|
12
14
|
export class UrlInput extends InputSource {
|
|
13
15
|
constructor({ url, dispatcher }) {
|
|
14
16
|
super();
|
|
@@ -16,7 +18,9 @@ export class UrlInput extends InputSource {
|
|
|
16
18
|
this.dispatcher = dispatcher ?? resolveDefaultDispatcher();
|
|
17
19
|
logger.debug("Initialized URL input source.");
|
|
18
20
|
}
|
|
19
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Initializes this source by validating and storing the URL.
|
|
23
|
+
*/
|
|
20
24
|
async init() {
|
|
21
25
|
if (this.initialized) {
|
|
22
26
|
return;
|
|
@@ -52,7 +56,9 @@ export class UrlInput extends InputSource {
|
|
|
52
56
|
}
|
|
53
57
|
return await this.makeRequest(this.url, headers, 0, maxRedirects);
|
|
54
58
|
}
|
|
55
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* Downloads the URL content and writes it to disk.
|
|
61
|
+
*/
|
|
56
62
|
async saveToFile(options) {
|
|
57
63
|
const { filepath, filename, ...fetchOptions } = options;
|
|
58
64
|
const { content, finalUrl } = await this.fetchFileContent(fetchOptions);
|
|
@@ -61,7 +67,9 @@ export class UrlInput extends InputSource {
|
|
|
61
67
|
await writeFile(fullPath, content);
|
|
62
68
|
return fullPath;
|
|
63
69
|
}
|
|
64
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* Downloads the URL content and returns it as a local bytes source.
|
|
72
|
+
*/
|
|
65
73
|
async asLocalInputSource(options = {}) {
|
|
66
74
|
const { filename, ...fetchOptions } = options;
|
|
67
75
|
const { content, finalUrl } = await this.fetchFileContent(fetchOptions);
|
|
@@ -69,7 +77,7 @@ export class UrlInput extends InputSource {
|
|
|
69
77
|
return new BytesInput({ inputBytes: content, filename: finalFilename });
|
|
70
78
|
}
|
|
71
79
|
static extractFilenameFromUrl(uri) {
|
|
72
|
-
return basename(new URL(uri).pathname || "");
|
|
80
|
+
return path.basename(new URL(uri).pathname || "");
|
|
73
81
|
}
|
|
74
82
|
static generateFileName(extension = ".tmp") {
|
|
75
83
|
const randomString = randomBytes(4).toString("hex");
|
|
@@ -77,14 +85,14 @@ export class UrlInput extends InputSource {
|
|
|
77
85
|
return `mindee_temp_${timestamp}_${randomString}${extension}`;
|
|
78
86
|
}
|
|
79
87
|
static getFileExtension(filename) {
|
|
80
|
-
const ext = extname(filename);
|
|
88
|
+
const ext = path.extname(filename);
|
|
81
89
|
return ext ? ext.toLowerCase() : null;
|
|
82
90
|
}
|
|
83
91
|
fillFilename(filename, finalUrl) {
|
|
84
92
|
if (!filename) {
|
|
85
93
|
filename = finalUrl ? UrlInput.extractFilenameFromUrl(finalUrl) : UrlInput.extractFilenameFromUrl(this.url);
|
|
86
94
|
}
|
|
87
|
-
if (!filename || !extname(filename)) {
|
|
95
|
+
if (!filename || !path.extname(filename)) {
|
|
88
96
|
filename = UrlInput.generateFileName(UrlInput.getFileExtension(filename || "") || undefined);
|
|
89
97
|
}
|
|
90
98
|
return filename;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import { StringDict } from "./stringDict.js";
|
|
3
3
|
/**
|
|
4
4
|
* Local response loaded from a file.
|
|
5
5
|
* Note: Has to be initialized through init() before use.
|
|
@@ -7,13 +7,17 @@ import { Buffer } from "buffer";
|
|
|
7
7
|
export declare abstract class BaseLocalResponse {
|
|
8
8
|
private fileBytes;
|
|
9
9
|
private readonly inputHandle;
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Whether the local response payload has been loaded.
|
|
12
|
+
*/
|
|
11
13
|
protected initialized: boolean;
|
|
12
14
|
/**
|
|
13
15
|
* Creates an instance of LocalResponse.
|
|
14
16
|
*/
|
|
15
17
|
constructor(inputFile: Buffer | string);
|
|
16
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Loads the local payload from a string, buffer, or file path.
|
|
20
|
+
*/
|
|
17
21
|
init(): Promise<void>;
|
|
18
22
|
/**
|
|
19
23
|
* Returns the dictionary representation of the file.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import * as crypto from "node:crypto";
|
|
2
3
|
import * as fs from "node:fs/promises";
|
|
3
4
|
import { MindeeError } from "../errors/index.js";
|
|
4
|
-
import { Buffer } from "buffer";
|
|
5
5
|
/**
|
|
6
6
|
* Local response loaded from a file.
|
|
7
7
|
* Note: Has to be initialized through init() before use.
|
|
@@ -11,18 +11,22 @@ export class BaseLocalResponse {
|
|
|
11
11
|
* Creates an instance of LocalResponse.
|
|
12
12
|
*/
|
|
13
13
|
constructor(inputFile) {
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Whether the local response payload has been loaded.
|
|
16
|
+
*/
|
|
15
17
|
this.initialized = false;
|
|
16
18
|
if (inputFile === undefined || inputFile === null) {
|
|
17
19
|
throw new TypeError("input cannot be null or undefined");
|
|
18
20
|
}
|
|
19
|
-
if (typeof inputFile === "string" ? !inputFile.trim() :
|
|
21
|
+
if (typeof inputFile === "string" ? !inputFile.trim() : inputFile.length === 0) {
|
|
20
22
|
throw new TypeError("input cannot be empty");
|
|
21
23
|
}
|
|
22
24
|
this.fileBytes = Buffer.alloc(0);
|
|
23
25
|
this.inputHandle = inputFile;
|
|
24
26
|
}
|
|
25
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Loads the local payload from a string, buffer, or file path.
|
|
29
|
+
*/
|
|
26
30
|
async init() {
|
|
27
31
|
/**
|
|
28
32
|
* @param inputFile - The input file, which can be a Buffer, string, or PathLike.
|
|
@@ -37,12 +41,12 @@ export class BaseLocalResponse {
|
|
|
37
41
|
let fileContents;
|
|
38
42
|
try {
|
|
39
43
|
await fs.access(this.inputHandle);
|
|
40
|
-
fileContents = await fs.readFile(this.inputHandle, { encoding: "
|
|
44
|
+
fileContents = await fs.readFile(this.inputHandle, { encoding: "utf8" });
|
|
41
45
|
}
|
|
42
46
|
catch {
|
|
43
47
|
fileContents = this.inputHandle;
|
|
44
48
|
}
|
|
45
|
-
this.fileBytes = Buffer.from(fileContents.replace(/\r/g, "").replace(/\n/g, ""), "
|
|
49
|
+
this.fileBytes = Buffer.from(fileContents.replace(/\r/g, "").replace(/\n/g, ""), "utf8");
|
|
46
50
|
}
|
|
47
51
|
else {
|
|
48
52
|
throw new MindeeError("Incompatible type for input.");
|
|
@@ -58,7 +62,7 @@ export class BaseLocalResponse {
|
|
|
58
62
|
await this.init();
|
|
59
63
|
}
|
|
60
64
|
try {
|
|
61
|
-
const content = this.fileBytes.toString("
|
|
65
|
+
const content = this.fileBytes.toString("utf8");
|
|
62
66
|
return JSON.parse(content);
|
|
63
67
|
}
|
|
64
68
|
catch {
|
|
@@ -102,8 +106,8 @@ export class BaseLocalResponse {
|
|
|
102
106
|
if (!expectedSignature?.trim()) {
|
|
103
107
|
return false;
|
|
104
108
|
}
|
|
105
|
-
const expectedBytes = Buffer.from(expectedSignature, "
|
|
106
|
-
const actualBytes = Buffer.from(signature.toLowerCase(), "
|
|
109
|
+
const expectedBytes = Buffer.from(expectedSignature, "utf8");
|
|
110
|
+
const actualBytes = Buffer.from(signature.toLowerCase(), "utf8");
|
|
107
111
|
if (expectedBytes.length !== actualBytes.length) {
|
|
108
112
|
return false;
|
|
109
113
|
}
|
|
@@ -113,6 +117,6 @@ export class BaseLocalResponse {
|
|
|
113
117
|
* Print the file as a UTF-8 string.
|
|
114
118
|
*/
|
|
115
119
|
toString() {
|
|
116
|
-
return this.fileBytes.toString("
|
|
120
|
+
return this.fileBytes.toString("utf8");
|
|
117
121
|
}
|
|
118
122
|
}
|
|
@@ -1,14 +1,24 @@
|
|
|
1
|
-
import { BufferInput } from "../input/index.js";
|
|
2
1
|
import { Buffer } from "node:buffer";
|
|
3
|
-
|
|
2
|
+
import { BufferInput } from "../input/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Represents a PDF artifact produced by an extraction/splitting operation.
|
|
5
|
+
*/
|
|
4
6
|
export declare class ExtractedPdf {
|
|
5
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* Raw bytes of the extracted PDF segment.
|
|
9
|
+
*/
|
|
6
10
|
readonly buffer: Buffer;
|
|
7
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* Filename suggested for export.
|
|
13
|
+
*/
|
|
8
14
|
readonly filename: string;
|
|
9
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Number of pages in this extracted PDF.
|
|
17
|
+
*/
|
|
10
18
|
readonly pageCount: number;
|
|
11
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Zero-based indexes of pages included in this extracted PDF.
|
|
21
|
+
*/
|
|
12
22
|
readonly pageIndexes: number[];
|
|
13
23
|
constructor(pdfData: Buffer<ArrayBufferLike>, filename: string, pageIndexes: number[]);
|
|
14
24
|
/**
|
package/src/pdf/extractedPdf.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { writeFileSync } from "node:fs";
|
|
3
|
+
import { writeFile } from "node:fs/promises";
|
|
2
4
|
import { BufferInput, MIMETYPES } from "../input/index.js";
|
|
3
5
|
import { MindeeError } from "../errors/index.js";
|
|
4
|
-
import { writeFile } from "fs/promises";
|
|
5
6
|
import { logger } from "../logger.js";
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Represents a PDF artifact produced by an extraction/splitting operation.
|
|
9
|
+
*/
|
|
8
10
|
export class ExtractedPdf {
|
|
9
11
|
constructor(pdfData, filename, pageIndexes) {
|
|
10
12
|
this.buffer = pdfData;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { ExtractedPdf } from "
|
|
2
|
-
/**
|
|
1
|
+
import { ExtractedPdf } from "./extractedPdf.js";
|
|
2
|
+
/**
|
|
3
|
+
* Collection of extracted PDF artifacts.
|
|
4
|
+
*/
|
|
3
5
|
export declare class ExtractedPdfs extends Array<ExtractedPdf> {
|
|
4
6
|
constructor(...items: ExtractedPdf[]);
|
|
5
7
|
}
|
package/src/pdf/extractedPdfs.js
CHANGED
package/src/pdf/pdfCompressor.js
CHANGED
|
@@ -80,8 +80,8 @@ async function compressPdfPages(pdfData, extractedPdfInfo, imageQuality, disable
|
|
|
80
80
|
* @returns A Promise resolving to an array of compressed page buffers.
|
|
81
81
|
*/
|
|
82
82
|
async function compressPagesWithQuality(pdfData, extractedPdfInfo, imageQuality, disableSourceText, extractedText) {
|
|
83
|
-
const
|
|
84
|
-
const pdfDoc = await
|
|
83
|
+
const currentPdfLib = await getPdfLib();
|
|
84
|
+
const pdfDoc = await currentPdfLib.PDFDocument.load(pdfData, {
|
|
85
85
|
ignoreEncryption: true,
|
|
86
86
|
password: ""
|
|
87
87
|
});
|
|
@@ -126,19 +126,19 @@ function isCompressionSuccessful(totalCompressedSize, originalSize, imageQuality
|
|
|
126
126
|
* @returns A Promise resolving to the new PDF as a Buffer.
|
|
127
127
|
*/
|
|
128
128
|
async function createNewPdfFromCompressedPages(compressedPages) {
|
|
129
|
-
const
|
|
130
|
-
const
|
|
129
|
+
const currentPdfLib = await getPdfLib();
|
|
130
|
+
const pdfDocument = await currentPdfLib.PDFDocument.create();
|
|
131
131
|
for (const compressedPage of compressedPages) {
|
|
132
|
-
const image = await
|
|
133
|
-
const
|
|
134
|
-
|
|
132
|
+
const image = await pdfDocument.embedJpg(compressedPage);
|
|
133
|
+
const pdfPage = pdfDocument.addPage([image.width, image.height]);
|
|
134
|
+
pdfPage.drawImage(image, {
|
|
135
135
|
x: 0,
|
|
136
136
|
y: 0,
|
|
137
137
|
width: image.width,
|
|
138
138
|
height: image.height,
|
|
139
139
|
});
|
|
140
140
|
}
|
|
141
|
-
const compressedPdfBytes = await
|
|
141
|
+
const compressedPdfBytes = await pdfDocument.save();
|
|
142
142
|
return Buffer.from(compressedPdfBytes);
|
|
143
143
|
}
|
|
144
144
|
/**
|
|
@@ -150,14 +150,14 @@ async function addTextToPdfPage(page, textInfo) {
|
|
|
150
150
|
if (textInfo === null) {
|
|
151
151
|
return;
|
|
152
152
|
}
|
|
153
|
-
const
|
|
153
|
+
const currentPdfLib = await getPdfLib();
|
|
154
154
|
for (const textPages of textInfo.pages) {
|
|
155
155
|
for (const textPage of textPages.content) {
|
|
156
156
|
page.drawText(textPage.str, {
|
|
157
157
|
x: textPage.x,
|
|
158
158
|
y: textPage.y,
|
|
159
159
|
size: textPage.height,
|
|
160
|
-
color:
|
|
160
|
+
color: currentPdfLib.rgb(0, 0, 0),
|
|
161
161
|
font: await getFontFromName(textPage.fontName)
|
|
162
162
|
});
|
|
163
163
|
}
|
|
@@ -168,15 +168,15 @@ async function addTextToPdfPage(page, textInfo) {
|
|
|
168
168
|
* @param fontName The name of the font to get.
|
|
169
169
|
*/
|
|
170
170
|
async function getFontFromName(fontName) {
|
|
171
|
-
const
|
|
172
|
-
const pdfDoc = await
|
|
171
|
+
const currentPdfLib = await getPdfLib();
|
|
172
|
+
const pdfDoc = await currentPdfLib.PDFDocument.create();
|
|
173
173
|
let font;
|
|
174
|
-
const standardFontValues = Object.values(
|
|
174
|
+
const standardFontValues = Object.values(currentPdfLib.StandardFonts);
|
|
175
175
|
if (standardFontValues.includes(fontName)) {
|
|
176
176
|
font = await pdfDoc.embedFont(fontName);
|
|
177
177
|
}
|
|
178
178
|
else {
|
|
179
|
-
font = await pdfDoc.embedFont(
|
|
179
|
+
font = await pdfDoc.embedFont(currentPdfLib.StandardFonts.Helvetica);
|
|
180
180
|
}
|
|
181
181
|
return font;
|
|
182
182
|
}
|
package/src/pdf/pdfExtractor.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import path from "node:path";
|
|
1
2
|
import { PageOptionsOperation, PathInput } from "../input/index.js";
|
|
2
3
|
import { logger } from "../logger.js";
|
|
3
|
-
import path from "path";
|
|
4
4
|
import { loadOptionalDependency } from "../dependency/index.js";
|
|
5
5
|
import { MindeeInputSourceError, MindeePdfError } from "../errors/index.js";
|
|
6
|
-
import { ExtractedPdf } from "
|
|
7
|
-
import { createPdfFromInputSource, extractPages } from "
|
|
6
|
+
import { ExtractedPdf } from "./extractedPdf.js";
|
|
7
|
+
import { createPdfFromInputSource, extractPages } from "./pdfOperation.js";
|
|
8
8
|
let pdfLib = null;
|
|
9
9
|
/**
|
|
10
10
|
* Load the PDF library if not already loaded.
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import type * as pdfLibTypes from "@cantoo/pdf-lib";
|
|
2
2
|
import { PageOptions } from "../input/pageOptions.js";
|
|
3
3
|
import { LocalInputSource } from "../input/index.js";
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Result of a PDF split/extract operation.
|
|
6
|
+
*/
|
|
5
7
|
export interface SplitPdf {
|
|
6
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* PDF content after page extraction.
|
|
10
|
+
*/
|
|
7
11
|
file: Buffer;
|
|
8
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Number of pages removed from the source PDF.
|
|
14
|
+
*/
|
|
9
15
|
totalPagesRemoved: number;
|
|
10
16
|
}
|
|
11
17
|
/**
|
package/src/pdf/pdfOperation.js
CHANGED
|
@@ -21,12 +21,12 @@ async function getPdfLib() {
|
|
|
21
21
|
* @returns the new cut PDF file.
|
|
22
22
|
*/
|
|
23
23
|
export async function extractPages(file, pageOptions) {
|
|
24
|
-
const
|
|
25
|
-
const currentPdf = await
|
|
24
|
+
const currentPdfLib = await getPdfLib();
|
|
25
|
+
const currentPdf = await currentPdfLib.PDFDocument.load(file, {
|
|
26
26
|
ignoreEncryption: true,
|
|
27
27
|
password: ""
|
|
28
28
|
});
|
|
29
|
-
const
|
|
29
|
+
const pdfDocument = await currentPdfLib.PDFDocument.create();
|
|
30
30
|
const pageCount = currentPdf.getPageCount();
|
|
31
31
|
if (pageCount < pageOptions.onMinPages) {
|
|
32
32
|
logger.debug(`File skipped because it had less than ${pageOptions} pages (${pageCount}).`);
|
|
@@ -53,25 +53,25 @@ export async function extractPages(file, pageOptions) {
|
|
|
53
53
|
(${currentPdf.getPageIndices().join(", ")})`));
|
|
54
54
|
}
|
|
55
55
|
if (pageOptions.operation === PageOptionsOperation.KeepOnly) {
|
|
56
|
-
const keptPages = await
|
|
56
|
+
const keptPages = await pdfDocument.copyPages(currentPdf, pageIndexes);
|
|
57
57
|
keptPages.forEach((keptPage) => {
|
|
58
|
-
|
|
58
|
+
pdfDocument.addPage(keptPage);
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
else if (pageOptions.operation === PageOptionsOperation.Remove) {
|
|
62
62
|
const pagesToKeep = currentPdf
|
|
63
63
|
.getPageIndices()
|
|
64
64
|
.filter((v) => !pageIndexes.includes(v));
|
|
65
|
-
const keptPages = await
|
|
65
|
+
const keptPages = await pdfDocument.copyPages(currentPdf, pagesToKeep);
|
|
66
66
|
keptPages.forEach((keptPage) => {
|
|
67
|
-
|
|
67
|
+
pdfDocument.addPage(keptPage);
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
70
|
else {
|
|
71
71
|
throw new Error(`The operation ${pageOptions.operation} is not available.`);
|
|
72
72
|
}
|
|
73
|
-
const sumRemovedPages = pageCount -
|
|
74
|
-
const fileBuffer = Buffer.from(await
|
|
73
|
+
const sumRemovedPages = pageCount - pdfDocument.getPageCount();
|
|
74
|
+
const fileBuffer = Buffer.from(await pdfDocument.save());
|
|
75
75
|
return { file: fileBuffer, totalPagesRemoved: sumRemovedPages };
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
@@ -80,8 +80,8 @@ export async function extractPages(file, pageOptions) {
|
|
|
80
80
|
* @returns the number of pages in the file.
|
|
81
81
|
*/
|
|
82
82
|
export async function countPages(file) {
|
|
83
|
-
const
|
|
84
|
-
const currentPdf = await
|
|
83
|
+
const currentPdfLib = await getPdfLib();
|
|
84
|
+
const currentPdf = await currentPdfLib.PDFDocument.load(file, {
|
|
85
85
|
ignoreEncryption: true,
|
|
86
86
|
password: ""
|
|
87
87
|
});
|
|
@@ -92,7 +92,7 @@ export async function countPages(file) {
|
|
|
92
92
|
* @param inputSource The input source to create a PDF from.
|
|
93
93
|
*/
|
|
94
94
|
export async function createPdfFromInputSource(inputSource) {
|
|
95
|
-
const
|
|
95
|
+
const currentPdfLib = await getPdfLib();
|
|
96
96
|
let pdfDoc;
|
|
97
97
|
if (!["image/jpeg", "image/jpg", "image/png", "application/pdf"].includes(inputSource.mimeType)) {
|
|
98
98
|
throw new MindeeInputSourceError('Unsupported file type "' +
|
|
@@ -100,13 +100,13 @@ export async function createPdfFromInputSource(inputSource) {
|
|
|
100
100
|
'" Currently supported types are .png, .jpg and .pdf');
|
|
101
101
|
}
|
|
102
102
|
else if (inputSource.isPdf()) {
|
|
103
|
-
pdfDoc = await
|
|
103
|
+
pdfDoc = await currentPdfLib.PDFDocument.load(inputSource.fileObject, {
|
|
104
104
|
ignoreEncryption: true,
|
|
105
105
|
password: ""
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
108
|
else {
|
|
109
|
-
pdfDoc = await
|
|
109
|
+
pdfDoc = await currentPdfLib.PDFDocument.create();
|
|
110
110
|
let image;
|
|
111
111
|
if (inputSource.mimeType === "image/png") {
|
|
112
112
|
image = await pdfDoc.embedPng(inputSource.fileObject);
|
package/src/pdf/pdfUtils.js
CHANGED
package/src/v1/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PageOptionsOperation, PathInput } from "../input/index.js";
|
|
2
2
|
import { Command, Option } from "commander";
|
|
3
|
-
import * as console from "console";
|
|
3
|
+
import * as console from "node:console";
|
|
4
4
|
import { Client } from "./client.js";
|
|
5
5
|
import { CLI_COMMAND_CONFIG, COMMAND_GENERATED } from "./product/cliProducts.js";
|
|
6
6
|
const program = new Command();
|
package/src/v1/client.d.ts
CHANGED
|
@@ -25,7 +25,9 @@ interface BaseOptions {
|
|
|
25
25
|
* Options relating to predictions.
|
|
26
26
|
*/
|
|
27
27
|
export interface PredictOptions extends BaseOptions {
|
|
28
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* A custom endpoint.
|
|
30
|
+
*/
|
|
29
31
|
endpoint?: Endpoint;
|
|
30
32
|
/**
|
|
31
33
|
* Whether to include the full text for each page.
|
|
@@ -60,26 +62,42 @@ export interface WorkflowOptions extends BaseOptions {
|
|
|
60
62
|
*/
|
|
61
63
|
publicUrl?: string;
|
|
62
64
|
}
|
|
63
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* Timer options forwarded to `setTimeout` in polling loops.
|
|
67
|
+
*/
|
|
64
68
|
export interface TimerOptions {
|
|
65
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* Whether the timer should keep the event loop active.
|
|
71
|
+
*/
|
|
66
72
|
ref?: boolean;
|
|
67
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* Optional signal used to abort timer waits.
|
|
75
|
+
*/
|
|
68
76
|
signal?: AbortSignal;
|
|
69
77
|
}
|
|
70
78
|
/**
|
|
71
79
|
* Asynchronous polling parameters.
|
|
72
80
|
*/
|
|
73
81
|
export interface OptionalAsyncOptions extends PredictOptions {
|
|
74
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* Delay in seconds before the first polling attempt.
|
|
84
|
+
*/
|
|
75
85
|
initialDelaySec?: number;
|
|
76
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* Delay in seconds between polling attempts.
|
|
88
|
+
*/
|
|
77
89
|
delaySec?: number;
|
|
78
|
-
/**
|
|
90
|
+
/**
|
|
91
|
+
* Maximum number of polling attempts.
|
|
92
|
+
*/
|
|
79
93
|
maxRetries?: number;
|
|
80
|
-
/**
|
|
94
|
+
/**
|
|
95
|
+
* Timer options used for the first delay.
|
|
96
|
+
*/
|
|
81
97
|
initialTimerOptions?: TimerOptions;
|
|
82
|
-
/**
|
|
98
|
+
/**
|
|
99
|
+
* Timer options used for recurring polling delays.
|
|
100
|
+
*/
|
|
83
101
|
recurringTimerOptions?: TimerOptions;
|
|
84
102
|
}
|
|
85
103
|
export interface AsyncOptions extends PredictOptions {
|
|
@@ -90,13 +108,21 @@ export interface AsyncOptions extends PredictOptions {
|
|
|
90
108
|
recurringTimerOptions?: TimerOptions;
|
|
91
109
|
}
|
|
92
110
|
export interface ClientOptions {
|
|
93
|
-
/**
|
|
111
|
+
/**
|
|
112
|
+
* Your API key for all endpoints.
|
|
113
|
+
*/
|
|
94
114
|
apiKey?: string;
|
|
95
|
-
/**
|
|
115
|
+
/**
|
|
116
|
+
* Raise an `Error` on errors.
|
|
117
|
+
*/
|
|
96
118
|
throwOnError?: boolean;
|
|
97
|
-
/**
|
|
119
|
+
/**
|
|
120
|
+
* Log debug messages.
|
|
121
|
+
*/
|
|
98
122
|
debug?: boolean;
|
|
99
|
-
/**
|
|
123
|
+
/**
|
|
124
|
+
* Custom dispatcher for HTTP requests.
|
|
125
|
+
*/
|
|
100
126
|
dispatcher?: Dispatcher;
|
|
101
127
|
}
|
|
102
128
|
/**
|
|
@@ -106,7 +132,9 @@ export interface ClientOptions {
|
|
|
106
132
|
*/
|
|
107
133
|
export declare class Client {
|
|
108
134
|
#private;
|
|
109
|
-
/**
|
|
135
|
+
/**
|
|
136
|
+
* Mindee V1 API settings.
|
|
137
|
+
*/
|
|
110
138
|
protected apiSettings: ApiSettingsV1;
|
|
111
139
|
/**
|
|
112
140
|
* @param {ClientOptions} options options for the initialization of a client.
|
package/src/v1/client.js
CHANGED
|
@@ -252,20 +252,20 @@ _Client_instances = new WeakSet(), _Client_setAsyncParams = function _Client_set
|
|
|
252
252
|
const minDelaySec = 1;
|
|
253
253
|
const minInitialDelay = 1;
|
|
254
254
|
const minRetries = 2;
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
if (
|
|
255
|
+
const asyncParamsInstance = { ...asyncParams };
|
|
256
|
+
asyncParamsInstance.delaySec ??= 1.5;
|
|
257
|
+
asyncParamsInstance.initialDelaySec ??= 2;
|
|
258
|
+
asyncParamsInstance.maxRetries ??= 80;
|
|
259
|
+
if (asyncParamsInstance.delaySec < minDelaySec) {
|
|
260
260
|
throw Error(`Cannot set auto-parsing delay to less than ${minDelaySec} second(s).`);
|
|
261
261
|
}
|
|
262
|
-
if (
|
|
262
|
+
if (asyncParamsInstance.initialDelaySec < minInitialDelay) {
|
|
263
263
|
throw Error(`Cannot set initial parsing delay to less than ${minInitialDelay} second(s).`);
|
|
264
264
|
}
|
|
265
|
-
if (
|
|
265
|
+
if (asyncParamsInstance.maxRetries < minRetries) {
|
|
266
266
|
throw Error(`Cannot set retry to less than ${minRetries}.`);
|
|
267
267
|
}
|
|
268
|
-
return
|
|
268
|
+
return asyncParamsInstance;
|
|
269
269
|
}, _Client_buildProductEndpoint = function _Client_buildProductEndpoint(endpointName, accountName, endpointVersion) {
|
|
270
270
|
return new Endpoint(endpointName, accountName, endpointVersion, this.apiSettings);
|
|
271
271
|
}, _Client_initializeOTSEndpoint = function _Client_initializeOTSEndpoint(productClass) {
|
|
@@ -3,9 +3,13 @@ import { ExtractedPdf } from "../../../pdf/index.js";
|
|
|
3
3
|
* Wrapper class for extracted invoice pages.
|
|
4
4
|
*/
|
|
5
5
|
export declare class ExtractedInvoiceSplitterImage extends ExtractedPdf {
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Start page index of the extracted invoice segment.
|
|
8
|
+
*/
|
|
7
9
|
readonly pageIdMin: number;
|
|
8
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* End page index of the extracted invoice segment.
|
|
12
|
+
*/
|
|
9
13
|
readonly pageIdMax: number;
|
|
10
14
|
constructor(bytes: Uint8Array, pageIndices: [number, number]);
|
|
11
15
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { InvoiceSplitterV1 } from "
|
|
1
|
+
import { InvoiceSplitterV1 } from "../../product/index.js";
|
|
2
2
|
import { LocalInputSource } from "../../../input/index.js";
|
|
3
|
-
import { ExtractedInvoiceSplitterImage } from "
|
|
3
|
+
import { ExtractedInvoiceSplitterImage } from "../index.js";
|
|
4
4
|
/**
|
|
5
5
|
* Extracts & cuts the pages of a main document invoice according to the provided indexes.
|
|
6
6
|
*
|