sarvamai 1.1.2-alpha.4 → 1.1.2-alpha.5
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/cjs/BaseClient.js +2 -2
- package/dist/cjs/api/resources/docDigitizationJob/client/Client.d.ts +28 -0
- package/dist/cjs/api/resources/docDigitizationJob/client/Client.js +41 -0
- package/dist/cjs/api/resources/docDigitizationJob/client/DocDigitizationJobInstance.d.ts +82 -0
- package/dist/cjs/api/resources/docDigitizationJob/client/DocDigitizationJobInstance.js +268 -0
- package/dist/cjs/api/resources/docDigitizationJob/client/index.d.ts +1 -0
- package/dist/cjs/api/resources/docDigitizationJob/client/index.js +3 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/BaseClient.mjs +2 -2
- package/dist/esm/api/resources/docDigitizationJob/client/Client.d.mts +28 -0
- package/dist/esm/api/resources/docDigitizationJob/client/Client.mjs +41 -0
- package/dist/esm/api/resources/docDigitizationJob/client/DocDigitizationJobInstance.d.mts +82 -0
- package/dist/esm/api/resources/docDigitizationJob/client/DocDigitizationJobInstance.mjs +231 -0
- package/dist/esm/api/resources/docDigitizationJob/client/index.d.mts +1 -0
- package/dist/esm/api/resources/docDigitizationJob/client/index.mjs +1 -0
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +1 -1
package/dist/cjs/BaseClient.js
CHANGED
|
@@ -43,8 +43,8 @@ function normalizeClientOptions(options) {
|
|
|
43
43
|
const headers = (0, headers_js_1.mergeHeaders)({
|
|
44
44
|
"X-Fern-Language": "JavaScript",
|
|
45
45
|
"X-Fern-SDK-Name": "sarvamai",
|
|
46
|
-
"X-Fern-SDK-Version": "1.1.2-alpha.
|
|
47
|
-
"User-Agent": "sarvamai/1.1.2-alpha.
|
|
46
|
+
"X-Fern-SDK-Version": "1.1.2-alpha.5",
|
|
47
|
+
"User-Agent": "sarvamai/1.1.2-alpha.5",
|
|
48
48
|
"X-Fern-Runtime": core.RUNTIME.type,
|
|
49
49
|
"X-Fern-Runtime-Version": core.RUNTIME.version,
|
|
50
50
|
}, options === null || options === void 0 ? void 0 : options.headers);
|
|
@@ -2,6 +2,7 @@ import type { BaseClientOptions, BaseRequestOptions } from "../../../../BaseClie
|
|
|
2
2
|
import { type NormalizedClientOptionsWithAuth } from "../../../../BaseClient.js";
|
|
3
3
|
import * as core from "../../../../core/index.js";
|
|
4
4
|
import * as SarvamAI from "../../../index.js";
|
|
5
|
+
import { DocDigitizationJobInstance } from "./DocDigitizationJobInstance.js";
|
|
5
6
|
export declare namespace DocDigitizationJobClient {
|
|
6
7
|
interface Options extends BaseClientOptions {
|
|
7
8
|
}
|
|
@@ -164,4 +165,31 @@ export declare class DocDigitizationJobClient {
|
|
|
164
165
|
*/
|
|
165
166
|
getDownloadLinks(job_id: string, requestOptions?: DocDigitizationJobClient.RequestOptions): core.HttpResponsePromise<SarvamAI.DocDigitizationDownloadFilesResponse>;
|
|
166
167
|
private __getDownloadLinks;
|
|
168
|
+
/**
|
|
169
|
+
* Create a new Document Digitization job and return a job instance.
|
|
170
|
+
*
|
|
171
|
+
* @param language - ISO language code for the document (default: "hi")
|
|
172
|
+
* @param outputFormat - Output format: "html" or "md" (default: "html")
|
|
173
|
+
* @param callback - Optional webhook configuration for job completion notification
|
|
174
|
+
* @returns Promise<DocDigitizationJobInstance> - A job instance for managing the job
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* const job = await client.docDigitizationJob.createJob("hi", "md");
|
|
178
|
+
* await job.uploadFile("/path/to/document.pdf");
|
|
179
|
+
* await job.start();
|
|
180
|
+
* await job.waitUntilComplete();
|
|
181
|
+
* await job.downloadOutput("./output.md");
|
|
182
|
+
*/
|
|
183
|
+
createJob(language?: SarvamAI.DocDigitizationSupportedLanguage, outputFormat?: SarvamAI.DocDigitizationOutputFormat, callback?: SarvamAI.DocDigitizationWebhookCallback): Promise<DocDigitizationJobInstance>;
|
|
184
|
+
/**
|
|
185
|
+
* Get an existing Document Digitization job instance by job ID.
|
|
186
|
+
*
|
|
187
|
+
* @param jobId - The job ID of a previously created job
|
|
188
|
+
* @returns DocDigitizationJobInstance - A job instance for managing the job
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* const job = client.docDigitizationJob.getJob("your-job-uuid");
|
|
192
|
+
* const status = await job.getStatus();
|
|
193
|
+
*/
|
|
194
|
+
getJob(jobId: string): DocDigitizationJobInstance;
|
|
167
195
|
}
|
|
@@ -50,6 +50,7 @@ const core = __importStar(require("../../../../core/index.js"));
|
|
|
50
50
|
const environments = __importStar(require("../../../../environments.js"));
|
|
51
51
|
const errors = __importStar(require("../../../../errors/index.js"));
|
|
52
52
|
const SarvamAI = __importStar(require("../../../index.js"));
|
|
53
|
+
const DocDigitizationJobInstance_js_1 = require("./DocDigitizationJobInstance.js");
|
|
53
54
|
class DocDigitizationJobClient {
|
|
54
55
|
constructor(options = {}) {
|
|
55
56
|
this._options = (0, BaseClient_js_1.normalizeClientOptionsWithAuth)(options);
|
|
@@ -538,5 +539,45 @@ class DocDigitizationJobClient {
|
|
|
538
539
|
}
|
|
539
540
|
});
|
|
540
541
|
}
|
|
542
|
+
/**
|
|
543
|
+
* Create a new Document Digitization job and return a job instance.
|
|
544
|
+
*
|
|
545
|
+
* @param language - ISO language code for the document (default: "hi")
|
|
546
|
+
* @param outputFormat - Output format: "html" or "md" (default: "html")
|
|
547
|
+
* @param callback - Optional webhook configuration for job completion notification
|
|
548
|
+
* @returns Promise<DocDigitizationJobInstance> - A job instance for managing the job
|
|
549
|
+
*
|
|
550
|
+
* @example
|
|
551
|
+
* const job = await client.docDigitizationJob.createJob("hi", "md");
|
|
552
|
+
* await job.uploadFile("/path/to/document.pdf");
|
|
553
|
+
* await job.start();
|
|
554
|
+
* await job.waitUntilComplete();
|
|
555
|
+
* await job.downloadOutput("./output.md");
|
|
556
|
+
*/
|
|
557
|
+
createJob() {
|
|
558
|
+
return __awaiter(this, arguments, void 0, function* (language = "hi", outputFormat = "html", callback) {
|
|
559
|
+
const response = yield this.initialise({
|
|
560
|
+
job_parameters: {
|
|
561
|
+
language,
|
|
562
|
+
output_format: outputFormat,
|
|
563
|
+
},
|
|
564
|
+
callback,
|
|
565
|
+
});
|
|
566
|
+
return new DocDigitizationJobInstance_js_1.DocDigitizationJobInstance(response.job_id, this);
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Get an existing Document Digitization job instance by job ID.
|
|
571
|
+
*
|
|
572
|
+
* @param jobId - The job ID of a previously created job
|
|
573
|
+
* @returns DocDigitizationJobInstance - A job instance for managing the job
|
|
574
|
+
*
|
|
575
|
+
* @example
|
|
576
|
+
* const job = client.docDigitizationJob.getJob("your-job-uuid");
|
|
577
|
+
* const status = await job.getStatus();
|
|
578
|
+
*/
|
|
579
|
+
getJob(jobId) {
|
|
580
|
+
return new DocDigitizationJobInstance_js_1.DocDigitizationJobInstance(jobId, this);
|
|
581
|
+
}
|
|
541
582
|
}
|
|
542
583
|
exports.DocDigitizationJobClient = DocDigitizationJobClient;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type * as SarvamAI from "../../../index.js";
|
|
2
|
+
import type { DocDigitizationJobClient } from "./Client.js";
|
|
3
|
+
export declare class DocDigitizationJobInstance {
|
|
4
|
+
private _jobId;
|
|
5
|
+
private _client;
|
|
6
|
+
constructor(jobId: string, client: DocDigitizationJobClient);
|
|
7
|
+
/**
|
|
8
|
+
* Returns the job ID associated with this job instance.
|
|
9
|
+
*/
|
|
10
|
+
get jobId(): string;
|
|
11
|
+
/**
|
|
12
|
+
* Upload the input PDF or ZIP file for the document digitization job.
|
|
13
|
+
*
|
|
14
|
+
* @param filePath - Full path to local PDF or ZIP file
|
|
15
|
+
* @param timeoutInSeconds - The maximum time to wait for the upload to complete (default: 120)
|
|
16
|
+
* @returns Promise<boolean> - True if file is uploaded successfully
|
|
17
|
+
*/
|
|
18
|
+
uploadFile(filePath: string, _timeoutInSeconds?: number): Promise<boolean>;
|
|
19
|
+
/**
|
|
20
|
+
* Polls job status until it completes, partially completes, or fails.
|
|
21
|
+
*
|
|
22
|
+
* @param pollIntervalSeconds - Time in seconds between polling attempts (default: 5)
|
|
23
|
+
* @param timeoutSeconds - Maximum time to wait for completion in seconds (default: 1800)
|
|
24
|
+
* @returns Promise<SarvamAI.DocDigitizationJobStatusResponse> - Final job status
|
|
25
|
+
* @throws Error if the job does not complete within the given timeout
|
|
26
|
+
*/
|
|
27
|
+
waitUntilComplete(pollIntervalSeconds?: number, timeoutSeconds?: number): Promise<SarvamAI.DocDigitizationJobStatusResponse>;
|
|
28
|
+
/**
|
|
29
|
+
* Download the output file (HTML or Markdown) to the specified path.
|
|
30
|
+
*
|
|
31
|
+
* @param outputPath - Local file path where output will be saved
|
|
32
|
+
* @returns Promise<boolean> - True if download was successful
|
|
33
|
+
* @throws Error if download fails
|
|
34
|
+
*/
|
|
35
|
+
downloadOutput(outputPath: string): Promise<boolean>;
|
|
36
|
+
/**
|
|
37
|
+
* Retrieve the current status of the job.
|
|
38
|
+
*/
|
|
39
|
+
getStatus(): Promise<SarvamAI.DocDigitizationJobStatusResponse>;
|
|
40
|
+
/**
|
|
41
|
+
* Start the document digitization job processing.
|
|
42
|
+
*/
|
|
43
|
+
start(): Promise<SarvamAI.DocDigitizationJobStatusResponse>;
|
|
44
|
+
/**
|
|
45
|
+
* Get page processing metrics from the job status.
|
|
46
|
+
*
|
|
47
|
+
* @returns Object with total_pages, pages_processed, pages_succeeded, pages_failed
|
|
48
|
+
*/
|
|
49
|
+
getPageMetrics(): Promise<{
|
|
50
|
+
total_pages: number;
|
|
51
|
+
pages_processed: number;
|
|
52
|
+
pages_succeeded: number;
|
|
53
|
+
pages_failed: number;
|
|
54
|
+
} | null>;
|
|
55
|
+
/**
|
|
56
|
+
* Get any page-level errors from the job.
|
|
57
|
+
*
|
|
58
|
+
* @returns Array of page errors, or null if not available
|
|
59
|
+
*/
|
|
60
|
+
getPageErrors(): Promise<SarvamAI.DocDigitizationPageError[] | null>;
|
|
61
|
+
/**
|
|
62
|
+
* Check if the job exists in the system.
|
|
63
|
+
*/
|
|
64
|
+
exists(): Promise<boolean>;
|
|
65
|
+
/**
|
|
66
|
+
* Check if the job is complete (completed, partially completed, or failed).
|
|
67
|
+
*/
|
|
68
|
+
isComplete(): Promise<boolean>;
|
|
69
|
+
/**
|
|
70
|
+
* Check if the job completed successfully.
|
|
71
|
+
*/
|
|
72
|
+
isSuccessful(): Promise<boolean>;
|
|
73
|
+
/**
|
|
74
|
+
* Check if the job partially completed (some pages succeeded, some failed).
|
|
75
|
+
*/
|
|
76
|
+
isPartiallyCompleted(): Promise<boolean>;
|
|
77
|
+
/**
|
|
78
|
+
* Check if the job has failed.
|
|
79
|
+
*/
|
|
80
|
+
isFailed(): Promise<boolean>;
|
|
81
|
+
private getMimeType;
|
|
82
|
+
}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.DocDigitizationJobInstance = void 0;
|
|
46
|
+
const fs = __importStar(require("fs"));
|
|
47
|
+
const path = __importStar(require("path"));
|
|
48
|
+
class DocDigitizationJobInstance {
|
|
49
|
+
constructor(jobId, client) {
|
|
50
|
+
this._jobId = jobId;
|
|
51
|
+
this._client = client;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Returns the job ID associated with this job instance.
|
|
55
|
+
*/
|
|
56
|
+
get jobId() {
|
|
57
|
+
return this._jobId;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Upload the input PDF or ZIP file for the document digitization job.
|
|
61
|
+
*
|
|
62
|
+
* @param filePath - Full path to local PDF or ZIP file
|
|
63
|
+
* @param timeoutInSeconds - The maximum time to wait for the upload to complete (default: 120)
|
|
64
|
+
* @returns Promise<boolean> - True if file is uploaded successfully
|
|
65
|
+
*/
|
|
66
|
+
uploadFile(filePath_1) {
|
|
67
|
+
return __awaiter(this, arguments, void 0, function* (filePath, _timeoutInSeconds = 120) {
|
|
68
|
+
const fileName = path.basename(filePath);
|
|
69
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
70
|
+
if (ext !== ".pdf" && ext !== ".zip") {
|
|
71
|
+
throw new Error(`Only PDF or ZIP files are supported, got: ${ext}`);
|
|
72
|
+
}
|
|
73
|
+
const uploadLinksResponse = yield this._client.getUploadLinks({
|
|
74
|
+
job_id: this._jobId,
|
|
75
|
+
files: [fileName],
|
|
76
|
+
});
|
|
77
|
+
const url = uploadLinksResponse.upload_urls[fileName].file_url;
|
|
78
|
+
const fileBuffer = fs.readFileSync(filePath);
|
|
79
|
+
const mimeType = this.getMimeType(filePath);
|
|
80
|
+
const response = yield fetch(url, {
|
|
81
|
+
method: "PUT",
|
|
82
|
+
body: fileBuffer,
|
|
83
|
+
headers: {
|
|
84
|
+
"x-ms-blob-type": "BlockBlob",
|
|
85
|
+
"Content-Type": mimeType,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
if (response.status < 200 || response.status > 226) {
|
|
89
|
+
throw new Error(`Upload failed for ${fileName}: ${response.status}`);
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Polls job status until it completes, partially completes, or fails.
|
|
96
|
+
*
|
|
97
|
+
* @param pollIntervalSeconds - Time in seconds between polling attempts (default: 5)
|
|
98
|
+
* @param timeoutSeconds - Maximum time to wait for completion in seconds (default: 1800)
|
|
99
|
+
* @returns Promise<SarvamAI.DocDigitizationJobStatusResponse> - Final job status
|
|
100
|
+
* @throws Error if the job does not complete within the given timeout
|
|
101
|
+
*/
|
|
102
|
+
waitUntilComplete() {
|
|
103
|
+
return __awaiter(this, arguments, void 0, function* (pollIntervalSeconds = 5, timeoutSeconds = 1800) {
|
|
104
|
+
const startTime = Date.now();
|
|
105
|
+
const terminalStates = ["completed", "partiallycompleted", "failed"];
|
|
106
|
+
while (true) {
|
|
107
|
+
const status = yield this.getStatus();
|
|
108
|
+
const state = status.job_state.toLowerCase();
|
|
109
|
+
if (terminalStates.includes(state)) {
|
|
110
|
+
return status;
|
|
111
|
+
}
|
|
112
|
+
if (Date.now() - startTime > timeoutSeconds * 1000) {
|
|
113
|
+
throw new Error(`Job ${this._jobId} did not complete within ${timeoutSeconds} seconds. Current state: ${status.job_state}`);
|
|
114
|
+
}
|
|
115
|
+
yield new Promise((resolve) => setTimeout(resolve, pollIntervalSeconds * 1000));
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Download the output file (HTML or Markdown) to the specified path.
|
|
121
|
+
*
|
|
122
|
+
* @param outputPath - Local file path where output will be saved
|
|
123
|
+
* @returns Promise<boolean> - True if download was successful
|
|
124
|
+
* @throws Error if download fails
|
|
125
|
+
*/
|
|
126
|
+
downloadOutput(outputPath) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
const downloadLinksResponse = yield this._client.getDownloadLinks(this._jobId);
|
|
129
|
+
const downloadUrls = downloadLinksResponse.download_urls;
|
|
130
|
+
const fileNames = Object.keys(downloadUrls);
|
|
131
|
+
if (fileNames.length === 0) {
|
|
132
|
+
throw new Error("No download URL returned from API");
|
|
133
|
+
}
|
|
134
|
+
const url = downloadUrls[fileNames[0]].file_url;
|
|
135
|
+
const response = yield fetch(url);
|
|
136
|
+
if (response.status < 200 || response.status > 226) {
|
|
137
|
+
throw new Error(`Download failed: ${response.status}`);
|
|
138
|
+
}
|
|
139
|
+
// Create output directory if it doesn't exist
|
|
140
|
+
const outputDir = path.dirname(outputPath);
|
|
141
|
+
if (outputDir && !fs.existsSync(outputDir)) {
|
|
142
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
143
|
+
}
|
|
144
|
+
const buffer = yield response.arrayBuffer();
|
|
145
|
+
fs.writeFileSync(outputPath, Buffer.from(buffer));
|
|
146
|
+
return true;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Retrieve the current status of the job.
|
|
151
|
+
*/
|
|
152
|
+
getStatus() {
|
|
153
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
+
const response = yield this._client.getStatus(this._jobId);
|
|
155
|
+
return response;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Start the document digitization job processing.
|
|
160
|
+
*/
|
|
161
|
+
start() {
|
|
162
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
163
|
+
const response = yield this._client.start(this._jobId);
|
|
164
|
+
return response;
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Get page processing metrics from the job status.
|
|
169
|
+
*
|
|
170
|
+
* @returns Object with total_pages, pages_processed, pages_succeeded, pages_failed
|
|
171
|
+
*/
|
|
172
|
+
getPageMetrics() {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
var _a, _b, _c, _d;
|
|
175
|
+
const status = yield this.getStatus();
|
|
176
|
+
const jobDetails = status.job_details;
|
|
177
|
+
if (jobDetails && jobDetails.length > 0) {
|
|
178
|
+
const detail = jobDetails[0];
|
|
179
|
+
return {
|
|
180
|
+
total_pages: (_a = detail.total_pages) !== null && _a !== void 0 ? _a : 0,
|
|
181
|
+
pages_processed: (_b = detail.pages_processed) !== null && _b !== void 0 ? _b : 0,
|
|
182
|
+
pages_succeeded: (_c = detail.pages_succeeded) !== null && _c !== void 0 ? _c : 0,
|
|
183
|
+
pages_failed: (_d = detail.pages_failed) !== null && _d !== void 0 ? _d : 0,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
return null;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Get any page-level errors from the job.
|
|
191
|
+
*
|
|
192
|
+
* @returns Array of page errors, or null if not available
|
|
193
|
+
*/
|
|
194
|
+
getPageErrors() {
|
|
195
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
196
|
+
var _a;
|
|
197
|
+
const status = yield this.getStatus();
|
|
198
|
+
const jobDetails = status.job_details;
|
|
199
|
+
if (jobDetails && jobDetails.length > 0) {
|
|
200
|
+
return (_a = jobDetails[0].page_errors) !== null && _a !== void 0 ? _a : null;
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Check if the job exists in the system.
|
|
207
|
+
*/
|
|
208
|
+
exists() {
|
|
209
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
210
|
+
try {
|
|
211
|
+
yield this.getStatus();
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
if (error.statusCode && (error.statusCode === 404 || error.statusCode === 400)) {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
throw error;
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Check if the job is complete (completed, partially completed, or failed).
|
|
224
|
+
*/
|
|
225
|
+
isComplete() {
|
|
226
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
227
|
+
const status = yield this.getStatus();
|
|
228
|
+
const state = status.job_state.toLowerCase();
|
|
229
|
+
return state === "completed" || state === "partiallycompleted" || state === "failed";
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Check if the job completed successfully.
|
|
234
|
+
*/
|
|
235
|
+
isSuccessful() {
|
|
236
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
237
|
+
const status = yield this.getStatus();
|
|
238
|
+
return status.job_state.toLowerCase() === "completed";
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Check if the job partially completed (some pages succeeded, some failed).
|
|
243
|
+
*/
|
|
244
|
+
isPartiallyCompleted() {
|
|
245
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
246
|
+
const status = yield this.getStatus();
|
|
247
|
+
return status.job_state.toLowerCase() === "partiallycompleted";
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Check if the job has failed.
|
|
252
|
+
*/
|
|
253
|
+
isFailed() {
|
|
254
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
255
|
+
const status = yield this.getStatus();
|
|
256
|
+
return status.job_state.toLowerCase() === "failed";
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
getMimeType(filePath) {
|
|
260
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
261
|
+
const mimeTypes = {
|
|
262
|
+
".pdf": "application/pdf",
|
|
263
|
+
".zip": "application/zip",
|
|
264
|
+
};
|
|
265
|
+
return mimeTypes[ext] || "application/octet-stream";
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
exports.DocDigitizationJobInstance = DocDigitizationJobInstance;
|
|
@@ -14,4 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.DocDigitizationJobInstance = void 0;
|
|
17
18
|
__exportStar(require("./requests/index.js"), exports);
|
|
19
|
+
var DocDigitizationJobInstance_js_1 = require("./DocDigitizationJobInstance.js");
|
|
20
|
+
Object.defineProperty(exports, "DocDigitizationJobInstance", { enumerable: true, get: function () { return DocDigitizationJobInstance_js_1.DocDigitizationJobInstance; } });
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.1.2-alpha.
|
|
1
|
+
export declare const SDK_VERSION = "1.1.2-alpha.5";
|
package/dist/cjs/version.js
CHANGED
package/dist/esm/BaseClient.mjs
CHANGED
|
@@ -6,8 +6,8 @@ export function normalizeClientOptions(options) {
|
|
|
6
6
|
const headers = mergeHeaders({
|
|
7
7
|
"X-Fern-Language": "JavaScript",
|
|
8
8
|
"X-Fern-SDK-Name": "sarvamai",
|
|
9
|
-
"X-Fern-SDK-Version": "1.1.2-alpha.
|
|
10
|
-
"User-Agent": "sarvamai/1.1.2-alpha.
|
|
9
|
+
"X-Fern-SDK-Version": "1.1.2-alpha.5",
|
|
10
|
+
"User-Agent": "sarvamai/1.1.2-alpha.5",
|
|
11
11
|
"X-Fern-Runtime": core.RUNTIME.type,
|
|
12
12
|
"X-Fern-Runtime-Version": core.RUNTIME.version,
|
|
13
13
|
}, options === null || options === void 0 ? void 0 : options.headers);
|
|
@@ -2,6 +2,7 @@ import type { BaseClientOptions, BaseRequestOptions } from "../../../../BaseClie
|
|
|
2
2
|
import { type NormalizedClientOptionsWithAuth } from "../../../../BaseClient.mjs";
|
|
3
3
|
import * as core from "../../../../core/index.mjs";
|
|
4
4
|
import * as SarvamAI from "../../../index.mjs";
|
|
5
|
+
import { DocDigitizationJobInstance } from "./DocDigitizationJobInstance.mjs";
|
|
5
6
|
export declare namespace DocDigitizationJobClient {
|
|
6
7
|
interface Options extends BaseClientOptions {
|
|
7
8
|
}
|
|
@@ -164,4 +165,31 @@ export declare class DocDigitizationJobClient {
|
|
|
164
165
|
*/
|
|
165
166
|
getDownloadLinks(job_id: string, requestOptions?: DocDigitizationJobClient.RequestOptions): core.HttpResponsePromise<SarvamAI.DocDigitizationDownloadFilesResponse>;
|
|
166
167
|
private __getDownloadLinks;
|
|
168
|
+
/**
|
|
169
|
+
* Create a new Document Digitization job and return a job instance.
|
|
170
|
+
*
|
|
171
|
+
* @param language - ISO language code for the document (default: "hi")
|
|
172
|
+
* @param outputFormat - Output format: "html" or "md" (default: "html")
|
|
173
|
+
* @param callback - Optional webhook configuration for job completion notification
|
|
174
|
+
* @returns Promise<DocDigitizationJobInstance> - A job instance for managing the job
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* const job = await client.docDigitizationJob.createJob("hi", "md");
|
|
178
|
+
* await job.uploadFile("/path/to/document.pdf");
|
|
179
|
+
* await job.start();
|
|
180
|
+
* await job.waitUntilComplete();
|
|
181
|
+
* await job.downloadOutput("./output.md");
|
|
182
|
+
*/
|
|
183
|
+
createJob(language?: SarvamAI.DocDigitizationSupportedLanguage, outputFormat?: SarvamAI.DocDigitizationOutputFormat, callback?: SarvamAI.DocDigitizationWebhookCallback): Promise<DocDigitizationJobInstance>;
|
|
184
|
+
/**
|
|
185
|
+
* Get an existing Document Digitization job instance by job ID.
|
|
186
|
+
*
|
|
187
|
+
* @param jobId - The job ID of a previously created job
|
|
188
|
+
* @returns DocDigitizationJobInstance - A job instance for managing the job
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* const job = client.docDigitizationJob.getJob("your-job-uuid");
|
|
192
|
+
* const status = await job.getStatus();
|
|
193
|
+
*/
|
|
194
|
+
getJob(jobId: string): DocDigitizationJobInstance;
|
|
167
195
|
}
|
|
@@ -14,6 +14,7 @@ import * as core from "../../../../core/index.mjs";
|
|
|
14
14
|
import * as environments from "../../../../environments.mjs";
|
|
15
15
|
import * as errors from "../../../../errors/index.mjs";
|
|
16
16
|
import * as SarvamAI from "../../../index.mjs";
|
|
17
|
+
import { DocDigitizationJobInstance } from "./DocDigitizationJobInstance.mjs";
|
|
17
18
|
export class DocDigitizationJobClient {
|
|
18
19
|
constructor(options = {}) {
|
|
19
20
|
this._options = normalizeClientOptionsWithAuth(options);
|
|
@@ -502,4 +503,44 @@ export class DocDigitizationJobClient {
|
|
|
502
503
|
}
|
|
503
504
|
});
|
|
504
505
|
}
|
|
506
|
+
/**
|
|
507
|
+
* Create a new Document Digitization job and return a job instance.
|
|
508
|
+
*
|
|
509
|
+
* @param language - ISO language code for the document (default: "hi")
|
|
510
|
+
* @param outputFormat - Output format: "html" or "md" (default: "html")
|
|
511
|
+
* @param callback - Optional webhook configuration for job completion notification
|
|
512
|
+
* @returns Promise<DocDigitizationJobInstance> - A job instance for managing the job
|
|
513
|
+
*
|
|
514
|
+
* @example
|
|
515
|
+
* const job = await client.docDigitizationJob.createJob("hi", "md");
|
|
516
|
+
* await job.uploadFile("/path/to/document.pdf");
|
|
517
|
+
* await job.start();
|
|
518
|
+
* await job.waitUntilComplete();
|
|
519
|
+
* await job.downloadOutput("./output.md");
|
|
520
|
+
*/
|
|
521
|
+
createJob() {
|
|
522
|
+
return __awaiter(this, arguments, void 0, function* (language = "hi", outputFormat = "html", callback) {
|
|
523
|
+
const response = yield this.initialise({
|
|
524
|
+
job_parameters: {
|
|
525
|
+
language,
|
|
526
|
+
output_format: outputFormat,
|
|
527
|
+
},
|
|
528
|
+
callback,
|
|
529
|
+
});
|
|
530
|
+
return new DocDigitizationJobInstance(response.job_id, this);
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Get an existing Document Digitization job instance by job ID.
|
|
535
|
+
*
|
|
536
|
+
* @param jobId - The job ID of a previously created job
|
|
537
|
+
* @returns DocDigitizationJobInstance - A job instance for managing the job
|
|
538
|
+
*
|
|
539
|
+
* @example
|
|
540
|
+
* const job = client.docDigitizationJob.getJob("your-job-uuid");
|
|
541
|
+
* const status = await job.getStatus();
|
|
542
|
+
*/
|
|
543
|
+
getJob(jobId) {
|
|
544
|
+
return new DocDigitizationJobInstance(jobId, this);
|
|
545
|
+
}
|
|
505
546
|
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type * as SarvamAI from "../../../index.mjs";
|
|
2
|
+
import type { DocDigitizationJobClient } from "./Client.mjs";
|
|
3
|
+
export declare class DocDigitizationJobInstance {
|
|
4
|
+
private _jobId;
|
|
5
|
+
private _client;
|
|
6
|
+
constructor(jobId: string, client: DocDigitizationJobClient);
|
|
7
|
+
/**
|
|
8
|
+
* Returns the job ID associated with this job instance.
|
|
9
|
+
*/
|
|
10
|
+
get jobId(): string;
|
|
11
|
+
/**
|
|
12
|
+
* Upload the input PDF or ZIP file for the document digitization job.
|
|
13
|
+
*
|
|
14
|
+
* @param filePath - Full path to local PDF or ZIP file
|
|
15
|
+
* @param timeoutInSeconds - The maximum time to wait for the upload to complete (default: 120)
|
|
16
|
+
* @returns Promise<boolean> - True if file is uploaded successfully
|
|
17
|
+
*/
|
|
18
|
+
uploadFile(filePath: string, _timeoutInSeconds?: number): Promise<boolean>;
|
|
19
|
+
/**
|
|
20
|
+
* Polls job status until it completes, partially completes, or fails.
|
|
21
|
+
*
|
|
22
|
+
* @param pollIntervalSeconds - Time in seconds between polling attempts (default: 5)
|
|
23
|
+
* @param timeoutSeconds - Maximum time to wait for completion in seconds (default: 1800)
|
|
24
|
+
* @returns Promise<SarvamAI.DocDigitizationJobStatusResponse> - Final job status
|
|
25
|
+
* @throws Error if the job does not complete within the given timeout
|
|
26
|
+
*/
|
|
27
|
+
waitUntilComplete(pollIntervalSeconds?: number, timeoutSeconds?: number): Promise<SarvamAI.DocDigitizationJobStatusResponse>;
|
|
28
|
+
/**
|
|
29
|
+
* Download the output file (HTML or Markdown) to the specified path.
|
|
30
|
+
*
|
|
31
|
+
* @param outputPath - Local file path where output will be saved
|
|
32
|
+
* @returns Promise<boolean> - True if download was successful
|
|
33
|
+
* @throws Error if download fails
|
|
34
|
+
*/
|
|
35
|
+
downloadOutput(outputPath: string): Promise<boolean>;
|
|
36
|
+
/**
|
|
37
|
+
* Retrieve the current status of the job.
|
|
38
|
+
*/
|
|
39
|
+
getStatus(): Promise<SarvamAI.DocDigitizationJobStatusResponse>;
|
|
40
|
+
/**
|
|
41
|
+
* Start the document digitization job processing.
|
|
42
|
+
*/
|
|
43
|
+
start(): Promise<SarvamAI.DocDigitizationJobStatusResponse>;
|
|
44
|
+
/**
|
|
45
|
+
* Get page processing metrics from the job status.
|
|
46
|
+
*
|
|
47
|
+
* @returns Object with total_pages, pages_processed, pages_succeeded, pages_failed
|
|
48
|
+
*/
|
|
49
|
+
getPageMetrics(): Promise<{
|
|
50
|
+
total_pages: number;
|
|
51
|
+
pages_processed: number;
|
|
52
|
+
pages_succeeded: number;
|
|
53
|
+
pages_failed: number;
|
|
54
|
+
} | null>;
|
|
55
|
+
/**
|
|
56
|
+
* Get any page-level errors from the job.
|
|
57
|
+
*
|
|
58
|
+
* @returns Array of page errors, or null if not available
|
|
59
|
+
*/
|
|
60
|
+
getPageErrors(): Promise<SarvamAI.DocDigitizationPageError[] | null>;
|
|
61
|
+
/**
|
|
62
|
+
* Check if the job exists in the system.
|
|
63
|
+
*/
|
|
64
|
+
exists(): Promise<boolean>;
|
|
65
|
+
/**
|
|
66
|
+
* Check if the job is complete (completed, partially completed, or failed).
|
|
67
|
+
*/
|
|
68
|
+
isComplete(): Promise<boolean>;
|
|
69
|
+
/**
|
|
70
|
+
* Check if the job completed successfully.
|
|
71
|
+
*/
|
|
72
|
+
isSuccessful(): Promise<boolean>;
|
|
73
|
+
/**
|
|
74
|
+
* Check if the job partially completed (some pages succeeded, some failed).
|
|
75
|
+
*/
|
|
76
|
+
isPartiallyCompleted(): Promise<boolean>;
|
|
77
|
+
/**
|
|
78
|
+
* Check if the job has failed.
|
|
79
|
+
*/
|
|
80
|
+
isFailed(): Promise<boolean>;
|
|
81
|
+
private getMimeType;
|
|
82
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import * as fs from "fs";
|
|
11
|
+
import * as path from "path";
|
|
12
|
+
export class DocDigitizationJobInstance {
|
|
13
|
+
constructor(jobId, client) {
|
|
14
|
+
this._jobId = jobId;
|
|
15
|
+
this._client = client;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Returns the job ID associated with this job instance.
|
|
19
|
+
*/
|
|
20
|
+
get jobId() {
|
|
21
|
+
return this._jobId;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Upload the input PDF or ZIP file for the document digitization job.
|
|
25
|
+
*
|
|
26
|
+
* @param filePath - Full path to local PDF or ZIP file
|
|
27
|
+
* @param timeoutInSeconds - The maximum time to wait for the upload to complete (default: 120)
|
|
28
|
+
* @returns Promise<boolean> - True if file is uploaded successfully
|
|
29
|
+
*/
|
|
30
|
+
uploadFile(filePath_1) {
|
|
31
|
+
return __awaiter(this, arguments, void 0, function* (filePath, _timeoutInSeconds = 120) {
|
|
32
|
+
const fileName = path.basename(filePath);
|
|
33
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
34
|
+
if (ext !== ".pdf" && ext !== ".zip") {
|
|
35
|
+
throw new Error(`Only PDF or ZIP files are supported, got: ${ext}`);
|
|
36
|
+
}
|
|
37
|
+
const uploadLinksResponse = yield this._client.getUploadLinks({
|
|
38
|
+
job_id: this._jobId,
|
|
39
|
+
files: [fileName],
|
|
40
|
+
});
|
|
41
|
+
const url = uploadLinksResponse.upload_urls[fileName].file_url;
|
|
42
|
+
const fileBuffer = fs.readFileSync(filePath);
|
|
43
|
+
const mimeType = this.getMimeType(filePath);
|
|
44
|
+
const response = yield fetch(url, {
|
|
45
|
+
method: "PUT",
|
|
46
|
+
body: fileBuffer,
|
|
47
|
+
headers: {
|
|
48
|
+
"x-ms-blob-type": "BlockBlob",
|
|
49
|
+
"Content-Type": mimeType,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
if (response.status < 200 || response.status > 226) {
|
|
53
|
+
throw new Error(`Upload failed for ${fileName}: ${response.status}`);
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Polls job status until it completes, partially completes, or fails.
|
|
60
|
+
*
|
|
61
|
+
* @param pollIntervalSeconds - Time in seconds between polling attempts (default: 5)
|
|
62
|
+
* @param timeoutSeconds - Maximum time to wait for completion in seconds (default: 1800)
|
|
63
|
+
* @returns Promise<SarvamAI.DocDigitizationJobStatusResponse> - Final job status
|
|
64
|
+
* @throws Error if the job does not complete within the given timeout
|
|
65
|
+
*/
|
|
66
|
+
waitUntilComplete() {
|
|
67
|
+
return __awaiter(this, arguments, void 0, function* (pollIntervalSeconds = 5, timeoutSeconds = 1800) {
|
|
68
|
+
const startTime = Date.now();
|
|
69
|
+
const terminalStates = ["completed", "partiallycompleted", "failed"];
|
|
70
|
+
while (true) {
|
|
71
|
+
const status = yield this.getStatus();
|
|
72
|
+
const state = status.job_state.toLowerCase();
|
|
73
|
+
if (terminalStates.includes(state)) {
|
|
74
|
+
return status;
|
|
75
|
+
}
|
|
76
|
+
if (Date.now() - startTime > timeoutSeconds * 1000) {
|
|
77
|
+
throw new Error(`Job ${this._jobId} did not complete within ${timeoutSeconds} seconds. Current state: ${status.job_state}`);
|
|
78
|
+
}
|
|
79
|
+
yield new Promise((resolve) => setTimeout(resolve, pollIntervalSeconds * 1000));
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Download the output file (HTML or Markdown) to the specified path.
|
|
85
|
+
*
|
|
86
|
+
* @param outputPath - Local file path where output will be saved
|
|
87
|
+
* @returns Promise<boolean> - True if download was successful
|
|
88
|
+
* @throws Error if download fails
|
|
89
|
+
*/
|
|
90
|
+
downloadOutput(outputPath) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
const downloadLinksResponse = yield this._client.getDownloadLinks(this._jobId);
|
|
93
|
+
const downloadUrls = downloadLinksResponse.download_urls;
|
|
94
|
+
const fileNames = Object.keys(downloadUrls);
|
|
95
|
+
if (fileNames.length === 0) {
|
|
96
|
+
throw new Error("No download URL returned from API");
|
|
97
|
+
}
|
|
98
|
+
const url = downloadUrls[fileNames[0]].file_url;
|
|
99
|
+
const response = yield fetch(url);
|
|
100
|
+
if (response.status < 200 || response.status > 226) {
|
|
101
|
+
throw new Error(`Download failed: ${response.status}`);
|
|
102
|
+
}
|
|
103
|
+
// Create output directory if it doesn't exist
|
|
104
|
+
const outputDir = path.dirname(outputPath);
|
|
105
|
+
if (outputDir && !fs.existsSync(outputDir)) {
|
|
106
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
107
|
+
}
|
|
108
|
+
const buffer = yield response.arrayBuffer();
|
|
109
|
+
fs.writeFileSync(outputPath, Buffer.from(buffer));
|
|
110
|
+
return true;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Retrieve the current status of the job.
|
|
115
|
+
*/
|
|
116
|
+
getStatus() {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
const response = yield this._client.getStatus(this._jobId);
|
|
119
|
+
return response;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Start the document digitization job processing.
|
|
124
|
+
*/
|
|
125
|
+
start() {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
const response = yield this._client.start(this._jobId);
|
|
128
|
+
return response;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Get page processing metrics from the job status.
|
|
133
|
+
*
|
|
134
|
+
* @returns Object with total_pages, pages_processed, pages_succeeded, pages_failed
|
|
135
|
+
*/
|
|
136
|
+
getPageMetrics() {
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
var _a, _b, _c, _d;
|
|
139
|
+
const status = yield this.getStatus();
|
|
140
|
+
const jobDetails = status.job_details;
|
|
141
|
+
if (jobDetails && jobDetails.length > 0) {
|
|
142
|
+
const detail = jobDetails[0];
|
|
143
|
+
return {
|
|
144
|
+
total_pages: (_a = detail.total_pages) !== null && _a !== void 0 ? _a : 0,
|
|
145
|
+
pages_processed: (_b = detail.pages_processed) !== null && _b !== void 0 ? _b : 0,
|
|
146
|
+
pages_succeeded: (_c = detail.pages_succeeded) !== null && _c !== void 0 ? _c : 0,
|
|
147
|
+
pages_failed: (_d = detail.pages_failed) !== null && _d !== void 0 ? _d : 0,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
return null;
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Get any page-level errors from the job.
|
|
155
|
+
*
|
|
156
|
+
* @returns Array of page errors, or null if not available
|
|
157
|
+
*/
|
|
158
|
+
getPageErrors() {
|
|
159
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
var _a;
|
|
161
|
+
const status = yield this.getStatus();
|
|
162
|
+
const jobDetails = status.job_details;
|
|
163
|
+
if (jobDetails && jobDetails.length > 0) {
|
|
164
|
+
return (_a = jobDetails[0].page_errors) !== null && _a !== void 0 ? _a : null;
|
|
165
|
+
}
|
|
166
|
+
return null;
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Check if the job exists in the system.
|
|
171
|
+
*/
|
|
172
|
+
exists() {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
try {
|
|
175
|
+
yield this.getStatus();
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
if (error.statusCode && (error.statusCode === 404 || error.statusCode === 400)) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Check if the job is complete (completed, partially completed, or failed).
|
|
188
|
+
*/
|
|
189
|
+
isComplete() {
|
|
190
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
const status = yield this.getStatus();
|
|
192
|
+
const state = status.job_state.toLowerCase();
|
|
193
|
+
return state === "completed" || state === "partiallycompleted" || state === "failed";
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Check if the job completed successfully.
|
|
198
|
+
*/
|
|
199
|
+
isSuccessful() {
|
|
200
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
201
|
+
const status = yield this.getStatus();
|
|
202
|
+
return status.job_state.toLowerCase() === "completed";
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Check if the job partially completed (some pages succeeded, some failed).
|
|
207
|
+
*/
|
|
208
|
+
isPartiallyCompleted() {
|
|
209
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
210
|
+
const status = yield this.getStatus();
|
|
211
|
+
return status.job_state.toLowerCase() === "partiallycompleted";
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Check if the job has failed.
|
|
216
|
+
*/
|
|
217
|
+
isFailed() {
|
|
218
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
219
|
+
const status = yield this.getStatus();
|
|
220
|
+
return status.job_state.toLowerCase() === "failed";
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
getMimeType(filePath) {
|
|
224
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
225
|
+
const mimeTypes = {
|
|
226
|
+
".pdf": "application/pdf",
|
|
227
|
+
".zip": "application/zip",
|
|
228
|
+
};
|
|
229
|
+
return mimeTypes[ext] || "application/octet-stream";
|
|
230
|
+
}
|
|
231
|
+
}
|
package/dist/esm/version.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.1.2-alpha.
|
|
1
|
+
export declare const SDK_VERSION = "1.1.2-alpha.5";
|
package/dist/esm/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "1.1.2-alpha.
|
|
1
|
+
export const SDK_VERSION = "1.1.2-alpha.5";
|