unstructured-transform-client 0.18.18
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/LICENSE +21 -0
- package/README.md +210 -0
- package/dist/_generated/apis/ExtractApi.d.ts +43 -0
- package/dist/_generated/apis/ExtractApi.js +70 -0
- package/dist/_generated/apis/JobsApi.d.ts +117 -0
- package/dist/_generated/apis/JobsApi.js +211 -0
- package/dist/_generated/apis/ParseApi.d.ts +79 -0
- package/dist/_generated/apis/ParseApi.js +111 -0
- package/dist/_generated/apis/UploadApi.d.ts +78 -0
- package/dist/_generated/apis/UploadApi.js +172 -0
- package/dist/_generated/apis/index.d.ts +4 -0
- package/dist/_generated/apis/index.js +6 -0
- package/dist/_generated/index.d.ts +3 -0
- package/dist/_generated/index.js +5 -0
- package/dist/_generated/models/Citation.d.ts +31 -0
- package/dist/_generated/models/Citation.js +44 -0
- package/dist/_generated/models/DocumentMetadata.d.ts +30 -0
- package/dist/_generated/models/DocumentMetadata.js +43 -0
- package/dist/_generated/models/Element.d.ts +43 -0
- package/dist/_generated/models/Element.js +56 -0
- package/dist/_generated/models/ElementMetadata.d.ts +40 -0
- package/dist/_generated/models/ElementMetadata.js +51 -0
- package/dist/_generated/models/ErrorCode.d.ts +46 -0
- package/dist/_generated/models/ErrorCode.js +64 -0
- package/dist/_generated/models/ExtractRequest.d.ts +40 -0
- package/dist/_generated/models/ExtractRequest.js +49 -0
- package/dist/_generated/models/ExtractionResult.d.ts +37 -0
- package/dist/_generated/models/ExtractionResult.js +47 -0
- package/dist/_generated/models/FieldMetadata.d.ts +31 -0
- package/dist/_generated/models/FieldMetadata.js +42 -0
- package/dist/_generated/models/JobAccepted.d.ts +67 -0
- package/dist/_generated/models/JobAccepted.js +73 -0
- package/dist/_generated/models/JobOperation.d.ts +25 -0
- package/dist/_generated/models/JobOperation.js +43 -0
- package/dist/_generated/models/JobPage.d.ts +35 -0
- package/dist/_generated/models/JobPage.js +48 -0
- package/dist/_generated/models/JobResult.d.ts +61 -0
- package/dist/_generated/models/JobResult.js +64 -0
- package/dist/_generated/models/JobResultState.d.ts +26 -0
- package/dist/_generated/models/JobResultState.js +44 -0
- package/dist/_generated/models/JobStatus.d.ts +29 -0
- package/dist/_generated/models/JobStatus.js +47 -0
- package/dist/_generated/models/JobSummary.d.ts +74 -0
- package/dist/_generated/models/JobSummary.js +86 -0
- package/dist/_generated/models/Locator.d.ts +45 -0
- package/dist/_generated/models/Locator.js +57 -0
- package/dist/_generated/models/ModelError.d.ts +35 -0
- package/dist/_generated/models/ModelError.js +48 -0
- package/dist/_generated/models/OutputFormat.d.ts +25 -0
- package/dist/_generated/models/OutputFormat.js +43 -0
- package/dist/_generated/models/ParseResult.d.ts +87 -0
- package/dist/_generated/models/ParseResult.js +98 -0
- package/dist/_generated/models/SourceFile.d.ts +42 -0
- package/dist/_generated/models/SourceFile.js +56 -0
- package/dist/_generated/models/TransformStatus.d.ts +26 -0
- package/dist/_generated/models/TransformStatus.js +44 -0
- package/dist/_generated/models/TransformWarning.d.ts +34 -0
- package/dist/_generated/models/TransformWarning.js +47 -0
- package/dist/_generated/models/UploadResult.d.ts +38 -0
- package/dist/_generated/models/UploadResult.js +52 -0
- package/dist/_generated/models/index.d.ts +23 -0
- package/dist/_generated/models/index.js +25 -0
- package/dist/_generated/runtime.d.ts +196 -0
- package/dist/_generated/runtime.js +398 -0
- package/dist/client.d.ts +145 -0
- package/dist/client.js +259 -0
- package/dist/files.d.ts +32 -0
- package/dist/files.js +46 -0
- package/dist/hostHeaders.d.ts +36 -0
- package/dist/hostHeaders.js +133 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +35 -0
- package/dist/multipart.d.ts +50 -0
- package/dist/multipart.js +65 -0
- package/dist/outcome.d.ts +45 -0
- package/dist/outcome.js +40 -0
- package/dist/retry.d.ts +16 -0
- package/dist/retry.js +181 -0
- package/dist/sse.d.ts +50 -0
- package/dist/sse.js +140 -0
- package/dist/version.d.ts +10 -0
- package/dist/version.js +10 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Unstructured-IO
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# unstructured-transform-client
|
|
2
|
+
|
|
3
|
+
TypeScript client for the [Unstructured](https://unstructured.io) Transform v2
|
|
4
|
+
API. One document in, structured output back.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import { TransformClient, isAccepted } from "unstructured-transform-client";
|
|
8
|
+
|
|
9
|
+
const client = new TransformClient(); // reads UNSTRUCTURED_API_KEY in Node
|
|
10
|
+
const outcome = await client.parse.run({ input: file }); // a File, from an <input>
|
|
11
|
+
if (!isAccepted(outcome)) console.log(outcome.body.markdown);
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
Install from public npm:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install unstructured-transform-client
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Set `UNSTRUCTURED_API_KEY` for the default API-key authentication path:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
export UNSTRUCTURED_API_KEY="your-key-here"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
In Node, create the client without passing a key. An explicit `apiKey` takes
|
|
29
|
+
precedence over the environment variable; pass `bearerToken` explicitly for
|
|
30
|
+
bearer authentication. If neither is available, construction raises an error
|
|
31
|
+
naming `UNSTRUCTURED_API_KEY`.
|
|
32
|
+
|
|
33
|
+
Requires Node 22 or newer, for native `fetch` and `FormData`.
|
|
34
|
+
|
|
35
|
+
## The three flows
|
|
36
|
+
|
|
37
|
+
**Parse a document.**
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
const outcome = await client.parse.run({ input: file });
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Every submitting call answers **either** a finished result (200) **or** a job
|
|
44
|
+
handle (202) — `waitSeconds: 0` always produces the latter. So they return a
|
|
45
|
+
discriminated union rather than pretending the second is the first:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
if (isAccepted(outcome)) {
|
|
49
|
+
for await (const event of client.jobs.stream(outcome.body.id)) { /* ... */ }
|
|
50
|
+
} else {
|
|
51
|
+
console.log(outcome.body.markdown);
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**Extract fields from a document in one call.** Supplying a schema adds an
|
|
56
|
+
extraction step to the same job, so the document is parsed once.
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
const outcome = await client.parse.run({
|
|
60
|
+
input: file,
|
|
61
|
+
schema: {
|
|
62
|
+
type: "object",
|
|
63
|
+
properties: { invoiceNumber: { type: "string" } },
|
|
64
|
+
required: ["invoiceNumber"],
|
|
65
|
+
additionalProperties: false,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The engine requires `required` to list every key in `properties` and
|
|
71
|
+
`additionalProperties` to be `false`. That constraint cannot be expressed in
|
|
72
|
+
OpenAPI, so the types do not enforce it — a schema without it is rejected at
|
|
73
|
+
request time rather than by the compiler.
|
|
74
|
+
|
|
75
|
+
**Extract against a parse you already have.**
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
const extraction = await client.extract.run({ parseId, schema });
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`extract.fromDocument` also takes `fileId` instead of `input`, for a document
|
|
82
|
+
already uploaded.
|
|
83
|
+
|
|
84
|
+
An extraction is a job like any other. If the call returns an accepted job,
|
|
85
|
+
follow it to a terminal status before reading `result.extractedData`. A
|
|
86
|
+
single `jobs.get` right after submitting can still land on `queued` or
|
|
87
|
+
`processing`, with `result` still `undefined`:
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
const outcome = await client.extract.run({ parseId, schema, waitSeconds: 0 });
|
|
91
|
+
if (isAccepted(outcome)) {
|
|
92
|
+
const deadline = Date.now() + 300_000;
|
|
93
|
+
let job = await client.jobs.get(outcome.body.id);
|
|
94
|
+
while (job.status === "queued" || job.status === "processing") {
|
|
95
|
+
if (Date.now() >= deadline) {
|
|
96
|
+
throw new Error(`extraction ${outcome.body.id} is still ${job.status}`);
|
|
97
|
+
}
|
|
98
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
99
|
+
job = await client.jobs.get(outcome.body.id);
|
|
100
|
+
}
|
|
101
|
+
console.log(job.status, job.result?.extractedData);
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Give the wait a bound, as above. A job can stay queued or processing, and a
|
|
106
|
+
loop without a deadline polls forever. `jobs.stream` is the alternative: it
|
|
107
|
+
ends on its own at the terminal event, and is shown under Long-running jobs
|
|
108
|
+
below.
|
|
109
|
+
|
|
110
|
+
## Long-running jobs
|
|
111
|
+
|
|
112
|
+
Pass `waitSeconds` to block, or `waitSeconds: 0` to take a job handle and
|
|
113
|
+
follow it yourself.
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
const job = await client.parse.run({ input: file, waitSeconds: 0 });
|
|
117
|
+
|
|
118
|
+
for await (const event of client.jobs.stream(job.body.id)) {
|
|
119
|
+
console.log(event.event, event.data);
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
The stream yields `status` events and then exactly one terminal `result` or
|
|
124
|
+
`error`, after which it ends on its own. Pass an `AbortSignal` to stop early:
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
const controller = new AbortController();
|
|
128
|
+
for await (const event of client.jobs.stream(job.body.id, { signal: controller.signal })) {
|
|
129
|
+
if (someCondition) controller.abort();
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Polling with `client.jobs.get(job.body.id)` returns the same resource if you would
|
|
134
|
+
rather not hold a connection open.
|
|
135
|
+
|
|
136
|
+
To scan jobs across every page, use the cursor-following async iterator.
|
|
137
|
+
`list()` still returns one page when you need page boundaries.
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
for await (const job of client.jobs.iterate({ status: "completed" })) {
|
|
141
|
+
console.log(job.id, job.status);
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Retries
|
|
146
|
+
|
|
147
|
+
Retries are enabled by default for transient failures. Configure them per
|
|
148
|
+
client, or pass `retries: false` to disable them:
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
const client = new TransformClient({
|
|
152
|
+
retries: { maxAttempts: 5, maxElapsedMs: 20_000 },
|
|
153
|
+
});
|
|
154
|
+
const withoutRetries = new TransformClient({ retries: false });
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
`GET` and `DELETE` are retried on any transient failure. Everything else — a
|
|
158
|
+
parse, extract or upload submit, and any other write — is retried only when the
|
|
159
|
+
failure proves the request never reached the service, such as a refused
|
|
160
|
+
connection or a DNS failure. A read timeout or a `5xx` on a write is not
|
|
161
|
+
retried, because the service may have acted on it already and a second attempt
|
|
162
|
+
could duplicate the effect.
|
|
163
|
+
|
|
164
|
+
## Documents need a filename
|
|
165
|
+
|
|
166
|
+
Pass a `File`, or `{ data, filename }`. A bare `Blob` is refused:
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
await client.parse.run({ input: new File([bytes], "invoice.pdf") });
|
|
170
|
+
await client.parse.run({ input: { data: bytes, filename: "invoice.pdf" } });
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
The service validates an upload's extension against an allowlist, and a
|
|
174
|
+
`FormData` part built from an unnamed `Blob` arrives called `blob` — so it
|
|
175
|
+
would be rejected as an unsupported file type. Refusing it here names the real
|
|
176
|
+
problem instead.
|
|
177
|
+
|
|
178
|
+
## Credentials
|
|
179
|
+
|
|
180
|
+
Pass exactly one of `apiKey` or `bearerToken`. They are different identities,
|
|
181
|
+
not two spellings of one credential — whichever you send is forwarded upstream
|
|
182
|
+
as-is.
|
|
183
|
+
|
|
184
|
+
## What this client tells us about your environment
|
|
185
|
+
|
|
186
|
+
Every request carries a `User-Agent` and a set of `X-Unstructured-Client-*`
|
|
187
|
+
headers: this package's version, the language, your Node version, your OS
|
|
188
|
+
family, and your CPU architecture.
|
|
189
|
+
|
|
190
|
+
It never sends your hostname, username, working directory, environment
|
|
191
|
+
variables, IP address, or anything read from your documents. In a browser it
|
|
192
|
+
reports neither OS nor architecture, and the `User-Agent` is set by the browser
|
|
193
|
+
rather than by this package.
|
|
194
|
+
|
|
195
|
+
To send only the `User-Agent`:
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
const client = new TransformClient({ apiKey: "...", sendHostHeaders: false });
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
or set `UNSTRUCTURED_TRANSFORM_DISABLE_HOST_HEADERS=1`.
|
|
202
|
+
|
|
203
|
+
## Versioning
|
|
204
|
+
|
|
205
|
+
This client's version tracks the Transform API revision it was generated from,
|
|
206
|
+
so `0.18.x` of this package describes `0.18.x` of the API.
|
|
207
|
+
|
|
208
|
+
Everything exported from the package root is public. The `_generated` directory
|
|
209
|
+
is not — it is produced from the OpenAPI contract at build time and may be
|
|
210
|
+
reorganised without notice.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unstructured Transform API
|
|
3
|
+
* One document in, the parsed document back. A single call takes a document and returns structured output — no job graph, no strategy selection, no model provider setup, and no polling loop. An optional schema switches the request from parse-only to parse-then-extract.
|
|
4
|
+
*
|
|
5
|
+
* The version of the OpenAPI document: 0.1.0
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
9
|
+
* https://openapi-generator.tech
|
|
10
|
+
* Do not edit the class manually.
|
|
11
|
+
*/
|
|
12
|
+
import * as runtime from '../runtime.js';
|
|
13
|
+
import { type ExtractRequest } from '../models/ExtractRequest.js';
|
|
14
|
+
import { type ParseResult } from '../models/ParseResult.js';
|
|
15
|
+
export interface ExtractRunRequest {
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
extractRequest: ExtractRequest;
|
|
20
|
+
/**
|
|
21
|
+
* Wait up to this many seconds for completed extraction.
|
|
22
|
+
*/
|
|
23
|
+
prefer?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
export declare class ExtractApi extends runtime.BaseAPI {
|
|
29
|
+
/**
|
|
30
|
+
* Creates request options for extractRun without sending the request
|
|
31
|
+
*/
|
|
32
|
+
extractRunRequestOpts(requestParameters: ExtractRunRequest): Promise<runtime.RequestOpts>;
|
|
33
|
+
/**
|
|
34
|
+
* Takes either a parse ID or a document and a schema, then returns the fields. A multipart input is limited to 50 MB and to the supported extensions: bmp, docx, heic, jpeg, jpg, pdf, png, pptx, tiff.
|
|
35
|
+
* Extract fields from a parse or document
|
|
36
|
+
*/
|
|
37
|
+
extractRunRaw(requestParameters: ExtractRunRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ParseResult>>;
|
|
38
|
+
/**
|
|
39
|
+
* Takes either a parse ID or a document and a schema, then returns the fields. A multipart input is limited to 50 MB and to the supported extensions: bmp, docx, heic, jpeg, jpg, pdf, png, pptx, tiff.
|
|
40
|
+
* Extract fields from a parse or document
|
|
41
|
+
*/
|
|
42
|
+
extractRun(requestParameters: ExtractRunRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ParseResult>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* Unstructured Transform API
|
|
5
|
+
* One document in, the parsed document back. A single call takes a document and returns structured output — no job graph, no strategy selection, no model provider setup, and no polling loop. An optional schema switches the request from parse-only to parse-then-extract.
|
|
6
|
+
*
|
|
7
|
+
* The version of the OpenAPI document: 0.1.0
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
11
|
+
* https://openapi-generator.tech
|
|
12
|
+
* Do not edit the class manually.
|
|
13
|
+
*/
|
|
14
|
+
import * as runtime from '../runtime.js';
|
|
15
|
+
import { ExtractRequestToJSON, } from '../models/ExtractRequest.js';
|
|
16
|
+
import { ParseResultFromJSON, } from '../models/ParseResult.js';
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
export class ExtractApi extends runtime.BaseAPI {
|
|
21
|
+
/**
|
|
22
|
+
* Creates request options for extractRun without sending the request
|
|
23
|
+
*/
|
|
24
|
+
async extractRunRequestOpts(requestParameters) {
|
|
25
|
+
if (requestParameters['extractRequest'] == null) {
|
|
26
|
+
throw new runtime.RequiredError('extractRequest', 'Required parameter "extractRequest" was null or undefined when calling extractRun().');
|
|
27
|
+
}
|
|
28
|
+
const queryParameters = {};
|
|
29
|
+
const headerParameters = {};
|
|
30
|
+
headerParameters['Content-Type'] = 'application/json';
|
|
31
|
+
if (requestParameters['prefer'] != null) {
|
|
32
|
+
headerParameters['Prefer'] = String(requestParameters['prefer']);
|
|
33
|
+
}
|
|
34
|
+
if (this.configuration && this.configuration.apiKey) {
|
|
35
|
+
headerParameters["unstructured-api-key"] = await this.configuration.apiKey("unstructured-api-key"); // ApiKeyAuth authentication
|
|
36
|
+
}
|
|
37
|
+
if (this.configuration && this.configuration.accessToken) {
|
|
38
|
+
const token = this.configuration.accessToken;
|
|
39
|
+
const tokenString = await token("BearerAuth", []);
|
|
40
|
+
if (tokenString) {
|
|
41
|
+
headerParameters["Authorization"] = `Bearer ${tokenString}`;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
let urlPath = `/api/v2/extract`;
|
|
45
|
+
return {
|
|
46
|
+
path: urlPath,
|
|
47
|
+
method: 'POST',
|
|
48
|
+
headers: headerParameters,
|
|
49
|
+
query: queryParameters,
|
|
50
|
+
body: ExtractRequestToJSON(requestParameters['extractRequest']),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Takes either a parse ID or a document and a schema, then returns the fields. A multipart input is limited to 50 MB and to the supported extensions: bmp, docx, heic, jpeg, jpg, pdf, png, pptx, tiff.
|
|
55
|
+
* Extract fields from a parse or document
|
|
56
|
+
*/
|
|
57
|
+
async extractRunRaw(requestParameters, initOverrides) {
|
|
58
|
+
const requestOptions = await this.extractRunRequestOpts(requestParameters);
|
|
59
|
+
const response = await this.request(requestOptions, initOverrides);
|
|
60
|
+
return new runtime.JSONApiResponse(response, (jsonValue) => ParseResultFromJSON(jsonValue));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Takes either a parse ID or a document and a schema, then returns the fields. A multipart input is limited to 50 MB and to the supported extensions: bmp, docx, heic, jpeg, jpg, pdf, png, pptx, tiff.
|
|
64
|
+
* Extract fields from a parse or document
|
|
65
|
+
*/
|
|
66
|
+
async extractRun(requestParameters, initOverrides) {
|
|
67
|
+
const response = await this.extractRunRaw(requestParameters, initOverrides);
|
|
68
|
+
return await response.value();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unstructured Transform API
|
|
3
|
+
* One document in, the parsed document back. A single call takes a document and returns structured output — no job graph, no strategy selection, no model provider setup, and no polling loop. An optional schema switches the request from parse-only to parse-then-extract.
|
|
4
|
+
*
|
|
5
|
+
* The version of the OpenAPI document: 0.1.0
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
9
|
+
* https://openapi-generator.tech
|
|
10
|
+
* Do not edit the class manually.
|
|
11
|
+
*/
|
|
12
|
+
import * as runtime from '../runtime.js';
|
|
13
|
+
import { type JobPage } from '../models/JobPage.js';
|
|
14
|
+
import { type JobResult } from '../models/JobResult.js';
|
|
15
|
+
import { type JobStatus } from '../models/JobStatus.js';
|
|
16
|
+
import { type OutputFormat } from '../models/OutputFormat.js';
|
|
17
|
+
export interface JobsCancelRequest {
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
jobId: string;
|
|
22
|
+
}
|
|
23
|
+
export interface JobsDeleteRequest {
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
27
|
+
jobId: string;
|
|
28
|
+
}
|
|
29
|
+
export interface JobsGetRequest {
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
jobId: string;
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
37
|
+
output?: OutputFormat;
|
|
38
|
+
/**
|
|
39
|
+
* Optional list of projection fields to include in elements output. Allowed values are 'coordinates' and 'table_html'. Only valid when output='elements'.
|
|
40
|
+
*/
|
|
41
|
+
include?: Array<string>;
|
|
42
|
+
}
|
|
43
|
+
export interface JobsListRequest {
|
|
44
|
+
/**
|
|
45
|
+
* Opaque pagination cursor from a previous response.
|
|
46
|
+
*/
|
|
47
|
+
cursor?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Maximum number of jobs to return.
|
|
50
|
+
*/
|
|
51
|
+
limit?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Return only jobs with this public status. completed_with_warnings maps to completed upstream and may include completed jobs without warnings.
|
|
54
|
+
*/
|
|
55
|
+
status?: JobStatus;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
*/
|
|
60
|
+
export declare class JobsApi extends runtime.BaseAPI {
|
|
61
|
+
/**
|
|
62
|
+
* Creates request options for jobsCancel without sending the request
|
|
63
|
+
*/
|
|
64
|
+
jobsCancelRequestOpts(requestParameters: JobsCancelRequest): Promise<runtime.RequestOpts>;
|
|
65
|
+
/**
|
|
66
|
+
* Requests cancellation of a queued or processing job. The response is the current job snapshot; poll this resource until its status is cancelled. Cancellation is idempotent and terminal jobs are unchanged.
|
|
67
|
+
* Request cancellation of a parse or extraction job
|
|
68
|
+
*/
|
|
69
|
+
jobsCancelRaw(requestParameters: JobsCancelRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<JobResult>>;
|
|
70
|
+
/**
|
|
71
|
+
* Requests cancellation of a queued or processing job. The response is the current job snapshot; poll this resource until its status is cancelled. Cancellation is idempotent and terminal jobs are unchanged.
|
|
72
|
+
* Request cancellation of a parse or extraction job
|
|
73
|
+
*/
|
|
74
|
+
jobsCancel(requestParameters: JobsCancelRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<JobResult>;
|
|
75
|
+
/**
|
|
76
|
+
* Creates request options for jobsDelete without sending the request
|
|
77
|
+
*/
|
|
78
|
+
jobsDeleteRequestOpts(requestParameters: JobsDeleteRequest): Promise<runtime.RequestOpts>;
|
|
79
|
+
/**
|
|
80
|
+
* Deletes a terminal job from the API\'s visible set. Deletion is asynchronous and idempotent. Source and output blobs follow retention policy and are not synchronously removed by this operation.
|
|
81
|
+
* Delete a completed parse or extraction job
|
|
82
|
+
*/
|
|
83
|
+
jobsDeleteRaw(requestParameters: JobsDeleteRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>>;
|
|
84
|
+
/**
|
|
85
|
+
* Deletes a terminal job from the API\'s visible set. Deletion is asynchronous and idempotent. Source and output blobs follow retention policy and are not synchronously removed by this operation.
|
|
86
|
+
* Delete a completed parse or extraction job
|
|
87
|
+
*/
|
|
88
|
+
jobsDelete(requestParameters: JobsDeleteRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Creates request options for jobsGet without sending the request
|
|
91
|
+
*/
|
|
92
|
+
jobsGetRequestOpts(requestParameters: JobsGetRequest): Promise<runtime.RequestOpts>;
|
|
93
|
+
/**
|
|
94
|
+
* Returns the job\'s status, and its content as soon as it is available, for a job started by either parse or extract. An extraction job\'s fields arrive in result.extracted_data. Send Accept text/event-stream for progress events as the job runs, ending in one result event whose data is this same JobResult.
|
|
95
|
+
* Get the status or result of a parse or extraction job
|
|
96
|
+
*/
|
|
97
|
+
jobsGetRaw(requestParameters: JobsGetRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<JobResult>>;
|
|
98
|
+
/**
|
|
99
|
+
* Returns the job\'s status, and its content as soon as it is available, for a job started by either parse or extract. An extraction job\'s fields arrive in result.extracted_data. Send Accept text/event-stream for progress events as the job runs, ending in one result event whose data is this same JobResult.
|
|
100
|
+
* Get the status or result of a parse or extraction job
|
|
101
|
+
*/
|
|
102
|
+
jobsGet(requestParameters: JobsGetRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<JobResult>;
|
|
103
|
+
/**
|
|
104
|
+
* Creates request options for jobsList without sending the request
|
|
105
|
+
*/
|
|
106
|
+
jobsListRequestOpts(requestParameters: JobsListRequest): Promise<runtime.RequestOpts>;
|
|
107
|
+
/**
|
|
108
|
+
* Returns this caller\'s visible jobs, newest first. Tenant scope comes from the credential; the request has no tenant parameter.
|
|
109
|
+
* List parse and extraction jobs
|
|
110
|
+
*/
|
|
111
|
+
jobsListRaw(requestParameters: JobsListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<JobPage>>;
|
|
112
|
+
/**
|
|
113
|
+
* Returns this caller\'s visible jobs, newest first. Tenant scope comes from the credential; the request has no tenant parameter.
|
|
114
|
+
* List parse and extraction jobs
|
|
115
|
+
*/
|
|
116
|
+
jobsList(requestParameters?: JobsListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<JobPage>;
|
|
117
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* Unstructured Transform API
|
|
5
|
+
* One document in, the parsed document back. A single call takes a document and returns structured output — no job graph, no strategy selection, no model provider setup, and no polling loop. An optional schema switches the request from parse-only to parse-then-extract.
|
|
6
|
+
*
|
|
7
|
+
* The version of the OpenAPI document: 0.1.0
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
11
|
+
* https://openapi-generator.tech
|
|
12
|
+
* Do not edit the class manually.
|
|
13
|
+
*/
|
|
14
|
+
import * as runtime from '../runtime.js';
|
|
15
|
+
import { JobPageFromJSON, } from '../models/JobPage.js';
|
|
16
|
+
import { JobResultFromJSON, } from '../models/JobResult.js';
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
export class JobsApi extends runtime.BaseAPI {
|
|
21
|
+
/**
|
|
22
|
+
* Creates request options for jobsCancel without sending the request
|
|
23
|
+
*/
|
|
24
|
+
async jobsCancelRequestOpts(requestParameters) {
|
|
25
|
+
if (requestParameters['jobId'] == null) {
|
|
26
|
+
throw new runtime.RequiredError('jobId', 'Required parameter "jobId" was null or undefined when calling jobsCancel().');
|
|
27
|
+
}
|
|
28
|
+
const queryParameters = {};
|
|
29
|
+
const headerParameters = {};
|
|
30
|
+
if (this.configuration && this.configuration.apiKey) {
|
|
31
|
+
headerParameters["unstructured-api-key"] = await this.configuration.apiKey("unstructured-api-key"); // ApiKeyAuth authentication
|
|
32
|
+
}
|
|
33
|
+
if (this.configuration && this.configuration.accessToken) {
|
|
34
|
+
const token = this.configuration.accessToken;
|
|
35
|
+
const tokenString = await token("BearerAuth", []);
|
|
36
|
+
if (tokenString) {
|
|
37
|
+
headerParameters["Authorization"] = `Bearer ${tokenString}`;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
let urlPath = `/api/v2/jobs/{jobId}/cancel`;
|
|
41
|
+
urlPath = urlPath.replace('{jobId}', encodeURIComponent(String(requestParameters['jobId'])));
|
|
42
|
+
return {
|
|
43
|
+
path: urlPath,
|
|
44
|
+
method: 'POST',
|
|
45
|
+
headers: headerParameters,
|
|
46
|
+
query: queryParameters,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Requests cancellation of a queued or processing job. The response is the current job snapshot; poll this resource until its status is cancelled. Cancellation is idempotent and terminal jobs are unchanged.
|
|
51
|
+
* Request cancellation of a parse or extraction job
|
|
52
|
+
*/
|
|
53
|
+
async jobsCancelRaw(requestParameters, initOverrides) {
|
|
54
|
+
const requestOptions = await this.jobsCancelRequestOpts(requestParameters);
|
|
55
|
+
const response = await this.request(requestOptions, initOverrides);
|
|
56
|
+
return new runtime.JSONApiResponse(response, (jsonValue) => JobResultFromJSON(jsonValue));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Requests cancellation of a queued or processing job. The response is the current job snapshot; poll this resource until its status is cancelled. Cancellation is idempotent and terminal jobs are unchanged.
|
|
60
|
+
* Request cancellation of a parse or extraction job
|
|
61
|
+
*/
|
|
62
|
+
async jobsCancel(requestParameters, initOverrides) {
|
|
63
|
+
const response = await this.jobsCancelRaw(requestParameters, initOverrides);
|
|
64
|
+
return await response.value();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Creates request options for jobsDelete without sending the request
|
|
68
|
+
*/
|
|
69
|
+
async jobsDeleteRequestOpts(requestParameters) {
|
|
70
|
+
if (requestParameters['jobId'] == null) {
|
|
71
|
+
throw new runtime.RequiredError('jobId', 'Required parameter "jobId" was null or undefined when calling jobsDelete().');
|
|
72
|
+
}
|
|
73
|
+
const queryParameters = {};
|
|
74
|
+
const headerParameters = {};
|
|
75
|
+
if (this.configuration && this.configuration.apiKey) {
|
|
76
|
+
headerParameters["unstructured-api-key"] = await this.configuration.apiKey("unstructured-api-key"); // ApiKeyAuth authentication
|
|
77
|
+
}
|
|
78
|
+
if (this.configuration && this.configuration.accessToken) {
|
|
79
|
+
const token = this.configuration.accessToken;
|
|
80
|
+
const tokenString = await token("BearerAuth", []);
|
|
81
|
+
if (tokenString) {
|
|
82
|
+
headerParameters["Authorization"] = `Bearer ${tokenString}`;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
let urlPath = `/api/v2/jobs/{jobId}`;
|
|
86
|
+
urlPath = urlPath.replace('{jobId}', encodeURIComponent(String(requestParameters['jobId'])));
|
|
87
|
+
return {
|
|
88
|
+
path: urlPath,
|
|
89
|
+
method: 'DELETE',
|
|
90
|
+
headers: headerParameters,
|
|
91
|
+
query: queryParameters,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Deletes a terminal job from the API\'s visible set. Deletion is asynchronous and idempotent. Source and output blobs follow retention policy and are not synchronously removed by this operation.
|
|
96
|
+
* Delete a completed parse or extraction job
|
|
97
|
+
*/
|
|
98
|
+
async jobsDeleteRaw(requestParameters, initOverrides) {
|
|
99
|
+
const requestOptions = await this.jobsDeleteRequestOpts(requestParameters);
|
|
100
|
+
const response = await this.request(requestOptions, initOverrides);
|
|
101
|
+
return new runtime.VoidApiResponse(response);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Deletes a terminal job from the API\'s visible set. Deletion is asynchronous and idempotent. Source and output blobs follow retention policy and are not synchronously removed by this operation.
|
|
105
|
+
* Delete a completed parse or extraction job
|
|
106
|
+
*/
|
|
107
|
+
async jobsDelete(requestParameters, initOverrides) {
|
|
108
|
+
await this.jobsDeleteRaw(requestParameters, initOverrides);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Creates request options for jobsGet without sending the request
|
|
112
|
+
*/
|
|
113
|
+
async jobsGetRequestOpts(requestParameters) {
|
|
114
|
+
if (requestParameters['jobId'] == null) {
|
|
115
|
+
throw new runtime.RequiredError('jobId', 'Required parameter "jobId" was null or undefined when calling jobsGet().');
|
|
116
|
+
}
|
|
117
|
+
const queryParameters = {};
|
|
118
|
+
if (requestParameters['output'] != null) {
|
|
119
|
+
queryParameters['output'] = requestParameters['output'];
|
|
120
|
+
}
|
|
121
|
+
if (requestParameters['include'] != null) {
|
|
122
|
+
queryParameters['include'] = requestParameters['include'];
|
|
123
|
+
}
|
|
124
|
+
const headerParameters = {};
|
|
125
|
+
if (this.configuration && this.configuration.apiKey) {
|
|
126
|
+
headerParameters["unstructured-api-key"] = await this.configuration.apiKey("unstructured-api-key"); // ApiKeyAuth authentication
|
|
127
|
+
}
|
|
128
|
+
if (this.configuration && this.configuration.accessToken) {
|
|
129
|
+
const token = this.configuration.accessToken;
|
|
130
|
+
const tokenString = await token("BearerAuth", []);
|
|
131
|
+
if (tokenString) {
|
|
132
|
+
headerParameters["Authorization"] = `Bearer ${tokenString}`;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
let urlPath = `/api/v2/jobs/{jobId}`;
|
|
136
|
+
urlPath = urlPath.replace('{jobId}', encodeURIComponent(String(requestParameters['jobId'])));
|
|
137
|
+
return {
|
|
138
|
+
path: urlPath,
|
|
139
|
+
method: 'GET',
|
|
140
|
+
headers: headerParameters,
|
|
141
|
+
query: queryParameters,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Returns the job\'s status, and its content as soon as it is available, for a job started by either parse or extract. An extraction job\'s fields arrive in result.extracted_data. Send Accept text/event-stream for progress events as the job runs, ending in one result event whose data is this same JobResult.
|
|
146
|
+
* Get the status or result of a parse or extraction job
|
|
147
|
+
*/
|
|
148
|
+
async jobsGetRaw(requestParameters, initOverrides) {
|
|
149
|
+
const requestOptions = await this.jobsGetRequestOpts(requestParameters);
|
|
150
|
+
const response = await this.request(requestOptions, initOverrides);
|
|
151
|
+
return new runtime.JSONApiResponse(response, (jsonValue) => JobResultFromJSON(jsonValue));
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Returns the job\'s status, and its content as soon as it is available, for a job started by either parse or extract. An extraction job\'s fields arrive in result.extracted_data. Send Accept text/event-stream for progress events as the job runs, ending in one result event whose data is this same JobResult.
|
|
155
|
+
* Get the status or result of a parse or extraction job
|
|
156
|
+
*/
|
|
157
|
+
async jobsGet(requestParameters, initOverrides) {
|
|
158
|
+
const response = await this.jobsGetRaw(requestParameters, initOverrides);
|
|
159
|
+
return await response.value();
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Creates request options for jobsList without sending the request
|
|
163
|
+
*/
|
|
164
|
+
async jobsListRequestOpts(requestParameters) {
|
|
165
|
+
const queryParameters = {};
|
|
166
|
+
if (requestParameters['cursor'] != null) {
|
|
167
|
+
queryParameters['cursor'] = requestParameters['cursor'];
|
|
168
|
+
}
|
|
169
|
+
if (requestParameters['limit'] != null) {
|
|
170
|
+
queryParameters['limit'] = requestParameters['limit'];
|
|
171
|
+
}
|
|
172
|
+
if (requestParameters['status'] != null) {
|
|
173
|
+
queryParameters['status'] = requestParameters['status'];
|
|
174
|
+
}
|
|
175
|
+
const headerParameters = {};
|
|
176
|
+
if (this.configuration && this.configuration.apiKey) {
|
|
177
|
+
headerParameters["unstructured-api-key"] = await this.configuration.apiKey("unstructured-api-key"); // ApiKeyAuth authentication
|
|
178
|
+
}
|
|
179
|
+
if (this.configuration && this.configuration.accessToken) {
|
|
180
|
+
const token = this.configuration.accessToken;
|
|
181
|
+
const tokenString = await token("BearerAuth", []);
|
|
182
|
+
if (tokenString) {
|
|
183
|
+
headerParameters["Authorization"] = `Bearer ${tokenString}`;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
let urlPath = `/api/v2/jobs`;
|
|
187
|
+
return {
|
|
188
|
+
path: urlPath,
|
|
189
|
+
method: 'GET',
|
|
190
|
+
headers: headerParameters,
|
|
191
|
+
query: queryParameters,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Returns this caller\'s visible jobs, newest first. Tenant scope comes from the credential; the request has no tenant parameter.
|
|
196
|
+
* List parse and extraction jobs
|
|
197
|
+
*/
|
|
198
|
+
async jobsListRaw(requestParameters, initOverrides) {
|
|
199
|
+
const requestOptions = await this.jobsListRequestOpts(requestParameters);
|
|
200
|
+
const response = await this.request(requestOptions, initOverrides);
|
|
201
|
+
return new runtime.JSONApiResponse(response, (jsonValue) => JobPageFromJSON(jsonValue));
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Returns this caller\'s visible jobs, newest first. Tenant scope comes from the credential; the request has no tenant parameter.
|
|
205
|
+
* List parse and extraction jobs
|
|
206
|
+
*/
|
|
207
|
+
async jobsList(requestParameters = {}, initOverrides) {
|
|
208
|
+
const response = await this.jobsListRaw(requestParameters, initOverrides);
|
|
209
|
+
return await response.value();
|
|
210
|
+
}
|
|
211
|
+
}
|