import { NdiClient } from "ndi-sdk";
const schema = {
type: "object",
properties: {
invoice_number: { type: "string" },
total: { type: "number" },
},
required: ["invoice_number", "total"],
};
const client = new NdiClient();
const upload = await client.documents.createUpload("invoice.pdf");
const parsed = await client.jobs.wait(
(await client.documents.parse(upload, { wait_seconds: 30 })).job_id,
);
const job = await client.jobs.wait(
(
await client.documents.extract(
{ type: "parse_result", job_id: parsed.job_id },
{ json_schema: schema, wait_seconds: 30 },
)
).job_id,
);
if (job.result?.result_type === "extract" && "fields" in job.result) {
console.log(job.result.data);
for (const field of job.result.fields) {
console.log(field.path, field.status, field.value);
}
}