@retab/node 1.0.77 → 1.0.78
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/dist/api/client.d.ts +2 -0
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +2 -0
- package/dist/api/edit/client.d.ts +34 -0
- package/dist/api/edit/client.d.ts.map +1 -0
- package/dist/api/edit/client.js +43 -0
- package/dist/api/edit/templates/client.d.ts +125 -0
- package/dist/api/edit/templates/client.d.ts.map +1 -0
- package/dist/api/edit/templates/client.js +196 -0
- package/dist/client.js +1 -1
- package/dist/generated_types.d.ts +375 -236
- package/dist/generated_types.d.ts.map +1 -1
- package/dist/generated_types.js +27 -9
- package/dist/types.d.ts +296 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +10 -0
- package/package.json +1 -1
package/dist/api/client.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import APISchemas from "./schemas/client";
|
|
|
5
5
|
import APIProjects from "./projects/client";
|
|
6
6
|
import APIExtractions from "./extractions/client";
|
|
7
7
|
import APIWorkflows from "./workflows/client";
|
|
8
|
+
import APIEdit from "./edit/client";
|
|
8
9
|
export default class APIV1 extends CompositionClient {
|
|
9
10
|
constructor(client: AbstractClient);
|
|
10
11
|
models: APIModels;
|
|
@@ -13,5 +14,6 @@ export default class APIV1 extends CompositionClient {
|
|
|
13
14
|
projects: APIProjects;
|
|
14
15
|
extractions: APIExtractions;
|
|
15
16
|
workflows: APIWorkflows;
|
|
17
|
+
edit: APIEdit;
|
|
16
18
|
}
|
|
17
19
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/api/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,SAAS,MAAM,iBAAiB,CAAC;AACxC,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAC9C,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAC1C,OAAO,WAAW,MAAM,mBAAmB,CAAC;AAC5C,OAAO,cAAc,MAAM,sBAAsB,CAAC;AAClD,OAAO,YAAY,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,SAAS,MAAM,iBAAiB,CAAC;AACxC,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAC9C,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAC1C,OAAO,WAAW,MAAM,mBAAmB,CAAC;AAC5C,OAAO,cAAc,MAAM,sBAAsB,CAAC;AAClD,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAC9C,OAAO,OAAO,MAAM,eAAe,CAAC;AAEpC,MAAM,CAAC,OAAO,OAAO,KAAM,SAAQ,iBAAiB;gBACpC,MAAM,EAAE,cAAc;IAGlC,MAAM,YAAuB;IAC7B,SAAS,eAA0B;IACnC,OAAO,aAAwB;IAC/B,QAAQ,cAAyB;IACjC,WAAW,iBAA4B;IACvC,SAAS,eAA0B;IACnC,IAAI,UAAqB;CAC5B"}
|
package/dist/api/client.js
CHANGED
|
@@ -5,6 +5,7 @@ import APISchemas from "./schemas/client";
|
|
|
5
5
|
import APIProjects from "./projects/client";
|
|
6
6
|
import APIExtractions from "./extractions/client";
|
|
7
7
|
import APIWorkflows from "./workflows/client";
|
|
8
|
+
import APIEdit from "./edit/client";
|
|
8
9
|
export default class APIV1 extends CompositionClient {
|
|
9
10
|
constructor(client) {
|
|
10
11
|
super(client);
|
|
@@ -14,5 +15,6 @@ export default class APIV1 extends CompositionClient {
|
|
|
14
15
|
this.projects = new APIProjects(this);
|
|
15
16
|
this.extractions = new APIExtractions(this);
|
|
16
17
|
this.workflows = new APIWorkflows(this);
|
|
18
|
+
this.edit = new APIEdit(this);
|
|
17
19
|
}
|
|
18
20
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { CompositionClient, RequestOptions } from "../../client.js";
|
|
2
|
+
import { EditRequest, EditResponse } from "../../types.js";
|
|
3
|
+
import APIEditTemplates from "./templates/client.js";
|
|
4
|
+
export default class APIEdit extends CompositionClient {
|
|
5
|
+
templates: APIEditTemplates;
|
|
6
|
+
constructor(client: CompositionClient);
|
|
7
|
+
/**
|
|
8
|
+
* Edit a document by detecting and filling form fields with provided instructions.
|
|
9
|
+
*
|
|
10
|
+
* This method performs:
|
|
11
|
+
* 1. Detection to identify form field bounding boxes
|
|
12
|
+
* 2. LLM inference to name and describe detected fields
|
|
13
|
+
* 3. LLM-based form filling using the provided instructions
|
|
14
|
+
* 4. Returns the filled document with form field values populated
|
|
15
|
+
*
|
|
16
|
+
* Either `document` OR `template_id` must be provided, but not both.
|
|
17
|
+
*
|
|
18
|
+
* Supported document formats:
|
|
19
|
+
* - PDF: Native form field detection and filling
|
|
20
|
+
* - DOCX/DOC: Native editing to preserve styles and formatting
|
|
21
|
+
* - PPTX/PPT: Native editing for presentations
|
|
22
|
+
* - XLSX/XLS: Native editing for spreadsheets
|
|
23
|
+
*
|
|
24
|
+
* @param params - EditRequest containing:
|
|
25
|
+
* - filling_instructions: Natural language instructions for filling (required)
|
|
26
|
+
* - document: MIMEData object, file path, Buffer, or Readable stream (optional, mutually exclusive with template_id)
|
|
27
|
+
* - model: LLM model for inference (default: "retab-small")
|
|
28
|
+
* - template_id: Template ID to use for filling with pre-defined form fields (optional, mutually exclusive with document)
|
|
29
|
+
* @param options - Optional request options
|
|
30
|
+
* @returns EditResponse containing form_data (filled fields) and filled_document (MIMEData)
|
|
31
|
+
*/
|
|
32
|
+
fill_document(params: EditRequest, options?: RequestOptions): Promise<EditResponse>;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/api/edit/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EACH,WAAW,EACX,YAAY,EAGf,MAAM,gBAAgB,CAAC;AACxB,OAAO,gBAAgB,MAAM,uBAAuB,CAAC;AAErD,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,iBAAiB;IAC3C,SAAS,EAAE,gBAAgB,CAAC;gBAEvB,MAAM,EAAE,iBAAiB;IAKrC;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACG,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC;CAS5F"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { CompositionClient } from "../../client.js";
|
|
2
|
+
import { ZEditRequest, ZEditResponse, } from "../../types.js";
|
|
3
|
+
import APIEditTemplates from "./templates/client.js";
|
|
4
|
+
export default class APIEdit extends CompositionClient {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
super(client);
|
|
7
|
+
this.templates = new APIEditTemplates(this);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Edit a document by detecting and filling form fields with provided instructions.
|
|
11
|
+
*
|
|
12
|
+
* This method performs:
|
|
13
|
+
* 1. Detection to identify form field bounding boxes
|
|
14
|
+
* 2. LLM inference to name and describe detected fields
|
|
15
|
+
* 3. LLM-based form filling using the provided instructions
|
|
16
|
+
* 4. Returns the filled document with form field values populated
|
|
17
|
+
*
|
|
18
|
+
* Either `document` OR `template_id` must be provided, but not both.
|
|
19
|
+
*
|
|
20
|
+
* Supported document formats:
|
|
21
|
+
* - PDF: Native form field detection and filling
|
|
22
|
+
* - DOCX/DOC: Native editing to preserve styles and formatting
|
|
23
|
+
* - PPTX/PPT: Native editing for presentations
|
|
24
|
+
* - XLSX/XLS: Native editing for spreadsheets
|
|
25
|
+
*
|
|
26
|
+
* @param params - EditRequest containing:
|
|
27
|
+
* - filling_instructions: Natural language instructions for filling (required)
|
|
28
|
+
* - document: MIMEData object, file path, Buffer, or Readable stream (optional, mutually exclusive with template_id)
|
|
29
|
+
* - model: LLM model for inference (default: "retab-small")
|
|
30
|
+
* - template_id: Template ID to use for filling with pre-defined form fields (optional, mutually exclusive with document)
|
|
31
|
+
* @param options - Optional request options
|
|
32
|
+
* @returns EditResponse containing form_data (filled fields) and filled_document (MIMEData)
|
|
33
|
+
*/
|
|
34
|
+
async fill_document(params, options) {
|
|
35
|
+
return this._fetchJson(ZEditResponse, {
|
|
36
|
+
url: "/v1/edit/fill-document",
|
|
37
|
+
method: "POST",
|
|
38
|
+
body: { ...(await ZEditRequest.parseAsync(params)), ...(options?.body || {}) },
|
|
39
|
+
params: options?.params,
|
|
40
|
+
headers: options?.headers,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { CompositionClient, RequestOptions } from "../../../client.js";
|
|
2
|
+
import { PaginatedList, InferFormSchemaRequest, InferFormSchemaResponse, MIMEDataInput, EditResponse } from "../../../types.js";
|
|
3
|
+
import { EditTemplate, FormField } from "../../../generated_types.js";
|
|
4
|
+
export default class APIEditTemplates extends CompositionClient {
|
|
5
|
+
constructor(client: CompositionClient);
|
|
6
|
+
/**
|
|
7
|
+
* List edit templates with pagination and optional filtering.
|
|
8
|
+
*
|
|
9
|
+
* @param params - Pagination and filter parameters
|
|
10
|
+
* @param options - Optional request options
|
|
11
|
+
* @returns PaginatedList of EditTemplate objects
|
|
12
|
+
*/
|
|
13
|
+
list({ before, after, limit, order, filename, mime_type, include_embeddings, sort_by, }?: {
|
|
14
|
+
before?: string;
|
|
15
|
+
after?: string;
|
|
16
|
+
limit?: number;
|
|
17
|
+
order?: "asc" | "desc";
|
|
18
|
+
filename?: string;
|
|
19
|
+
mime_type?: string;
|
|
20
|
+
include_embeddings?: boolean;
|
|
21
|
+
sort_by?: string;
|
|
22
|
+
}, options?: RequestOptions): Promise<PaginatedList>;
|
|
23
|
+
/**
|
|
24
|
+
* Get an edit template by ID.
|
|
25
|
+
*
|
|
26
|
+
* @param template_id - The ID of the template to retrieve
|
|
27
|
+
* @param options - Optional request options
|
|
28
|
+
* @returns EditTemplate object
|
|
29
|
+
*/
|
|
30
|
+
get(template_id: string, options?: RequestOptions): Promise<EditTemplate>;
|
|
31
|
+
/**
|
|
32
|
+
* Create a new edit template.
|
|
33
|
+
*
|
|
34
|
+
* @param params - CreateEditTemplateRequest containing:
|
|
35
|
+
* - name: Name of the template
|
|
36
|
+
* - document: The document to use as a template (MIMEData, file path, Buffer, or Readable)
|
|
37
|
+
* - form_fields: Array of form field definitions
|
|
38
|
+
* @param options - Optional request options
|
|
39
|
+
* @returns EditTemplate object
|
|
40
|
+
*/
|
|
41
|
+
create({ name, document, form_fields, }: {
|
|
42
|
+
name: string;
|
|
43
|
+
document: MIMEDataInput;
|
|
44
|
+
form_fields: FormField[];
|
|
45
|
+
}, options?: RequestOptions): Promise<EditTemplate>;
|
|
46
|
+
/**
|
|
47
|
+
* Update an existing edit template.
|
|
48
|
+
*
|
|
49
|
+
* @param template_id - The ID of the template to update
|
|
50
|
+
* @param params - UpdateEditTemplateRequest containing optional fields to update:
|
|
51
|
+
* - name: New name for the template
|
|
52
|
+
* - form_fields: Updated array of form field definitions
|
|
53
|
+
* @param options - Optional request options
|
|
54
|
+
* @returns EditTemplate object
|
|
55
|
+
*/
|
|
56
|
+
update(template_id: string, { name, form_fields, }?: {
|
|
57
|
+
name?: string;
|
|
58
|
+
form_fields?: FormField[];
|
|
59
|
+
}, options?: RequestOptions): Promise<EditTemplate>;
|
|
60
|
+
/**
|
|
61
|
+
* Delete an edit template by ID.
|
|
62
|
+
*
|
|
63
|
+
* @param template_id - The ID of the template to delete
|
|
64
|
+
* @param options - Optional request options
|
|
65
|
+
*/
|
|
66
|
+
delete(template_id: string, options?: RequestOptions): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Duplicate an existing edit template.
|
|
69
|
+
*
|
|
70
|
+
* @param template_id - The ID of the template to duplicate
|
|
71
|
+
* @param params - DuplicateEditTemplateRequest containing optional:
|
|
72
|
+
* - name: Name for the duplicated template (defaults to "{original_name} (copy)")
|
|
73
|
+
* @param options - Optional request options
|
|
74
|
+
* @returns EditTemplate object (the new duplicated template)
|
|
75
|
+
*/
|
|
76
|
+
duplicate(template_id: string, { name }?: {
|
|
77
|
+
name?: string;
|
|
78
|
+
}, options?: RequestOptions): Promise<EditTemplate>;
|
|
79
|
+
/**
|
|
80
|
+
* Generate (infer) form schema from a PDF document.
|
|
81
|
+
*
|
|
82
|
+
* This method combines computer vision for precise bounding box detection
|
|
83
|
+
* with LLM for semantic field naming (key, description) and type classification.
|
|
84
|
+
*
|
|
85
|
+
* Supported document formats:
|
|
86
|
+
* - PDF: Direct processing (only PDF is supported)
|
|
87
|
+
*
|
|
88
|
+
* @param params - InferFormSchemaRequest containing:
|
|
89
|
+
* - document: MIMEData object, file path, Buffer, or Readable stream
|
|
90
|
+
* - model: LLM model for field naming (default: "retab-small")
|
|
91
|
+
* - instructions: Optional instructions to guide form field detection
|
|
92
|
+
* @param options - Optional request options
|
|
93
|
+
* @returns InferFormSchemaResponse containing:
|
|
94
|
+
* - form_schema: The detected form schema with field keys, descriptions, types, and bounding boxes
|
|
95
|
+
* - annotated_pdf: PDF with bounding boxes drawn around detected fields for visual verification
|
|
96
|
+
* - field_count: Number of fields detected
|
|
97
|
+
*/
|
|
98
|
+
generate(params: InferFormSchemaRequest, options?: RequestOptions): Promise<InferFormSchemaResponse>;
|
|
99
|
+
/**
|
|
100
|
+
* Fill a PDF form using a pre-defined template.
|
|
101
|
+
*
|
|
102
|
+
* This method uses a template's pre-defined form fields to fill a PDF form,
|
|
103
|
+
* skipping the field detection step for faster processing.
|
|
104
|
+
*
|
|
105
|
+
* Use cases:
|
|
106
|
+
* - Batch processing of the same form with different data
|
|
107
|
+
* - Faster form filling when field detection is already done
|
|
108
|
+
* - Consistent field mapping across multiple fills
|
|
109
|
+
*
|
|
110
|
+
* @param params - Fill request containing:
|
|
111
|
+
* - template_id: The template ID to use for filling
|
|
112
|
+
* - filling_instructions: Instructions describing how to fill the form fields
|
|
113
|
+
* - model: LLM model for inference (default: "retab-small")
|
|
114
|
+
* @param options - Optional request options
|
|
115
|
+
* @returns EditResponse containing:
|
|
116
|
+
* - form_data: List of form fields with filled values
|
|
117
|
+
* - filled_document: The filled PDF document as MIMEData
|
|
118
|
+
*/
|
|
119
|
+
fill({ template_id, filling_instructions, model, }: {
|
|
120
|
+
template_id: string;
|
|
121
|
+
filling_instructions: string;
|
|
122
|
+
model?: string;
|
|
123
|
+
}, options?: RequestOptions): Promise<EditResponse>;
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../src/api/edit/templates/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAEH,aAAa,EACb,sBAAsB,EACtB,uBAAuB,EAGvB,aAAa,EAEb,YAAY,EAEf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACH,YAAY,EAEZ,SAAS,EACZ,MAAM,6BAA6B,CAAC;AAErC,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,iBAAiB;gBAC/C,MAAM,EAAE,iBAAiB;IAIrC;;;;;;OAMG;IACG,IAAI,CACN,EACI,MAAM,EACN,KAAK,EACL,KAAU,EACV,KAAc,EACd,QAAQ,EACR,SAAS,EACT,kBAA0B,EAC1B,OAAsB,GACzB,GAAE;QACC,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;QACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,kBAAkB,CAAC,EAAE,OAAO,CAAC;QAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;KACf,EACN,OAAO,CAAC,EAAE,cAAc,GACzB,OAAO,CAAC,aAAa,CAAC;IAyBzB;;;;;;OAMG;IACG,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC;IAS/E;;;;;;;;;OASG;IACG,MAAM,CACR,EACI,IAAI,EACJ,QAAQ,EACR,WAAW,GACd,EAAE;QACC,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,aAAa,CAAC;QACxB,WAAW,EAAE,SAAS,EAAE,CAAC;KAC5B,EACD,OAAO,CAAC,EAAE,cAAc,GACzB,OAAO,CAAC,YAAY,CAAC;IAiBxB;;;;;;;;;OASG;IACG,MAAM,CACR,WAAW,EAAE,MAAM,EACnB,EACI,IAAI,EACJ,WAAW,GACd,GAAE;QACC,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,SAAS,EAAE,CAAC;KACxB,EACN,OAAO,CAAC,EAAE,cAAc,GACzB,OAAO,CAAC,YAAY,CAAC;IAcxB;;;;;OAKG;IACG,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAS1E;;;;;;;;OAQG;IACG,SAAS,CACX,WAAW,EAAE,MAAM,EACnB,EAAE,IAAI,EAAE,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAO,EAChC,OAAO,CAAC,EAAE,cAAc,GACzB,OAAO,CAAC,YAAY,CAAC;IAaxB;;;;;;;;;;;;;;;;;;OAkBG;IACG,QAAQ,CACV,MAAM,EAAE,sBAAsB,EAC9B,OAAO,CAAC,EAAE,cAAc,GACzB,OAAO,CAAC,uBAAuB,CAAC;IAUnC;;;;;;;;;;;;;;;;;;;OAmBG;IACG,IAAI,CACN,EACI,WAAW,EACX,oBAAoB,EACpB,KAAqB,GACxB,EAAE;QACC,WAAW,EAAE,MAAM,CAAC;QACpB,oBAAoB,EAAE,MAAM,CAAC;QAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;KAClB,EACD,OAAO,CAAC,EAAE,cAAc,GACzB,OAAO,CAAC,YAAY,CAAC;CAc3B"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { CompositionClient } from "../../../client.js";
|
|
2
|
+
import { ZPaginatedList, ZInferFormSchemaRequest, ZInferFormSchemaResponse, ZMIMEData, ZEditResponse, } from "../../../types.js";
|
|
3
|
+
import { ZEditTemplate, } from "../../../generated_types.js";
|
|
4
|
+
export default class APIEditTemplates extends CompositionClient {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
super(client);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* List edit templates with pagination and optional filtering.
|
|
10
|
+
*
|
|
11
|
+
* @param params - Pagination and filter parameters
|
|
12
|
+
* @param options - Optional request options
|
|
13
|
+
* @returns PaginatedList of EditTemplate objects
|
|
14
|
+
*/
|
|
15
|
+
async list({ before, after, limit = 10, order = "desc", filename, mime_type, include_embeddings = false, sort_by = "created_at", } = {}, options) {
|
|
16
|
+
const params = {
|
|
17
|
+
before,
|
|
18
|
+
after,
|
|
19
|
+
limit,
|
|
20
|
+
order,
|
|
21
|
+
filename,
|
|
22
|
+
mime_type,
|
|
23
|
+
include_embeddings,
|
|
24
|
+
sort_by,
|
|
25
|
+
};
|
|
26
|
+
// Remove undefined values
|
|
27
|
+
const cleanParams = Object.fromEntries(Object.entries(params).filter(([_, v]) => v !== undefined));
|
|
28
|
+
return this._fetchJson(ZPaginatedList, {
|
|
29
|
+
url: "/v1/edit/templates",
|
|
30
|
+
method: "GET",
|
|
31
|
+
params: { ...cleanParams, ...(options?.params || {}) },
|
|
32
|
+
headers: options?.headers,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get an edit template by ID.
|
|
37
|
+
*
|
|
38
|
+
* @param template_id - The ID of the template to retrieve
|
|
39
|
+
* @param options - Optional request options
|
|
40
|
+
* @returns EditTemplate object
|
|
41
|
+
*/
|
|
42
|
+
async get(template_id, options) {
|
|
43
|
+
return this._fetchJson(ZEditTemplate, {
|
|
44
|
+
url: `/v1/edit/templates/${template_id}`,
|
|
45
|
+
method: "GET",
|
|
46
|
+
params: options?.params,
|
|
47
|
+
headers: options?.headers,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Create a new edit template.
|
|
52
|
+
*
|
|
53
|
+
* @param params - CreateEditTemplateRequest containing:
|
|
54
|
+
* - name: Name of the template
|
|
55
|
+
* - document: The document to use as a template (MIMEData, file path, Buffer, or Readable)
|
|
56
|
+
* - form_fields: Array of form field definitions
|
|
57
|
+
* @param options - Optional request options
|
|
58
|
+
* @returns EditTemplate object
|
|
59
|
+
*/
|
|
60
|
+
async create({ name, document, form_fields, }, options) {
|
|
61
|
+
const parsedDocument = await ZMIMEData.parseAsync(document);
|
|
62
|
+
return this._fetchJson(ZEditTemplate, {
|
|
63
|
+
url: "/v1/edit/templates",
|
|
64
|
+
method: "POST",
|
|
65
|
+
body: {
|
|
66
|
+
name,
|
|
67
|
+
document: parsedDocument,
|
|
68
|
+
form_fields,
|
|
69
|
+
...(options?.body || {}),
|
|
70
|
+
},
|
|
71
|
+
params: options?.params,
|
|
72
|
+
headers: options?.headers,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Update an existing edit template.
|
|
77
|
+
*
|
|
78
|
+
* @param template_id - The ID of the template to update
|
|
79
|
+
* @param params - UpdateEditTemplateRequest containing optional fields to update:
|
|
80
|
+
* - name: New name for the template
|
|
81
|
+
* - form_fields: Updated array of form field definitions
|
|
82
|
+
* @param options - Optional request options
|
|
83
|
+
* @returns EditTemplate object
|
|
84
|
+
*/
|
|
85
|
+
async update(template_id, { name, form_fields, } = {}, options) {
|
|
86
|
+
const body = {};
|
|
87
|
+
if (name !== undefined)
|
|
88
|
+
body.name = name;
|
|
89
|
+
if (form_fields !== undefined)
|
|
90
|
+
body.form_fields = form_fields;
|
|
91
|
+
return this._fetchJson(ZEditTemplate, {
|
|
92
|
+
url: `/v1/edit/templates/${template_id}`,
|
|
93
|
+
method: "PATCH",
|
|
94
|
+
body: { ...body, ...(options?.body || {}) },
|
|
95
|
+
params: options?.params,
|
|
96
|
+
headers: options?.headers,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Delete an edit template by ID.
|
|
101
|
+
*
|
|
102
|
+
* @param template_id - The ID of the template to delete
|
|
103
|
+
* @param options - Optional request options
|
|
104
|
+
*/
|
|
105
|
+
async delete(template_id, options) {
|
|
106
|
+
return this._fetchJson({
|
|
107
|
+
url: `/v1/edit/templates/${template_id}`,
|
|
108
|
+
method: "DELETE",
|
|
109
|
+
params: options?.params,
|
|
110
|
+
headers: options?.headers,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Duplicate an existing edit template.
|
|
115
|
+
*
|
|
116
|
+
* @param template_id - The ID of the template to duplicate
|
|
117
|
+
* @param params - DuplicateEditTemplateRequest containing optional:
|
|
118
|
+
* - name: Name for the duplicated template (defaults to "{original_name} (copy)")
|
|
119
|
+
* @param options - Optional request options
|
|
120
|
+
* @returns EditTemplate object (the new duplicated template)
|
|
121
|
+
*/
|
|
122
|
+
async duplicate(template_id, { name } = {}, options) {
|
|
123
|
+
const body = {};
|
|
124
|
+
if (name !== undefined)
|
|
125
|
+
body.name = name;
|
|
126
|
+
return this._fetchJson(ZEditTemplate, {
|
|
127
|
+
url: `/v1/edit/templates/${template_id}/duplicate`,
|
|
128
|
+
method: "POST",
|
|
129
|
+
body: { ...body, ...(options?.body || {}) },
|
|
130
|
+
params: options?.params,
|
|
131
|
+
headers: options?.headers,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Generate (infer) form schema from a PDF document.
|
|
136
|
+
*
|
|
137
|
+
* This method combines computer vision for precise bounding box detection
|
|
138
|
+
* with LLM for semantic field naming (key, description) and type classification.
|
|
139
|
+
*
|
|
140
|
+
* Supported document formats:
|
|
141
|
+
* - PDF: Direct processing (only PDF is supported)
|
|
142
|
+
*
|
|
143
|
+
* @param params - InferFormSchemaRequest containing:
|
|
144
|
+
* - document: MIMEData object, file path, Buffer, or Readable stream
|
|
145
|
+
* - model: LLM model for field naming (default: "retab-small")
|
|
146
|
+
* - instructions: Optional instructions to guide form field detection
|
|
147
|
+
* @param options - Optional request options
|
|
148
|
+
* @returns InferFormSchemaResponse containing:
|
|
149
|
+
* - form_schema: The detected form schema with field keys, descriptions, types, and bounding boxes
|
|
150
|
+
* - annotated_pdf: PDF with bounding boxes drawn around detected fields for visual verification
|
|
151
|
+
* - field_count: Number of fields detected
|
|
152
|
+
*/
|
|
153
|
+
async generate(params, options) {
|
|
154
|
+
return this._fetchJson(ZInferFormSchemaResponse, {
|
|
155
|
+
url: "/v1/edit/templates/generate",
|
|
156
|
+
method: "POST",
|
|
157
|
+
body: { ...(await ZInferFormSchemaRequest.parseAsync(params)), ...(options?.body || {}) },
|
|
158
|
+
params: options?.params,
|
|
159
|
+
headers: options?.headers,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Fill a PDF form using a pre-defined template.
|
|
164
|
+
*
|
|
165
|
+
* This method uses a template's pre-defined form fields to fill a PDF form,
|
|
166
|
+
* skipping the field detection step for faster processing.
|
|
167
|
+
*
|
|
168
|
+
* Use cases:
|
|
169
|
+
* - Batch processing of the same form with different data
|
|
170
|
+
* - Faster form filling when field detection is already done
|
|
171
|
+
* - Consistent field mapping across multiple fills
|
|
172
|
+
*
|
|
173
|
+
* @param params - Fill request containing:
|
|
174
|
+
* - template_id: The template ID to use for filling
|
|
175
|
+
* - filling_instructions: Instructions describing how to fill the form fields
|
|
176
|
+
* - model: LLM model for inference (default: "retab-small")
|
|
177
|
+
* @param options - Optional request options
|
|
178
|
+
* @returns EditResponse containing:
|
|
179
|
+
* - form_data: List of form fields with filled values
|
|
180
|
+
* - filled_document: The filled PDF document as MIMEData
|
|
181
|
+
*/
|
|
182
|
+
async fill({ template_id, filling_instructions, model = "retab-small", }, options) {
|
|
183
|
+
return this._fetchJson(ZEditResponse, {
|
|
184
|
+
url: "/v1/edit/templates/fill",
|
|
185
|
+
method: "POST",
|
|
186
|
+
body: {
|
|
187
|
+
template_id,
|
|
188
|
+
filling_instructions,
|
|
189
|
+
model,
|
|
190
|
+
...(options?.body || {}),
|
|
191
|
+
},
|
|
192
|
+
params: options?.params,
|
|
193
|
+
headers: options?.headers,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}
|
package/dist/client.js
CHANGED
|
@@ -103,7 +103,7 @@ export class FetcherClient extends AbstractClient {
|
|
|
103
103
|
constructor(options) {
|
|
104
104
|
super();
|
|
105
105
|
this.options = options || {};
|
|
106
|
-
this.timeout = this.options.timeout ?? 1800000; // Default 1800 seconds (in milliseconds)
|
|
106
|
+
this.timeout = this.options.timeout ?? 1800000; // Default 1800 seconds (30 minutes) (in milliseconds)
|
|
107
107
|
// Validate that at least one authentication method is provided
|
|
108
108
|
const apiKey = "apiKey" in this.options ? this.options.apiKey : process.env["RETAB_API_KEY"];
|
|
109
109
|
if (!apiKey) {
|