Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/_test-integrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ jobs:
WORKFLOW_ID: ${{ secrets.WORKFLOW_ID_SE_TESTS }}
MINDEE_V2_API_KEY: ${{ secrets.MINDEE_V2_SE_TESTS_API_KEY }}
MINDEE_V2_FINDOC_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }}
MINDEE_V2_SE_TESTS_BLANK_PDF_URL: ${{ secrets.MINDEE_V2_SE_TESTS_BLANK_PDF_URL }}
run: npm run test-integration
120 changes: 60 additions & 60 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions src/clientV2.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
Base64Input, BufferInput, BytesInput,
LocalInputSource, PathInput, StreamInput, UrlInput,
Base64Input, BufferInput, BytesInput, InputSource,
PathInput, StreamInput, UrlInput,
} from "./input";
import { errorHandler } from "./errors/handler";
import { LOG_LEVELS, logger } from "./logger";
Expand Down Expand Up @@ -124,7 +124,7 @@ export interface ClientOptions {
* @category ClientV2
*/
export class ClientV2 {
/** Key of the API. */
/** Mindee API handler. */
protected mindeeApi: MindeeApiV2;

/**
Expand All @@ -148,13 +148,13 @@ export class ClientV2 {

/**
* Send the document to an asynchronous endpoint and return its ID in the queue.
* @param inputSource file to parse.
* @param inputSource file or URL to parse.
* @param params parameters relating to prediction options.
* @category Asynchronous
* @returns a `Promise` containing the job (queue) corresponding to a document.
*/
async enqueueInference(
inputSource: LocalInputSource,
inputSource: InputSource,
params: InferenceParameters
): Promise<JobResponse> {
if (inputSource === undefined) {
Expand Down Expand Up @@ -240,7 +240,7 @@ export class ClientV2 {
* @returns a `Promise` containing parsing results.
*/
async enqueueAndGetInference(
inputDoc: LocalInputSource,
inputDoc: InputSource,
params: InferenceParameters
): Promise<InferenceResponse> {
const validatedAsyncParams = this.#setAsyncParams(params.pollingOptions);
Expand Down
24 changes: 14 additions & 10 deletions src/http/mindeeApiV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { InferenceResponse, JobResponse } from "../parsing/v2";
import FormData from "form-data";
import { RequestOptions } from "https";
import { BaseEndpoint, EndpointResponse } from "./baseEndpoint";
import { LocalInputSource } from "../input";
import { InputSource, LocalInputSource, UrlInput } from "../input";
import { MindeeApiV2Error, MindeeHttpErrorV2 } from "../errors/mindeeError";
import { logger } from "../logger";

Expand All @@ -17,18 +17,18 @@ export class MindeeApiV2 {

/**
* Sends a file to the inference queue.
* @param inputDoc Local file loaded as an input.
* @param inputSource Local file loaded as an input.
* @param params {InferenceParameters} parameters relating to the enqueueing options.
* @category V2
* @throws Error if the server's response contains one.
* @returns a `Promise` containing a job response.
*/
async reqPostInferenceEnqueue(inputDoc: LocalInputSource, params: InferenceParameters): Promise<JobResponse> {
await inputDoc.init();
async reqPostInferenceEnqueue(inputSource: InputSource, params: InferenceParameters): Promise<JobResponse> {
await inputSource.init();
if (params.modelId === undefined || params.modelId === null || params.modelId === "") {
throw new Error("Model ID must be provided");
}
const result: EndpointResponse = await this.#documentEnqueuePost(inputDoc, params);
const result: EndpointResponse = await this.#documentEnqueuePost(inputSource, params);
if (result.data.error?.code !== undefined) {
throw new MindeeHttpErrorV2(
result.data.error.code,
Expand Down Expand Up @@ -86,10 +86,10 @@ export class MindeeApiV2 {
/**
* Sends a document to the inference queue.
*
* @param inputDoc Local file loaded as an input.
* @param inputSource Local or remote file as an input.
* @param params {InferenceParameters} parameters relating to the enqueueing options.
*/
#documentEnqueuePost(inputDoc: LocalInputSource, params: InferenceParameters): Promise<EndpointResponse> {
#documentEnqueuePost(inputSource: InputSource, params: InferenceParameters): Promise<EndpointResponse> {
const form = new FormData();

form.append("model_id", params.modelId);
Expand All @@ -99,9 +99,13 @@ export class MindeeApiV2 {
if (params.webhookIds && params.webhookIds.length > 0) {
form.append("webhook_ids", params.webhookIds.join(","));
}
form.append("file", inputDoc.fileObject, {
filename: inputDoc.filename,
});
if (inputSource instanceof LocalInputSource) {
form.append("file", inputSource.fileObject, {
filename: inputSource.filename,
});
} else {
form.append("url", (inputSource as UrlInput).url);
}
const path = "/v2/inferences/enqueue";
const headers = { ...this.settings.baseHeaders, ...form.getHeaders() };
const options: RequestOptions = {
Expand Down
2 changes: 1 addition & 1 deletion src/input/sources/urlInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IncomingMessage } from "http";
import { BytesInput } from "./bytesInput";

export class UrlInput extends InputSource {
private readonly url: string;
public readonly url: string;

constructor({ url }: { url: string }) {
super();
Expand Down
7 changes: 0 additions & 7 deletions src/parsing/v2/field/baseField.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import { FieldConfidence } from "./fieldConfidence";
import { FieldLocation } from "./fieldLocation";
import { StringDict } from "../../common";

export abstract class BaseField {
protected _indentLevel: number;
public locations: Array<FieldLocation> | undefined;
public confidence: FieldConfidence | undefined;

protected constructor(rawResponse: StringDict, indentLevel = 0) {
this._indentLevel = indentLevel;
if (rawResponse["locations"]) {
this.locations = rawResponse["locations"].map((location: StringDict | undefined) => {
return location ? new FieldLocation(location) : "";
});
}
if (rawResponse["confidence"] !== undefined) {
this.confidence = rawResponse["confidence"] as FieldConfidence;
}
Expand Down
17 changes: 17 additions & 0 deletions src/parsing/v2/field/dynamicField.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { BaseField } from "./baseField";
import { FieldLocation } from "./fieldLocation";
import { StringDict } from "../../common";


export class DynamicField extends BaseField {
public locations: Array<FieldLocation> | undefined;

constructor(rawResponse: StringDict, indentLevel = 0) {
super(rawResponse, indentLevel);
if (rawResponse["locations"]) {
this.locations = rawResponse["locations"].map((location: StringDict | undefined) => {
return location ? new FieldLocation(location) : "";
});
}
}
}
Loading
Loading