@pdfvector/client 0.0.54 → 0.1.1
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 +14 -0
- package/README.md +71 -8
- package/contract/package.json +5 -0
- package/dist/contract.cjs +4111 -0
- package/dist/contract.d.cts +2228 -0
- package/dist/contract.d.mts +2228 -0
- package/dist/contract.mjs +4094 -0
- package/dist/index.cjs +1941 -0
- package/dist/index.d.cts +2614 -0
- package/dist/index.d.mts +2614 -0
- package/dist/index.mjs +1908 -0
- package/dist/rolldown-runtime-D3KUYPsf.mjs +12 -0
- package/package.json +37 -7
- package/.tsc/lib/index.d.ts +0 -2
- package/.tsc/lib/index.d.ts.map +0 -1
- package/.tsc/lib/index.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @pdfvector/client
|
|
2
2
|
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#532](https://github.com/phuctm97/pdfvector/pull/532) [`ea63f1f`](https://github.com/phuctm97/pdfvector/commit/ea63f1f2fa69da5aadac35991fb4a143da361d8a) Thanks [@khanhduyvt0101](https://github.com/khanhduyvt0101)! - Upgrade every dependency to its newest release within the current major, including security fixes: better-auth 1.7.19 (GHSA magic-link/OAuth-proxy sign-in as another user, fixed in 1.7.7), the MCP TypeScript SDK 2.4.0 (request size limits, cross-client message delivery), Zod 4.6.7 (memory exhaustion on oversized collections) and nodemailer 10.5. Scalar API reference 1.77.0, Bun 1.4.4 and LibreOffice 26.8.2 for installer builds (the 25.8.5 download had been removed upstream).
|
|
8
|
+
|
|
9
|
+
## 0.1.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#513](https://github.com/phuctm97/pdfvector/pull/513) [`1bc5185`](https://github.com/phuctm97/pdfvector/commit/1bc518565c42c1a59a7d745e14f44bfa9f089892) Thanks [@khanhduyvt0101](https://github.com/khanhduyvt0101)! - Ship `@pdfvector/client` as a self-contained dual package: ESM and CommonJS builds with bundled type definitions (`.d.mts` and `.d.cts`), a proper `exports` map, `sideEffects: false` and `engines.node >=18`. `require("@pdfvector/client")` now works in every Node.js version, the types compile with `skipLibCheck: false` (no more missing `@opentelemetry/api`), and `zod` is the only runtime dependency (installs about 9 MB instead of 29 MB, no `@sentry/core`). The main entry no longer reads environment variables on import, so it runs in Deno without `--allow-env`; it imports in about 10 ms instead of about 400 ms and bundles to about 12 kB gzipped for browsers.
|
|
14
|
+
|
|
15
|
+
Breaking: `contract` and `pdfvectorModelSchema` moved from the main entry to `@pdfvector/client/contract`, because they pull the full zod contract into every import. Change `import { contract, pdfvectorModelSchema } from "@pdfvector/client"` to `import { contract, pdfvectorModelSchema } from "@pdfvector/client/contract"`. Every other export, and every inferred request and response type, is unchanged.
|
|
16
|
+
|
|
3
17
|
## 0.0.54
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -14,6 +14,8 @@ pnpm add @pdfvector/client
|
|
|
14
14
|
bun add @pdfvector/client
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
+
The package ships ESM and CommonJS builds with bundled type definitions and has a single runtime dependency (`zod`, used by the types and the optional contract export). It works in Node.js 18+, Bun, Deno, Cloudflare Workers, and browsers. See [Runtimes and module formats](#runtimes-and-module-formats).
|
|
18
|
+
|
|
17
19
|
## Quick Start
|
|
18
20
|
|
|
19
21
|
```typescript
|
|
@@ -60,6 +62,14 @@ const extractResult = await client.document.extract({
|
|
|
60
62
|
console.log(extractResult.data);
|
|
61
63
|
```
|
|
62
64
|
|
|
65
|
+
CommonJS works the same way:
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
const { createClient } = require("@pdfvector/client");
|
|
69
|
+
|
|
70
|
+
const client = createClient({ apiKey: process.env.PDFVECTOR_API_KEY });
|
|
71
|
+
```
|
|
72
|
+
|
|
63
73
|
## Authentication
|
|
64
74
|
|
|
65
75
|
Get your API key from the [PDF Vector dashboard](https://app.pdfvector.com/instances/2?tab=settings).
|
|
@@ -720,7 +730,7 @@ try {
|
|
|
720
730
|
} else if (error instanceof UnauthorizedError) {
|
|
721
731
|
console.error("Invalid API key; check your dashboard");
|
|
722
732
|
} else if (error instanceof PaymentRequiredError) {
|
|
723
|
-
console.error(
|
|
733
|
+
console.error(error.message, error.payUrl ?? error.billingUrl ?? "");
|
|
724
734
|
} else if (error instanceof TooManyRequestsError) {
|
|
725
735
|
console.error(`Rate limit ${error.limit} exceeded; resets at ${error.resetAt}`);
|
|
726
736
|
} else if (error instanceof EmptyDocumentError) {
|
|
@@ -731,6 +741,44 @@ try {
|
|
|
731
741
|
}
|
|
732
742
|
```
|
|
733
743
|
|
|
744
|
+
### Out of credits and billing holds (402)
|
|
745
|
+
|
|
746
|
+
`PaymentRequiredError` covers two cases. `reasonCode` holds the stable machine code from the API (`CREDITS_EXHAUSTED`, or a `BILLING_*` code such as `BILLING_UNPAID_INVOICE`, `BILLING_PAYMENT_METHOD_REQUIRED`, `BILLING_DISPUTE`, `BILLING_LINKED_UNPAID_BALANCE`, `BILLING_ACCOUNT_HOLD`). Show `message` to the user as-is.
|
|
747
|
+
|
|
748
|
+
```typescript
|
|
749
|
+
import { PaymentRequiredError } from "@pdfvector/client";
|
|
750
|
+
|
|
751
|
+
try {
|
|
752
|
+
await client.document.parse({ url: "https://example.com/document.pdf" });
|
|
753
|
+
} catch (error) {
|
|
754
|
+
if (error instanceof PaymentRequiredError) {
|
|
755
|
+
if (error.isBillingHold) {
|
|
756
|
+
// Unpaid invoice, missing payment method, dispute, or account hold.
|
|
757
|
+
console.error(error.message);
|
|
758
|
+
console.error(error.payUrl ?? error.billingUrl); // where to pay or fix billing
|
|
759
|
+
console.error(error.amountDue, error.currency); // minor units, e.g. 1900 "usd"
|
|
760
|
+
} else {
|
|
761
|
+
// error.isCreditsExhausted: the monthly credits are used up.
|
|
762
|
+
console.error(`${error.remainingCredits}/${error.totalCredits} credits left, reset on ${error.resetsAt}`);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
```
|
|
767
|
+
|
|
768
|
+
| Field | Type | Description |
|
|
769
|
+
|-------|------|-------------|
|
|
770
|
+
| `isCreditsExhausted` | `boolean` | The monthly credits are used up |
|
|
771
|
+
| `isBillingHold` | `boolean` | Requests are blocked by a billing problem (`reasonCode` starts with `BILLING_`) |
|
|
772
|
+
| `totalCredits` | `number \| undefined` | Monthly credits of the plan |
|
|
773
|
+
| `remainingCredits` | `number \| undefined` | Credits left in the current period |
|
|
774
|
+
| `resetsAt` | `string \| undefined` | ISO date when the credits reset |
|
|
775
|
+
| `billingReason` | `string \| undefined` | Billing hold reason from the API |
|
|
776
|
+
| `invoiceCount` | `number \| undefined` | Number of unpaid invoices |
|
|
777
|
+
| `amountDue` | `number \| undefined` | Outstanding amount in minor currency units (cents) |
|
|
778
|
+
| `currency` | `string \| undefined` | Currency of `amountDue`, such as `usd` |
|
|
779
|
+
| `billingUrl` | `string \| undefined` | Billing page to update the payment method or see invoices |
|
|
780
|
+
| `payUrl` | `string \| undefined` | Direct link to pay the outstanding invoice (absent for disputes and account holds) |
|
|
781
|
+
|
|
734
782
|
### Error Class Hierarchy
|
|
735
783
|
|
|
736
784
|
```
|
|
@@ -747,7 +795,7 @@ PDFVectorError
|
|
|
747
795
|
│ ├── InvalidSchemaError — reason
|
|
748
796
|
│ └── NoInputProvidedError
|
|
749
797
|
├── UnauthorizedError (401)
|
|
750
|
-
├── PaymentRequiredError (402) — totalCredits, remainingCredits, resetsAt
|
|
798
|
+
├── PaymentRequiredError (402) — totalCredits, remainingCredits, resetsAt, payUrl, billingUrl, …
|
|
751
799
|
├── NotFoundError (404)
|
|
752
800
|
│ ├── AcademicPaperNotFoundError — input, paperErrorCode
|
|
753
801
|
│ └── NoPublicPDFError — input, paperTitle, doi, providerURL
|
|
@@ -790,7 +838,7 @@ Use `error.toAgentError()` or `JSON.stringify(error)` when you need a serializab
|
|
|
790
838
|
|------|--------|-------------|
|
|
791
839
|
| `BAD_REQUEST` | 400 | Input validation failed, including invalid URLs, unsupported formats, file size limits, page limits, invalid base64, and invalid JSON Schema |
|
|
792
840
|
| `UNAUTHORIZED` | 401 | Missing, invalid or deleted API key |
|
|
793
|
-
| `PAYMENT_REQUIRED` | 402 | The workspace has used all of its monthly credits
|
|
841
|
+
| `PAYMENT_REQUIRED` | 402 | The workspace has used all of its monthly credits, or requests are on a billing hold (for example an unpaid invoice); see [Out of credits and billing holds](#out-of-credits-and-billing-holds-402) |
|
|
794
842
|
| `NOT_FOUND` | 404 | Resource not found, including academic paper IDs and papers without public PDFs |
|
|
795
843
|
| `CONFLICT` | 409 | Operation conflicts with the current state |
|
|
796
844
|
| `UNPROCESSABLE_CONTENT` | 422 | Document could not be processed, including empty documents, no readable text, and extraction failures |
|
|
@@ -853,12 +901,27 @@ import type {
|
|
|
853
901
|
} from "@pdfvector/client";
|
|
854
902
|
```
|
|
855
903
|
|
|
856
|
-
|
|
904
|
+
Request and response types are inferred from the API contract, so `client.document.parse(...)` is fully typed without extra imports. The types work with `strict` and `skipLibCheck: false` under every `moduleResolution` mode (`bundler`, `node16`, `nodenext`, and `node10` with `esModuleInterop`). They reference the standard `fetch` types (`Blob`, `ReadableStream`, `AbortSignal`), so include the `dom` lib or `@types/node`.
|
|
905
|
+
|
|
906
|
+
The contract itself (oRPC router with zod schemas) and `pdfvectorModelSchema` live on a separate entry point, so the main entry stays small:
|
|
907
|
+
|
|
908
|
+
```typescript
|
|
909
|
+
import { contract, pdfvectorModelSchema } from "@pdfvector/client/contract";
|
|
910
|
+
|
|
911
|
+
pdfvectorModelSchema.parse("nano"); // "nano" | "mini" | "pro" | "max"
|
|
912
|
+
```
|
|
913
|
+
|
|
914
|
+
## Runtimes and module formats
|
|
915
|
+
|
|
916
|
+
The SDK only needs the standard `fetch` API. It has no Node.js built-ins, reads no environment variables, and has no import-time side effects (`"sideEffects": false`), so bundlers can tree-shake it.
|
|
857
917
|
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
918
|
+
| Runtime | Notes |
|
|
919
|
+
|---------|-------|
|
|
920
|
+
| Node.js 18+ | ESM (`import`) and CommonJS (`require`). Node.js 20+ is recommended; `file` uploads need the global `File` class (Node.js 20+). |
|
|
921
|
+
| Bun | `import` or `require` |
|
|
922
|
+
| Deno | `import { createClient } from "npm:@pdfvector/client";` (no `--allow-env` needed) |
|
|
923
|
+
| Cloudflare Workers | Works with Wrangler's bundler; pass the API key from a secret: `createClient({ apiKey: env.PDFVECTOR_API_KEY })` |
|
|
924
|
+
| Browsers | Works with any bundler (about 12 kB gzipped). Never put an API key in browser code. Without `apiKey`, requests are sent with `credentials: "include"`, so the browser's PDF Vector session cookie for that domain is used. |
|
|
862
925
|
|
|
863
926
|
## Support
|
|
864
927
|
|