@pdfvector/client 0.0.21 → 0.0.24
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/CHANGELOG.md +26 -0
- package/README.md +145 -35
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @pdfvector/client
|
|
2
2
|
|
|
3
|
+
## 0.0.24
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
- [#222](https://github.com/phuctm97/pdfvector/pull/222) [`3b78122`](https://github.com/phuctm97/pdfvector/commit/3b78122a35206b85be4ac61813ad1691ad57b866) Thanks [@khanhduyvt0101](https://github.com/khanhduyvt0101)! - Re-trigger releases for client, instance-client, and gateway-server (previous attempt failed at frozen-lockfile install before publish)
|
|
9
|
+
|
|
10
|
+
- Updated dependencies [[`3b78122`](https://github.com/phuctm97/pdfvector/commit/3b78122a35206b85be4ac61813ad1691ad57b866)]:
|
|
11
|
+
- @pdfvector/instance-client@0.0.44
|
|
12
|
+
|
|
13
|
+
## 0.0.23
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
- [#221](https://github.com/phuctm97/pdfvector/pull/221) [`84b9c58`](https://github.com/phuctm97/pdfvector/commit/84b9c58ce1a4f920e163f1666f738c83b3faa5c2) Thanks [@khanhduyvt0101](https://github.com/khanhduyvt0101)! - Add typed PDFVectorError class hierarchy to instance-client SDK
|
|
19
|
+
|
|
20
|
+
- Updated dependencies [[`84b9c58`](https://github.com/phuctm97/pdfvector/commit/84b9c58ce1a4f920e163f1666f738c83b3faa5c2)]:
|
|
21
|
+
- @pdfvector/instance-client@0.0.43
|
|
22
|
+
|
|
23
|
+
## 0.0.22
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- Updated dependencies [[`3a1c66b`](https://github.com/phuctm97/pdfvector/commit/3a1c66bcdfade057be5f1b9170f8ed64934bf2a9)]:
|
|
27
|
+
- @pdfvector/instance-client@0.0.42
|
|
28
|
+
|
|
3
29
|
## 0.0.21
|
|
4
30
|
### Patch Changes
|
|
5
31
|
|
package/README.md
CHANGED
|
@@ -580,16 +580,12 @@ console.log(resultB.documentId); // "doc-b"
|
|
|
580
580
|
|
|
581
581
|
## Error Handling
|
|
582
582
|
|
|
583
|
-
All errors thrown
|
|
584
|
-
transport-layer failures (DNS, connection refused, timeouts), which surface
|
|
585
|
-
with `code: "NETWORK_ERROR"` and `status: 0`.
|
|
583
|
+
All API errors are thrown as `PDFVectorError` instances. The SDK transparently maps every server error into the most specific subclass it can, so you can branch on the type using `instanceof` and read typed metadata fields directly.
|
|
586
584
|
|
|
587
585
|
```typescript
|
|
588
586
|
import { createClient, PDFVectorError } from "@pdfvector/client";
|
|
589
587
|
|
|
590
|
-
const client = createClient({
|
|
591
|
-
apiKey: "your-api-key",
|
|
592
|
-
});
|
|
588
|
+
const client = createClient({ apiKey: "your-api-key" });
|
|
593
589
|
|
|
594
590
|
try {
|
|
595
591
|
const result = await client.document.parse({
|
|
@@ -600,21 +596,72 @@ try {
|
|
|
600
596
|
if (error instanceof PDFVectorError) {
|
|
601
597
|
console.error(`API Error [${error.code}]: ${error.message}`);
|
|
602
598
|
console.error(`HTTP Status: ${error.status}`);
|
|
603
|
-
console.error(`
|
|
604
|
-
console.error(`
|
|
599
|
+
console.error(`Request ID: ${error.requestId}`); // server-assigned, useful for support
|
|
600
|
+
console.error(`Document ID: ${error.documentId}`); // echoed back if you set one
|
|
601
|
+
console.error(`User error: ${error.userError}`); // true if caused by your input
|
|
605
602
|
} else {
|
|
603
|
+
// Network errors (DNS, connection refused, timeout) bubble up as TypeError.
|
|
606
604
|
console.error("Unexpected Error:", error);
|
|
607
605
|
}
|
|
608
606
|
}
|
|
609
607
|
```
|
|
610
608
|
|
|
611
|
-
|
|
609
|
+
### Branching on specific error types
|
|
610
|
+
|
|
611
|
+
Every error class extends `PDFVectorError`, so you can use `instanceof` to handle specific cases. Specialized subclasses expose typed fields pulled from the error's `data` payload:
|
|
612
|
+
|
|
613
|
+
```typescript
|
|
614
|
+
import {
|
|
615
|
+
createClient,
|
|
616
|
+
FileTooLargeError,
|
|
617
|
+
PageLimitExceededError,
|
|
618
|
+
PasswordProtectedError,
|
|
619
|
+
URLFetchError,
|
|
620
|
+
UnauthorizedError,
|
|
621
|
+
TooManyRequestsError,
|
|
622
|
+
EmptyDocumentError,
|
|
623
|
+
ExtractionFailedError,
|
|
624
|
+
PDFVectorError,
|
|
625
|
+
} from "@pdfvector/client";
|
|
626
|
+
|
|
627
|
+
try {
|
|
628
|
+
await client.document.parse({ url: "...", model: "nano" });
|
|
629
|
+
} catch (error) {
|
|
630
|
+
if (error instanceof FileTooLargeError) {
|
|
631
|
+
console.error(
|
|
632
|
+
`File ${error.fileSizeMB}MB exceeds ${error.limitMB}MB limit for the '${error.model}' model`,
|
|
633
|
+
);
|
|
634
|
+
} else if (error instanceof PageLimitExceededError) {
|
|
635
|
+
console.error(
|
|
636
|
+
`Document has ${error.pageCount} pages — ${error.model} only supports up to ${error.pageLimit}`,
|
|
637
|
+
);
|
|
638
|
+
} else if (error instanceof PasswordProtectedError) {
|
|
639
|
+
console.error("Remove the password from the file and try again");
|
|
640
|
+
} else if (error instanceof URLFetchError) {
|
|
641
|
+
console.error(`Could not fetch ${error.url}: ${error.statusCode} ${error.statusText}`);
|
|
642
|
+
} else if (error instanceof UnauthorizedError) {
|
|
643
|
+
console.error("Invalid API key — check your dashboard");
|
|
644
|
+
} else if (error instanceof TooManyRequestsError) {
|
|
645
|
+
console.error(`Rate limit ${error.limit} exceeded; resets at ${error.resetAt}`);
|
|
646
|
+
} else if (error instanceof EmptyDocumentError) {
|
|
647
|
+
console.error("The document has no readable content");
|
|
648
|
+
} else if (error instanceof ExtractionFailedError) {
|
|
649
|
+
console.error(`Extraction failed. Hint: ${error.hint}`);
|
|
650
|
+
if (error.rawText) console.error(`Model output sample: ${error.rawText}`);
|
|
651
|
+
} else if (error instanceof PDFVectorError) {
|
|
652
|
+
// Catch-all for any error code not specifically handled
|
|
653
|
+
console.error(`API Error [${error.code}]: ${error.message}`);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
```
|
|
657
|
+
|
|
658
|
+
You can also branch on the error code if you prefer:
|
|
612
659
|
|
|
613
660
|
```typescript
|
|
614
661
|
try {
|
|
615
662
|
await client.document.parse({ url: "..." });
|
|
616
663
|
} catch (error) {
|
|
617
|
-
if (PDFVectorError
|
|
664
|
+
if (error instanceof PDFVectorError) {
|
|
618
665
|
switch (error.code) {
|
|
619
666
|
case "UNAUTHORIZED":
|
|
620
667
|
console.error("Invalid API key");
|
|
@@ -623,45 +670,82 @@ try {
|
|
|
623
670
|
console.error("Validation error:", error.message);
|
|
624
671
|
break;
|
|
625
672
|
case "UNPROCESSABLE_CONTENT":
|
|
626
|
-
|
|
627
|
-
console.error("The upload is unreadable or empty — please check the document.");
|
|
628
|
-
} else {
|
|
629
|
-
console.error("The server failed to process the document:", error.message);
|
|
630
|
-
}
|
|
631
|
-
break;
|
|
632
|
-
case "NETWORK_ERROR":
|
|
633
|
-
console.error("Could not reach the server. Check your network connection.");
|
|
673
|
+
console.error("Could not process document:", error.message);
|
|
634
674
|
break;
|
|
635
675
|
case "INTERNAL_SERVER_ERROR":
|
|
636
|
-
console.error(
|
|
676
|
+
console.error(`Server error (requestId: ${error.requestId}):`, error.message);
|
|
637
677
|
break;
|
|
638
678
|
}
|
|
639
679
|
}
|
|
640
680
|
}
|
|
641
681
|
```
|
|
642
682
|
|
|
683
|
+
### Error Class Hierarchy
|
|
684
|
+
|
|
685
|
+
```
|
|
686
|
+
PDFVectorError
|
|
687
|
+
├── BadRequestError (400)
|
|
688
|
+
│ ├── FileTooLargeError — fileSizeMB, limitMB, model
|
|
689
|
+
│ ├── PageLimitExceededError — pageCount, pageLimit, model
|
|
690
|
+
│ ├── PasswordProtectedError
|
|
691
|
+
│ ├── UnsupportedFormatError — format, supportedFormats
|
|
692
|
+
│ ├── URLFetchError — url, statusCode, statusText
|
|
693
|
+
│ ├── TierNotSupportedError — documentType, model, allowedTypes
|
|
694
|
+
│ ├── InvalidSchemaError — reason
|
|
695
|
+
│ └── NoInputProvidedError
|
|
696
|
+
├── UnauthorizedError (401)
|
|
697
|
+
├── NotFoundError (404)
|
|
698
|
+
├── ConflictError (409)
|
|
699
|
+
├── TooManyRequestsError (429) — limit, resetAt
|
|
700
|
+
├── UnprocessableContentError (422)
|
|
701
|
+
│ ├── EmptyDocumentError
|
|
702
|
+
│ ├── NoTextDetectedError
|
|
703
|
+
│ └── ExtractionFailedError — hint, rawText
|
|
704
|
+
├── InternalServerError (500)
|
|
705
|
+
└── NotImplementedError (501)
|
|
706
|
+
```
|
|
707
|
+
|
|
708
|
+
### Common fields on every `PDFVectorError`
|
|
709
|
+
|
|
710
|
+
| Field | Type | Description |
|
|
711
|
+
|-------|------|-------------|
|
|
712
|
+
| `code` | `string` | The ORPC error code (`BAD_REQUEST`, `UNAUTHORIZED`, etc.) |
|
|
713
|
+
| `status` | `number` | HTTP status code (400, 401, 404, 409, 422, 429, 500, 501) |
|
|
714
|
+
| `message` | `string` | Human-readable error message |
|
|
715
|
+
| `data` | `Record<string, unknown>` | Raw error payload from the server |
|
|
716
|
+
| `requestId` | `number \| undefined` | Server-assigned request ID — include in support tickets |
|
|
717
|
+
| `documentId` | `string \| undefined` | Echoed back if you passed `context.documentId` |
|
|
718
|
+
| `userError` | `boolean` | `true` if the failure was caused by your input (vs. a server-side issue) |
|
|
719
|
+
| `cause` | `unknown` | Original error (the underlying `ORPCError` from the wire) |
|
|
720
|
+
|
|
721
|
+
### Type guard
|
|
722
|
+
|
|
723
|
+
If you'd rather not import `PDFVectorError` just to do an `instanceof` check, use the `isPDFVectorError` guard:
|
|
724
|
+
|
|
725
|
+
```typescript
|
|
726
|
+
import { isPDFVectorError } from "@pdfvector/client";
|
|
727
|
+
|
|
728
|
+
try {
|
|
729
|
+
await client.document.parse({ url: "..." });
|
|
730
|
+
} catch (error) {
|
|
731
|
+
if (isPDFVectorError(error)) {
|
|
732
|
+
console.error(error.code, error.message, error.requestId);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
```
|
|
736
|
+
|
|
643
737
|
### Error Codes
|
|
644
738
|
|
|
645
739
|
| Code | Status | Description |
|
|
646
740
|
|------|--------|-------------|
|
|
647
|
-
| `BAD_REQUEST` | 400 | Input validation failed (e.g., missing fields, invalid URL,
|
|
741
|
+
| `BAD_REQUEST` | 400 | Input validation failed (e.g., missing fields, invalid URL, file too large, page limit exceeded, invalid JSON Schema) |
|
|
648
742
|
| `UNAUTHORIZED` | 401 | Missing or invalid API key |
|
|
649
|
-
| `NOT_FOUND` | 404 |
|
|
650
|
-
| `CONFLICT` | 409 |
|
|
651
|
-
| `UNPROCESSABLE_CONTENT` | 422 | Document could not be processed
|
|
743
|
+
| `NOT_FOUND` | 404 | Resource not found (e.g., academic paper ID, version) |
|
|
744
|
+
| `CONFLICT` | 409 | Operation conflicts with the current state |
|
|
745
|
+
| `UNPROCESSABLE_CONTENT` | 422 | Document could not be processed (empty, no readable text, extraction failed) |
|
|
652
746
|
| `TOO_MANY_REQUESTS` | 429 | Rate limit exceeded |
|
|
653
|
-
| `
|
|
654
|
-
| `
|
|
655
|
-
| `NETWORK_ERROR` | 0 | Transport-layer failure — the request never reached the server (DNS, connection refused, timeout, etc.). `error.data.cause` holds the underlying error. |
|
|
656
|
-
|
|
657
|
-
### User vs. system errors
|
|
658
|
-
|
|
659
|
-
Document-family endpoints (`document.*`, `invoice.*`, `identity.*`,
|
|
660
|
-
`bankStatement.*`) surface `error.userError === true` when the failure is
|
|
661
|
-
caused by the uploaded document itself (e.g. empty file, illegible image,
|
|
662
|
-
password-protected, unsupported content type). Use this flag to decide whether
|
|
663
|
-
to show the end user an actionable message or report a backend issue. The same
|
|
664
|
-
information is also available as `error.data.userError`.
|
|
747
|
+
| `INTERNAL_SERVER_ERROR` | 500 | Server-side failure — capture the `requestId` for support |
|
|
748
|
+
| `NOT_IMPLEMENTED` | 501 | Endpoint not available on this instance |
|
|
665
749
|
|
|
666
750
|
## TypeScript Support
|
|
667
751
|
|
|
@@ -670,7 +754,32 @@ The SDK is written in TypeScript and includes full type definitions:
|
|
|
670
754
|
```typescript
|
|
671
755
|
import {
|
|
672
756
|
createClient,
|
|
757
|
+
isPDFVectorError,
|
|
758
|
+
// Base error class — all errors inherit from this
|
|
673
759
|
PDFVectorError,
|
|
760
|
+
// HTTP-aligned error categories
|
|
761
|
+
BadRequestError,
|
|
762
|
+
UnauthorizedError,
|
|
763
|
+
NotFoundError,
|
|
764
|
+
ConflictError,
|
|
765
|
+
TooManyRequestsError,
|
|
766
|
+
UnprocessableContentError,
|
|
767
|
+
InternalServerError,
|
|
768
|
+
NotImplementedError,
|
|
769
|
+
// Specialized error subclasses with typed metadata
|
|
770
|
+
FileTooLargeError,
|
|
771
|
+
PageLimitExceededError,
|
|
772
|
+
PasswordProtectedError,
|
|
773
|
+
UnsupportedFormatError,
|
|
774
|
+
URLFetchError,
|
|
775
|
+
TierNotSupportedError,
|
|
776
|
+
InvalidSchemaError,
|
|
777
|
+
NoInputProvidedError,
|
|
778
|
+
EmptyDocumentError,
|
|
779
|
+
NoTextDetectedError,
|
|
780
|
+
ExtractionFailedError,
|
|
781
|
+
// Underlying ORPC error — re-exported for advanced use cases
|
|
782
|
+
ORPCError,
|
|
674
783
|
} from "@pdfvector/client";
|
|
675
784
|
|
|
676
785
|
import type {
|
|
@@ -680,6 +789,7 @@ import type {
|
|
|
680
789
|
ContractInputs,
|
|
681
790
|
ContractOutputs,
|
|
682
791
|
PDFVectorModel,
|
|
792
|
+
PDFVectorErrorCode,
|
|
683
793
|
} from "@pdfvector/client";
|
|
684
794
|
```
|
|
685
795
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pdfvector/client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Official TypeScript/JavaScript SDK for PDF Vector API",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"main": ".tsc/lib/index.js",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@pdfvector/instance-client": "^0.0.
|
|
26
|
+
"@pdfvector/instance-client": "^0.0.44"
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
29
|
".tsc",
|