@pdfvector/instance-client 0.0.40 → 0.0.42

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.
@@ -1,61 +1,13 @@
1
- import type { ContractRouterClient } from "@orpc/contract";
2
- import type { contract } from "@pdfvector/instance-contract";
1
+ import { type ContractRouterClient, type contract } from "@pdfvector/instance-contract";
3
2
  export interface CreateClientOptions {
4
- /** Domain of the PDF Vector instance server (e.g., "your-instance.pdfvector.com"). Defaults to "global.pdfvector.com". */
3
+ /** Defaults to "global.pdfvector.com". */
5
4
  domain?: string;
6
- /** API key for Bearer token authentication */
7
5
  apiKey?: string;
8
- /** @internal Server secret */
9
- secret?: string;
10
- /** @internal Additional headers merged into every outgoing request (e.g. forwarded IP) */
11
- forwardedHeaders?: Record<string, string>;
12
6
  }
13
- /** Per-request context passed as the second argument to any API call. */
14
7
  export interface ClientContext {
15
- /** Document ID for usage tracking. Returned in response for document, identity, invoice, and bank statement endpoints. */
8
+ /** Optional ID echoed back in responses, used for per-document usage tracking. */
16
9
  documentId?: string;
17
10
  }
18
- /**
19
- * Custom error class for PDF Vector API errors.
20
- *
21
- * All API errors thrown by the client are instances of this class.
22
- * Provides structured access to error code, HTTP status, message, and additional data.
23
- *
24
- * @example
25
- * ```typescript
26
- * try {
27
- * await client.document.parse({ url: "..." });
28
- * } catch (error) {
29
- * if (error instanceof PDFVectorError) {
30
- * console.error(error.code); // "UNAUTHORIZED" | "BAD_REQUEST" | ...
31
- * console.error(error.status); // 401 | 400 | 422 | 500
32
- * console.error(error.message); // "Invalid API key"
33
- * console.error(error.data); // { requestId: 1 }
34
- * }
35
- * }
36
- * ```
37
- */
38
- export declare class PDFVectorError extends Error {
39
- /** Error code identifying the type of error */
40
- readonly code: string;
41
- /** HTTP status code */
42
- readonly status: number;
43
- /** Additional error data from the server (e.g., requestId) */
44
- readonly data: unknown;
45
- constructor(options: {
46
- code: string;
47
- message: string;
48
- status: number;
49
- data?: unknown;
50
- });
51
- /**
52
- * Type guard to check if an unknown error is a PDFVectorError.
53
- */
54
- static is(error: unknown): error is PDFVectorError;
55
- }
56
- /** @internal */
57
- export declare function _buildClient(options?: CreateClientOptions): Client;
58
- export declare function createClient(options?: CreateClientOptions): PublicClient;
59
- type Client = ContractRouterClient<typeof contract, ClientContext>;
60
- export type PublicClient = Omit<ContractRouterClient<typeof contract, ClientContext>, "admin" | "free">;
61
- export type { ContractInputs, ContractOutputs, PDFVectorModel, } from "@pdfvector/instance-contract";
11
+ export type Client = Omit<ContractRouterClient<typeof contract, ClientContext>, "admin" | "free">;
12
+ export declare function createClient(options?: CreateClientOptions): Client;
13
+ export * from "@pdfvector/instance-contract";
package/.tsc/lib/index.js CHANGED
@@ -1,85 +1,22 @@
1
- import { createORPCClient, ORPCError, onError } from "@orpc/client";
2
- import { RPCLink } from "@orpc/client/fetch";
1
+ import { createORPCClient, RPCLink, } from "@pdfvector/instance-contract";
3
2
  const DEFAULT_DOMAIN = "global.pdfvector.com";
