@pdfvector/instance-client 0.0.41 → 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.
- package/.tsc/lib/index.d.ts +6 -62
- package/.tsc/lib/index.js +8 -101
- package/CHANGELOG.md +10 -0
- package/README.md +7 -6
- package/package.json +4 -5
- package/.tsc/lib/internal.d.ts +0 -5
- package/.tsc/lib/internal.js +0 -4
package/.tsc/lib/index.d.ts
CHANGED
|
@@ -1,69 +1,13 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { contract } from "@pdfvector/instance-contract";
|
|
1
|
+
import { type ContractRouterClient, type contract } from "@pdfvector/instance-contract";
|
|
3
2
|
export interface CreateClientOptions {
|
|
4
|
-
/**
|
|
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
|
-
/**
|
|
8
|
+
/** Optional ID echoed back in responses, used for per-document usage tracking. */
|
|
16
9
|
documentId?: string;
|
|
17
10
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*
|
|
21
|
-
* All errors thrown by the client are instances of this class, including
|
|
22
|
-
* transport-layer failures (DNS, connection refused, timeouts) which surface
|
|
23
|
-
* with `code: "NETWORK_ERROR"` and `status: 0`.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```typescript
|
|
27
|
-
* try {
|
|
28
|
-
* await client.document.parse({ url: "..." });
|
|
29
|
-
* } catch (error) {
|
|
30
|
-
* if (error instanceof PDFVectorError) {
|
|
31
|
-
* console.error(error.code); // "UNAUTHORIZED" | "BAD_REQUEST" | "NETWORK_ERROR" | ...
|
|
32
|
-
* console.error(error.status); // 401 | 400 | 422 | 500 | 0 (network)
|
|
33
|
-
* console.error(error.message); // "Invalid API key"
|
|
34
|
-
* console.error(error.userError); // true if the error is caused by user input (illegible upload, etc.)
|
|
35
|
-
* console.error(error.data); // { requestId: 1, userError: true }
|
|
36
|
-
* }
|
|
37
|
-
* }
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
export declare class PDFVectorError extends Error {
|
|
41
|
-
/** Error code identifying the type of error */
|
|
42
|
-
readonly code: string;
|
|
43
|
-
/** HTTP status code. `0` for transport-layer failures (see `NETWORK_ERROR`). */
|
|
44
|
-
readonly status: number;
|
|
45
|
-
/** Additional error data from the server (e.g., `requestId`, `userError`) */
|
|
46
|
-
readonly data: unknown;
|
|
47
|
-
/**
|
|
48
|
-
* True when the server flagged this error as caused by user input
|
|
49
|
-
* (e.g. illegible uploads, empty documents) rather than a server-side
|
|
50
|
-
* failure. Mirrors `data.userError === true`.
|
|
51
|
-
*/
|
|
52
|
-
readonly userError: boolean;
|
|
53
|
-
constructor(options: {
|
|
54
|
-
code: string;
|
|
55
|
-
message: string;
|
|
56
|
-
status: number;
|
|
57
|
-
data?: unknown;
|
|
58
|
-
});
|
|
59
|
-
/**
|
|
60
|
-
* Type guard to check if an unknown error is a PDFVectorError.
|
|
61
|
-
*/
|
|
62
|
-
static is(error: unknown): error is PDFVectorError;
|
|
63
|
-
}
|
|
64
|
-
/** @internal */
|
|
65
|
-
export declare function _buildClient(options?: CreateClientOptions): Client;
|
|
66
|
-
export declare function createClient(options?: CreateClientOptions): PublicClient;
|
|
67
|
-
type Client = ContractRouterClient<typeof contract, ClientContext>;
|
|
68
|
-
export type PublicClient = Omit<ContractRouterClient<typeof contract, ClientContext>, "admin" | "free">;
|
|
69
|
-
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,115 +1,22 @@
|
|
|
1
|
-
import { createORPCClient,
|
|
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 errors thrown by the client are instances of this class, including
|
|
8
|
-
* transport-layer failures (DNS, connection refused, timeouts) which surface
|
|
9
|
-
* with `code: "NETWORK_ERROR"` and `status: 0`.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* try {
|
|
14
|
-
* await client.document.parse({ url: "..." });
|
|
15
|
-
* } catch (error) {
|
|
16
|
-
* if (error instanceof PDFVectorError) {
|
|
17
|
-
* console.error(error.code); // "UNAUTHORIZED" | "BAD_REQUEST" | "NETWORK_ERROR" | ...
|
|
18
|
-
* console.error(error.status); // 401 | 400 | 422 | 500 | 0 (network)
|
|
19
|
-
* console.error(error.message); // "Invalid API key"
|
|
20
|
-
* console.error(error.userError); // true if the error is caused by user input (illegible upload, etc.)
|
|
21
|
-
* console.error(error.data); // { requestId: 1, userError: true }
|
|
22
|
-
* }
|
|
23
|
-
* }
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export class PDFVectorError extends Error {
|
|
27
|
-
/** Error code identifying the type of error */
|
|
28
|
-
code;
|
|
29
|
-
/** HTTP status code. `0` for transport-layer failures (see `NETWORK_ERROR`). */
|
|
30
|
-
status;
|
|
31
|
-
/** Additional error data from the server (e.g., `requestId`, `userError`) */
|
|
32
|
-
data;
|
|
33
|
-
/**
|
|
34
|
-
* True when the server flagged this error as caused by user input
|
|
35
|
-
* (e.g. illegible uploads, empty documents) rather than a server-side
|
|
36
|
-
* failure. Mirrors `data.userError === true`.
|
|
37
|
-
*/
|
|
38
|
-
userError;
|
|
39
|
-
constructor(options) {
|
|
40
|
-
super(options.message);
|
|
41
|
-
this.name = "PDFVectorError";
|
|
42
|
-
this.code = options.code;
|
|
43
|
-
this.status = options.status;
|
|
44
|
-
this.data = options.data;
|
|
45
|
-
this.userError =
|
|
46
|
-
options.data != null &&
|
|
47
|
-
typeof options.data === "object" &&
|
|
48
|
-
options.data.userError === true;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Type guard to check if an unknown error is a PDFVectorError.
|
|
52
|
-
*/
|
|
53
|
-
static is(error) {
|
|
54
|
-
return error instanceof PDFVectorError;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/** @internal */
|
|
58
|
-
export function _buildClient(options) {
|
|
3
|
+
export function createClient(options) {
|
|
59
4
|
const domain = options?.domain ?? DEFAULT_DOMAIN;
|
|
60
5
|
const isLocal = domain.startsWith("localhost") || domain.startsWith("127.0.0.1");
|
|
61
6
|
const baseUrl = `${isLocal ? "http" : "https"}://${domain}`;
|
|
62
|
-
const token = options?.apiKey
|
|
63
|
-
const wrappedFetch = async (input, init) => {
|
|
64
|
-
try {
|
|
65
|
-
return await (token
|
|
66
|
-
? fetch(input, init)
|
|
67
|
-
: fetch(input, { ...init, credentials: "include" }));
|
|
68
|
-
}
|
|
69
|
-
catch (err) {
|
|
70
|
-
throw new PDFVectorError({
|
|
71
|
-
code: "NETWORK_ERROR",
|
|
72
|
-
message: err instanceof Error
|
|
73
|
-
? err.message
|
|
74
|
-
: "Network request failed before reaching the server",
|
|
75
|
-
status: 0,
|
|
76
|
-
data: { cause: err },
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
};
|
|
7
|
+
const token = options?.apiKey;
|
|
80
8
|
const link = new RPCLink({
|
|
81
9
|
url: `${baseUrl}/rpc`,
|
|
82
10
|
headers: ({ context }) => {
|
|
83
|
-
const headers = {
|
|
84
|
-
|
|
85
|
-
};
|
|
86
|
-
if (token) {
|
|
11
|
+
const headers = {};
|
|
12
|
+
if (token)
|
|
87
13
|
headers.authorization = `Bearer ${token}`;
|
|
88
|
-
|
|
89
|
-
if (context?.documentId) {
|
|
14
|
+
if (context?.documentId)
|
|
90
15
|
headers["x-pdfvector-document-id"] = context.documentId;
|
|
91
|
-
}
|
|
92
16
|
return headers;
|
|
93
17
|
},
|
|
94
|
-
fetch:
|
|
95
|
-
interceptors: [
|
|
96
|
-
onError((error) => {
|
|
97
|
-
if (error instanceof PDFVectorError) {
|
|
98
|
-
throw error;
|
|
99
|
-
}
|
|
100
|
-
if (error instanceof ORPCError) {
|
|
101
|
-
throw new PDFVectorError({
|
|
102
|
-
code: error.code,
|
|
103
|
-
message: error.message,
|
|
104
|
-
status: error.status,
|
|
105
|
-
data: error.data,
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
}),
|
|
109
|
-
],
|
|
18
|
+
fetch: (input, init) => fetch(input, token ? init : { ...init, credentials: "include" }),
|
|
110
19
|
});
|
|
111
20
|
return createORPCClient(link);
|
|
112
21
|
}
|
|
113
|
-
export
|
|
114
|
-
return _buildClient(options);
|
|
115
|
-
}
|
|
22
|
+
export * from "@pdfvector/instance-contract";
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
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
|
+
|
|
3
13
|
## 0.0.41
|
|
4
14
|
### Patch Changes
|
|
5
15
|
|
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 `
|
|
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,
|
|
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
|
|
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
|
|
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 (
|
|
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
|
-
|
|
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.
|
|
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
|
-
"@
|
|
37
|
-
"@orpc/contract": "^1.13.14",
|
|
38
|
-
"@pdfvector/instance-contract": "^0.0.40"
|
|
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
|
}
|
package/.tsc/lib/internal.d.ts
DELETED
|
@@ -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;
|
package/.tsc/lib/internal.js
DELETED