@pdfvector/client 0.0.22 → 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.
Files changed (3) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +148 -13
  3. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
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
+
3
23
  ## 0.0.22
4
24
  ### Patch Changes
5
25
 
package/README.md CHANGED
@@ -580,14 +580,12 @@ console.log(resultB.documentId); // "doc-b"
580
580
 
581
581
  ## Error Handling
582
582
 
583
- All API errors are thrown as `ORPCError` instances with structured error information matching the server's error response shape:
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.
584
584
 
585
585
  ```typescript
586
- import { createClient, ORPCError } from "@pdfvector/client";
586
+ import { createClient, PDFVectorError } from "@pdfvector/client";
587
587
 
588
- const client = createClient({
589
- apiKey: "your-api-key",
590
- });
588
+ const client = createClient({ apiKey: "your-api-key" });
591
589
 
592
590
  try {
593
591
  const result = await client.document.parse({
@@ -595,10 +593,12 @@ try {
595
593
  });
596
594
  console.log(result.markdown);
597
595
  } catch (error) {
598
- if (error instanceof ORPCError) {
596
+ if (error instanceof PDFVectorError) {
599
597
  console.error(`API Error [${error.code}]: ${error.message}`);
600
598
  console.error(`HTTP Status: ${error.status}`);
601
- console.error(`Error Data:`, error.data);
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
602
602
  } else {
603
603
  // Network errors (DNS, connection refused, timeout) bubble up as TypeError.
604
604
  console.error("Unexpected Error:", error);
@@ -606,13 +606,62 @@ try {
606
606
  }
607
607
  ```
608
608
 
609
- You can branch on the error code:
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:
610
659
 
611
660
  ```typescript
612
661
  try {
613
662
  await client.document.parse({ url: "..." });
614
663
  } catch (error) {
615
- if (error instanceof ORPCError) {
664
+ if (error instanceof PDFVectorError) {
616
665
  switch (error.code) {
617
666
  case "UNAUTHORIZED":
618
667
  console.error("Invalid API key");
@@ -620,23 +669,83 @@ try {
620
669
  case "BAD_REQUEST":
621
670
  console.error("Validation error:", error.message);
622
671
  break;
672
+ case "UNPROCESSABLE_CONTENT":
673
+ console.error("Could not process document:", error.message);
674
+ break;
623
675
  case "INTERNAL_SERVER_ERROR":
624
- console.error("Server error:", error.message);
676
+ console.error(`Server error (requestId: ${error.requestId}):`, error.message);
625
677
  break;
626
678
  }
627
679
  }
628
680
  }
629
681
  ```
630
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
+
631
737
  ### Error Codes
632
738
 
633
739
  | Code | Status | Description |
634
740
  |------|--------|-------------|
635
- | `BAD_REQUEST` | 400 | Input validation failed (e.g., missing fields, invalid URL, question too short) |
741
+ | `BAD_REQUEST` | 400 | Input validation failed (e.g., missing fields, invalid URL, file too large, page limit exceeded, invalid JSON Schema) |
636
742
  | `UNAUTHORIZED` | 401 | Missing or invalid API key |
637
- | `UNPROCESSABLE_CONTENT` | 422 | Document could not be processed by the requested model tier |
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) |
638
746
  | `TOO_MANY_REQUESTS` | 429 | Rate limit exceeded |
639
- | `INTERNAL_SERVER_ERROR` | 500 | Server-side failure |
747
+ | `INTERNAL_SERVER_ERROR` | 500 | Server-side failure — capture the `requestId` for support |
748
+ | `NOT_IMPLEMENTED` | 501 | Endpoint not available on this instance |
640
749
 
641
750
  ## TypeScript Support
642
751
 
@@ -645,6 +754,31 @@ The SDK is written in TypeScript and includes full type definitions:
645
754
  ```typescript
646
755
  import {
647
756
  createClient,
757
+ isPDFVectorError,
758
+ // Base error class — all errors inherit from this
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
648
782
  ORPCError,
649
783
  } from "@pdfvector/client";
650
784
 
@@ -655,6 +789,7 @@ import type {
655
789
  ContractInputs,
656
790
  ContractOutputs,
657
791
  PDFVectorModel,
792
+ PDFVectorErrorCode,
658
793
  } from "@pdfvector/client";
659
794
  ```
660
795
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdfvector/client",
3
- "version": "0.0.22",
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.42"
26
+ "@pdfvector/instance-client": "^0.0.44"
27
27
  },
28
28
  "files": [
29
29
  ".tsc",