@@ -13,7 +13,7 @@ import {
1313 RequestOptions
1414} from "@/http/apiCore.js" ;
1515import { InputSource , LocalInputSource , UrlInput } from "@/input/index.js" ;
16- import { MindeeDeserializationError } from "@/errors/index.js" ;
16+ import { MindeeDeserializationError , MindeeError } from "@/errors/index.js" ;
1717import { MindeeHttpErrorV2 } from "./errors.js" ;
1818import { logger } from "@/logger.js" ;
1919import { BaseProduct } from "@/v2/product/baseProduct.js" ;
@@ -32,7 +32,7 @@ export class MindeeApiV2 {
3232 * @param inputSource Local file loaded as an input.
3333 * @param params {ExtractionParameters} parameters relating to the enqueueing options.
3434 * @category V2
35- * @throws Error if the server's response contains one .
35+ * @throws Error if the server's response contains an error .
3636 * @returns a `Promise` containing a job response.
3737 */
3838 async enqueueProduct (
@@ -52,7 +52,7 @@ export class MindeeApiV2 {
5252
5353 /**
5454 * Requests the results of a queued document from the API.
55- * Throws an error if the server's response contains one .
55+ * Throws an error if the server's response contains an error .
5656 * @param jobId The document's ID in the queue.
5757 * @category Asynchronous
5858 * @returns a `Promise` containing information on the queue.
@@ -64,22 +64,38 @@ export class MindeeApiV2 {
6464
6565 /**
6666 * Requests the job of a queued document from the API.
67- * Throws an error if the server's response contains one .
67+ * Throws an error if the server's response contains an error .
6868 * @param product
69- * @param inferenceId The document 's ID in the queue.
69+ * @param inferenceId The result 's ID in the queue.
7070 * @category Asynchronous
7171 * @returns a `Promise` containing either the parsed result, or information on the queue.
7272 */
73- async getProductResult < P extends typeof BaseProduct > (
73+ async getProductResultById < P extends typeof BaseProduct > (
7474 product : P ,
7575 inferenceId : string ,
7676 ) : Promise < InstanceType < P [ "responseClass" ] > > {
7777 const queueResponse : BaseHttpResponse = await this . #reqGetProductResult(
78- inferenceId , product . slug
78+ `https:// ${ this . settings . hostname } /v2/products/ ${ product . slug } /results/ ${ inferenceId } `
7979 ) ;
8080 return this . #processResponse( queueResponse , product . responseClass ) as InstanceType < P [ "responseClass" ] > ;
8181 }
8282
83+ /**
84+ * Requests the job of a queued document from the API.
85+ * Throws an error if the server's response contains an error.
86+ * @param product
87+ * @param url The document's ID in the queue.
88+ * @category Asynchronous
89+ * @returns a `Promise` containing either the parsed result, or information on the queue.
90+ */
91+ async getProductResultByUrl < P extends typeof BaseProduct > (
92+ product : P ,
93+ url : string ,
94+ ) : Promise < InstanceType < P [ "responseClass" ] > > {
95+ const queueResponse : BaseHttpResponse = await this . #reqGetProductResult( url ) ;
96+ return this . #processResponse( queueResponse , product . responseClass ) as InstanceType < P [ "responseClass" ] > ;
97+ }
98+
8399 #processResponse< T extends BaseResponse > (
84100 result : BaseHttpResponse ,
85101 responseClass : ResponseConstructor < T > ,
@@ -155,19 +171,19 @@ export class MindeeApiV2 {
155171
156172 /**
157173 * Make a request to GET the status of a document in the queue.
158- * @param inferenceId ID of the inference.
159- * @param slug "jobs" or "inferences"...
174+ * @param url URL path to the result.
160175 * @category Asynchronous
161- * @returns a `Promise` containing either the parsed result, or information on the queue .
176+ * @returns a `Promise` containing the parsed result.
162177 */
163- async #reqGetProductResult( inferenceId : string , slug : string ) : Promise < BaseHttpResponse > {
178+ async #reqGetProductResult( url : string ) : Promise < BaseHttpResponse > {
164179 const options : RequestOptions = {
165180 method : "GET" ,
166181 headers : this . settings . baseHeaders ,
167- hostname : this . settings . hostname ,
168- path : `/v2/products/${ slug } /results/${ inferenceId } ` ,
169182 timeoutSecs : this . settings . timeoutSecs ,
170183 } ;
171- return await sendRequestAndReadResponse ( this . settings . dispatcher , options ) ;
184+ if ( ! url . startsWith ( "https://" ) ) {
185+ throw new MindeeError ( "URL must start with https://" ) ;
186+ }
187+ return await sendRequestAndReadResponse ( this . settings . dispatcher , options , url ) ;
172188 }
173189}
0 commit comments