4
- /**
5
- * Custom error class for PDF Vector API errors.
6
- *
7
- * All API errors thrown by the client are instances of this class.
8
- * Provides structured access to error code, HTTP status, message, and additional data.
9
- *
10
- * @example
11
- * ```typescript
12
- * try {
13
- * await client.document.parse({ url: "..." });
14
- * } catch (error) {
15
- * if (error instanceof PDFVectorError) {
16
- * console.error(error.code); // "UNAUTHORIZED" | "BAD_REQUEST" | ...
17
- * console.error(error.status); // 401 | 400 | 422 | 500
18
- * console.error(error.message); // "Invalid API key"
19
- * console.error(error.data); // { requestId: 1 }
20
- * }
21
- * }
22
- * ```
23
- */
24
- export class PDFVectorError extends Error {
25
- /** Error code identifying the type of error */
26
- code;
27
- /** HTTP status code */
28
- status;
29
- /** Additional error data from the server (e.g., requestId) */
30
- data;
31
- constructor(options) {
32
- super(options.message);
33
- this.name = "PDFVectorError";
34
- this.code = options.code;
35
- this.status = options.status;
36
- this.data = options.data;
37
- }
38
- /**
39
- * Type guard to check if an unknown error is a PDFVectorError.
40
- */
41
- static is(error) {
42
- return error instanceof PDFVectorError;
43
- }
44
- }
45
- /** @internal */
46
- export function _buildClient(options) {
3
+ export function createClient(options) {
47
4
  const domain = options?.domain ?? DEFAULT_DOMAIN;
48
5
  const isLocal = domain.startsWith("localhost") || domain.startsWith("127.0.0.1");
49
6
  const baseUrl = `${isLocal ? "http" : "https"}://${domain}`;
50
- const token = options?.apiKey ?? options?.secret;
7
+ const token = options?.apiKey;
51
8
  const link = new RPCLink({
52
9
  url: `${baseUrl}/rpc`,
53
10
  headers: ({ context }) => {
54
- const headers = {
55
- ...options?.forwardedHeaders,
56
- };
57
- if (token) {
11
+ const headers = {};
12
+ if (token)
58
13
  headers.authorization = `Bearer ${token}`;
59
- }
60
- if (context?.documentId) {
14
+ if (context?.documentId)
61
15
  headers["x-pdfvector-document-id"] = context.documentId;
62
- }
63
16
  return headers;
64
17
  },
65
- fetch: token
66
- ? undefined
67
- : (input, init) => fetch(input, { ...init, credentials: "include" }),
68
- interceptors: [
69
- onError((error) => {
70
- if (error instanceof ORPCError) {
71
- throw new PDFVectorError({
72
- code: error.code,
73
- message: error.message,
74
- status: error.status,
75
- data: error.data,
76
- });
77
- }
78
- }),
79
- ],
18
+ fetch: (input, init) => fetch(input, token ? init : { ...init, credentials: "include" }),
80
19
  });
81
20
  return createORPCClient(link);
82
21
  }
83
- export function createClient(options) {
84
- return _buildClient(options);
85
- }
22
+ export * from "@pdfvector/instance-contract";
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @pdfvector/instance-client
2
2
 
3
+ ## 0.0.42
4
+ ### Patch Changes
5
+
6
+
7
+
8
+ - [#214](https://github.com/phuctm97/pdfvector/pull/214) [`3a1c66b`](https://github.com/phuctm97/pdfvector/commit/3a1c66bcdfade057be5f1b9170f8ed64934bf2a9) Thanks [@khanhduyvt0101](https://github.com/khanhduyvt0101)! - Fix PDFVECTOR-INSTANCE-T and slim instance-client SDK
9
+
10
+ - Updated dependencies [[`3a1c66b`](https://github.com/phuctm97/pdfvector/commit/3a1c66bcdfade057be5f1b9170f8ed64934bf2a9)]:
11
+ - @pdfvector/instance-contract@0.0.41
12
+
13
+ ## 0.0.41
14
+ ### Patch Changes
15
+
16
+
17
+
18
+ - [#205](https://github.com/phuctm97/pdfvector/pull/205) [`93b9624`](https://github.com/phuctm97/pdfvector/commit/93b9624333f643b143062e08c6af216eed5a859a) Thanks [@khanhduyvt0101](https://github.com/khanhduyvt0101)! - Improve SDK error handling and tighten academic provider types
19
+
20
+ - Updated dependencies [[`93b9624`](https://github.com/phuctm97/pdfvector/commit/93b9624333f643b143062e08c6af216eed5a859a)]:
21
+ - @pdfvector/instance-contract@0.0.40
22
+
3
23
  ## 0.0.40
4
24
  ### Patch Changes
5
25
 
package/README.md CHANGED
@@ -580,10 +580,10 @@ console.log(resultB.documentId); // "doc-b"
580
580
 
581
581
  ## Error Handling
582
582
 
583
- All API errors are thrown as `PDFVectorError` instances with structured error information:
583
+ All API errors are thrown as `ORPCError` instances with structured error information matching the server's error response shape:
584
584
 
585
585
  ```typescript
586
- import { createClient, PDFVectorError } from "@pdfvector/instance-client";
586
+ import { createClient, ORPCError } from "@pdfvector/instance-client";
587
587
 
588
588
  const client = createClient({
589
589
  apiKey: "your-api-key",
@@ -595,23 +595,24 @@ try {
595
595
  });
596
596
  console.log(result.markdown);
597
597
  } catch (error) {
598
- if (error instanceof PDFVectorError) {
598
+ if (error instanceof ORPCError) {
599
599
  console.error(`API Error [${error.code}]: ${error.message}`);
600
600
  console.error(`HTTP Status: ${error.status}`);
601
601
  console.error(`Error Data:`, error.data);
602
602
  } else {
603
+ // Network errors (DNS, connection refused, timeout) bubble up as TypeError.
603
604
  console.error("Unexpected Error:", error);
604
605
  }
605
606
  }
606
607
  ```
607
608
 
608
- You can also use the static type guard:
609
+ You can branch on the error code:
609
610
 
610
611
  ```typescript
611
612
  try {
612
613
  await client.document.parse({ url: "..." });
613
614
  } catch (error) {
614
- if (PDFVectorError.is(error)) {
615
+ if (error instanceof ORPCError) {
615
616
  switch (error.code) {
616
617
  case "UNAUTHORIZED":
617
618
  console.error("Invalid API key");
@@ -644,7 +645,7 @@ The SDK is written in TypeScript and includes full type definitions:
644
645
  ```typescript
645
646
  import {
646
647
  createClient,
647
- PDFVectorError,
648
+ ORPCError,
648
649
  } from "@pdfvector/instance-client";
649
650
 
650
651
  import type {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdfvector/instance-client",
3
- "version": "0.0.40",
3
+ "version": "0.0.42",
4
4
  "type": "module",
5
5
  "description": "Official TypeScript/JavaScript SDK for PDF Vector API - Parse PDF/Word/Image/Excel documents to clean, structured markdown format and search academic publications across multiple databases",
6
6
  "license": "MIT",
@@ -33,12 +33,11 @@
33
33
  },
34
34
  "main": ".tsc/lib/index.js",
35
35
  "dependencies": {
36
- "@orpc/client": "^1.13.14",
37
- "@orpc/contract": "^1.13.14",
38
- "@pdfvector/instance-contract": "^0.0.39"
36
+ "@pdfvector/instance-contract": "^0.0.41"
39
37
  },
40
38
  "files": [
41
39
  ".tsc",
42
- "CHANGELOG.md"
40
+ "CHANGELOG.md",
41
+ "README.md"
43
42
  ]
44
43
  }
@@ -1,5 +0,0 @@
1
- import type { ContractRouterClient } from "@orpc/contract";
2
- import type { contract } from "@pdfvector/instance-contract";
3
- import { type ClientContext, type CreateClientOptions } from ".";
4
- export type Client = ContractRouterClient<typeof contract, ClientContext>;
5
- export declare function createInternalClient(options?: CreateClientOptions): Client;
@@ -1,4 +0,0 @@
1
- import { _buildClient } from ".";
2
- export function createInternalClient(options) {
3
- return _buildClient(options);
4
- }