@pdfvector/instance-client 0.0.73 → 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/.tsc/lib/errors.d.ts +9 -1
- package/.tsc/lib/errors.d.ts.map +1 -1
- package/.tsc/lib/errors.js +30 -3
- package/CHANGELOG.md +17 -0
- package/README.md +54 -8
- package/package.json +2 -2
package/.tsc/lib/errors.d.ts
CHANGED
|
@@ -58,7 +58,15 @@ export declare class PaymentRequiredError extends PDFVectorError {
|
|
|
58
58
|
readonly totalCredits: number | undefined;
|
|
59
59
|
readonly remainingCredits: number | undefined;
|
|
60
60
|
readonly resetsAt: string | undefined;
|
|
61
|
-
|
|
61
|
+
readonly billingReason: string | undefined;
|
|
62
|
+
readonly invoiceCount: number | undefined;
|
|
63
|
+
readonly amountDue: number | undefined;
|
|
64
|
+
readonly currency: string | undefined;
|
|
65
|
+
readonly billingUrl: string | undefined;
|
|
66
|
+
readonly payUrl: string | undefined;
|
|
67
|
+
constructor(options: SubclassOptions);
|
|
68
|
+
get isBillingHold(): boolean;
|
|
69
|
+
get isCreditsExhausted(): boolean;
|
|
62
70
|
}
|
|
63
71
|
export declare class NotFoundError extends PDFVectorError {
|
|
64
72
|
constructor(options: SubclassOptions);
|
package/.tsc/lib/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../lib/errors.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,kBAAkB,GAC3B,aAAa,GACb,cAAc,GACd,kBAAkB,GAClB,WAAW,GACX,mBAAmB,GACnB,UAAU,GACV,iBAAiB,GACjB,uBAAuB,GACvB,uBAAuB,CAAC;AAE3B,MAAM,MAAM,sBAAsB,GAC/B,gBAAgB,GAChB,SAAS,GACT,YAAY,GACZ,gBAAgB,GAChB,qBAAqB,GACrB,YAAY,GACZ,WAAW,GACX,UAAU,GACV,aAAa,GACb,QAAQ,CAAC;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BAAa,kBAAmB,SAAQ,yBAAyB;CAAG;AAEpE,qBAAa,mBAAoB,SAAQ,yBAAyB;CAAG;AAErE,qBAAa,qBAAsB,SAAQ,yBAAyB;IACnE,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAErC,YAAY,OAAO,EAAE,eAAe,EAInC;CACD;AAED,qBAAa,0BAA2B,SAAQ,aAAa;IAC5D,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IAE5C,YAAY,OAAO,EAAE,eAAe,EAInC;CACD;AAED,qBAAa,gBAAiB,SAAQ,aAAa;IAClD,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAEzC,YAAY,OAAO,EAAE,eAAe,EAMnC;CACD;AAmGD,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,GAAG,SAAS,CAexE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAExE;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAE5E"}
|
package/.tsc/lib/errors.js
CHANGED
|
@@ -89,7 +89,7 @@ function inferOrigin(code, category, data) {
|
|
|
89
89
|
return "system";
|
|
90
90
|
return "user";
|
|
91
91
|
}
|
|
92
|
-
function inferTitle(code, className, message) {
|
|
92
|
+
function inferTitle(code, className, message, billingCode) {
|
|
93
93
|
const lower = message.toLowerCase();
|
|
94
94
|
if (className === "FileTooLargeError")
|
|
95
95
|
return "File too large";
|
|
@@ -131,7 +131,7 @@ function inferTitle(code, className, message) {
|
|
|
131
131
|
case "UNAUTHORIZED":
|
|
132
132
|
return "Authentication failed";
|
|
133
133
|
case "PAYMENT_REQUIRED":
|
|
134
|
-
return "Out of credits";
|
|
134
|
+
return billingCode ? "Payment required" : "Out of credits";
|
|
135
135
|
case "NOT_FOUND":
|
|
136
136
|
return "Resource not found";
|
|
137
137
|
case "TOO_MANY_REQUESTS":
|
|
@@ -152,6 +152,15 @@ function inferSuggestion(code, message, data) {
|
|
|
152
152
|
if (code === "UNAUTHORIZED") {
|
|
153
153
|
return "Check that the API key is present, valid, and belongs to the workspace you intend to use.";
|
|
154
154
|
}
|
|
155
|
+
if (code === "PAYMENT_REQUIRED" &&
|
|
156
|
+
readString(data, "code")?.startsWith("BILLING_")) {
|
|
157
|
+
const payUrl = readString(data, "payUrl");
|
|
158
|
+
if (readString(data, "code") === "BILLING_DISPUTE")
|
|
159
|
+
return "Resolve the payment dispute with your bank or contact team@pdfvector.com.";
|
|
160
|
+
return payUrl
|
|
161
|
+
? `Pay the outstanding balance at ${payUrl}.`
|
|
162
|
+
: "Open billing at https://app.pdfvector.com/workspace/billing and settle the outstanding balance.";
|
|
163
|
+
}
|
|
155
164
|
if (code === "PAYMENT_REQUIRED") {
|
|
156
165
|
const resetsAt = readString(data, "resetsAt");
|
|
157
166
|
return resetsAt
|
|
@@ -250,7 +259,7 @@ export class PDFVectorError extends Error {
|
|
|
250
259
|
this.category = inferCategory(this.code, this.message, this.data);
|
|
251
260
|
this.origin = inferOrigin(this.code, this.category, this.data);
|
|
252
261
|
this.userError = this.origin === "user";
|
|
253
|
-
this.title = inferTitle(this.code, this.name, this.message);
|
|
262
|
+
this.title = inferTitle(this.code, this.name, this.message, readString(this.data, "code")?.startsWith("BILLING_") ?? false);
|
|
254
263
|
this.suggestion = inferSuggestion(this.code, this.message, this.data);
|
|
255
264
|
this.retryableWithHigherModel = hasHigherModelHint(this.message, this.data);
|
|
256
265
|
this.retryable =
|
|
@@ -304,11 +313,29 @@ export class PaymentRequiredError extends PDFVectorError {
|
|
|
304
313
|
totalCredits;
|
|
305
314
|
remainingCredits;
|
|
306
315
|
resetsAt;
|
|
316
|
+
billingReason;
|
|
317
|
+
invoiceCount;
|
|
318
|
+
amountDue;
|
|
319
|
+
currency;
|
|
320
|
+
billingUrl;
|
|
321
|
+
payUrl;
|
|
307
322
|
constructor(options) {
|
|
308
323
|
super({ ...options, code: "PAYMENT_REQUIRED", status: 402 });
|
|
309
324
|
this.totalCredits = readNumber(options.data, "total");
|
|
310
325
|
this.remainingCredits = readNumber(options.data, "remaining");
|
|
311
326
|
this.resetsAt = readString(options.data, "resetsAt");
|
|
327
|
+
this.billingReason = readString(options.data, "reason");
|
|
328
|
+
this.invoiceCount = readNumber(options.data, "invoiceCount");
|
|
329
|
+
this.amountDue = readNumber(options.data, "amountDue");
|
|
330
|
+
this.currency = readString(options.data, "currency");
|
|
331
|
+
this.billingUrl = readString(options.data, "billingUrl");
|
|
332
|
+
this.payUrl = readString(options.data, "payUrl");
|
|
333
|
+
}
|
|
334
|
+
get isBillingHold() {
|
|
335
|
+
return this.reasonCode?.startsWith("BILLING_") ?? false;
|
|
336
|
+
}
|
|
337
|
+
get isCreditsExhausted() {
|
|
338
|
+
return this.reasonCode === "CREDITS_EXHAUSTED" || !this.isBillingHold;
|
|
312
339
|
}
|
|
313
340
|
}
|
|
314
341
|
export class NotFoundError extends PDFVectorError {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @pdfvector/instance-client
|
|
2
2
|
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#515](https://github.com/phuctm97/pdfvector/pull/515) [`6f8ae23`](https://github.com/phuctm97/pdfvector/commit/6f8ae23349c1a386fb5c3fc4985b6a8f95f98616) Thanks [@khanhduyvt0101](https://github.com/khanhduyvt0101)! - Correct the README: this package is ESM only and exports the contract from its main entry; point most users to @pdfvector/client.
|
|
8
|
+
|
|
9
|
+
## 0.1.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#507](https://github.com/phuctm97/pdfvector/pull/507) [`fbe51ca`](https://github.com/phuctm97/pdfvector/commit/fbe51ca228221c31d36565b14c284c1259ddcef1) Thanks [@khanhduyvt0101](https://github.com/khanhduyvt0101)! - Billing holds: workspaces with unpaid invoices, payment disputes or a card/sign-in linked to another account's unpaid balance are blocked with HTTP 402 and a stable code (`BILLING_UNPAID_INVOICE`, `BILLING_DISPUTE`, `BILLING_PAYMENT_METHOD_REQUIRED`, `BILLING_LINKED_UNPAID_BALANCE`, `BILLING_ACCOUNT_HOLD`), cannot resubscribe until paid, and see their invoices with Pay buttons in billing. Out-of-credit errors now carry `CREDITS_EXHAUSTED`. Holds come from webhooks plus an hourly sweep, never from Stripe calls on the request path.
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies []:
|
|
18
|
+
- @pdfvector/instance-contract@0.2.17
|
|
19
|
+
|
|
3
20
|
## 0.0.73
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -14,6 +14,10 @@ pnpm add @pdfvector/instance-client
|
|
|
14
14
|
bun add @pdfvector/instance-client
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
+
> **Most users should install [`@pdfvector/client`](https://www.npmjs.com/package/@pdfvector/client)** (same API, plus a CommonJS build, smaller bundles and no environment access). `@pdfvector/instance-client` is the lower-level ESM-only package `@pdfvector/client` is built from.
|
|
18
|
+
|
|
19
|
+
This package is ESM only (`import`; Node.js 20.19+/22.12+ can also `require()` it) and ships type definitions. It works in Node.js, Bun, Cloudflare Workers, and browsers; Deno needs `--allow-env`.
|
|
20
|
+
|
|
17
21
|
## Quick Start
|
|
18
22
|
|
|
19
23
|
```typescript
|
|
@@ -60,6 +64,7 @@ const extractResult = await client.document.extract({
|
|
|
60
64
|
console.log(extractResult.data);
|
|
61
65
|
```
|
|
62
66
|
|
|
67
|
+
|
|
63
68
|
## Authentication
|
|
64
69
|
|
|
65
70
|
Get your API key from the [PDF Vector dashboard](https://app.pdfvector.com/instances/2?tab=settings).
|
|
@@ -720,7 +725,7 @@ try {
|
|
|
720
725
|
} else if (error instanceof UnauthorizedError) {
|
|
721
726
|
console.error("Invalid API key; check your dashboard");
|
|
722
727
|
} else if (error instanceof PaymentRequiredError) {
|
|
723
|
-
console.error(
|
|
728
|
+
console.error(error.message, error.payUrl ?? error.billingUrl ?? "");
|
|
724
729
|
} else if (error instanceof TooManyRequestsError) {
|
|
725
730
|
console.error(`Rate limit ${error.limit} exceeded; resets at ${error.resetAt}`);
|
|
726
731
|
} else if (error instanceof EmptyDocumentError) {
|
|
@@ -731,6 +736,44 @@ try {
|
|
|
731
736
|
}
|
|
732
737
|
```
|
|
733
738
|
|
|
739
|
+
### Out of credits and billing holds (402)
|
|
740
|
+
|
|
741
|
+
`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.
|
|
742
|
+
|
|
743
|
+
```typescript
|
|
744
|
+
import { PaymentRequiredError } from "@pdfvector/instance-client";
|
|
745
|
+
|
|
746
|
+
try {
|
|
747
|
+
await client.document.parse({ url: "https://example.com/document.pdf" });
|
|
748
|
+
} catch (error) {
|
|
749
|
+
if (error instanceof PaymentRequiredError) {
|
|
750
|
+
if (error.isBillingHold) {
|
|
751
|
+
// Unpaid invoice, missing payment method, dispute, or account hold.
|
|
752
|
+
console.error(error.message);
|
|
753
|
+
console.error(error.payUrl ?? error.billingUrl); // where to pay or fix billing
|
|
754
|
+
console.error(error.amountDue, error.currency); // minor units, e.g. 1900 "usd"
|
|
755
|
+
} else {
|
|
756
|
+
// error.isCreditsExhausted: the monthly credits are used up.
|
|
757
|
+
console.error(`${error.remainingCredits}/${error.totalCredits} credits left, reset on ${error.resetsAt}`);
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
```
|
|
762
|
+
|
|
763
|
+
| Field | Type | Description |
|
|
764
|
+
|-------|------|-------------|
|
|
765
|
+
| `isCreditsExhausted` | `boolean` | The monthly credits are used up |
|
|
766
|
+
| `isBillingHold` | `boolean` | Requests are blocked by a billing problem (`reasonCode` starts with `BILLING_`) |
|
|
767
|
+
| `totalCredits` | `number \| undefined` | Monthly credits of the plan |
|
|
768
|
+
| `remainingCredits` | `number \| undefined` | Credits left in the current period |
|
|
769
|
+
| `resetsAt` | `string \| undefined` | ISO date when the credits reset |
|
|
770
|
+
| `billingReason` | `string \| undefined` | Billing hold reason from the API |
|
|
771
|
+
| `invoiceCount` | `number \| undefined` | Number of unpaid invoices |
|
|
772
|
+
| `amountDue` | `number \| undefined` | Outstanding amount in minor currency units (cents) |
|
|
773
|
+
| `currency` | `string \| undefined` | Currency of `amountDue`, such as `usd` |
|
|
774
|
+
| `billingUrl` | `string \| undefined` | Billing page to update the payment method or see invoices |
|
|
775
|
+
| `payUrl` | `string \| undefined` | Direct link to pay the outstanding invoice (absent for disputes and account holds) |
|
|
776
|
+
|
|
734
777
|
### Error Class Hierarchy
|
|
735
778
|
|
|
736
779
|
```
|
|
@@ -747,7 +790,7 @@ PDFVectorError
|
|
|
747
790
|
│ ├── InvalidSchemaError — reason
|
|
748
791
|
│ └── NoInputProvidedError
|
|
749
792
|
├── UnauthorizedError (401)
|
|
750
|
-
├── PaymentRequiredError (402) — totalCredits, remainingCredits, resetsAt
|
|
793
|
+
├── PaymentRequiredError (402) — totalCredits, remainingCredits, resetsAt, payUrl, billingUrl, …
|
|
751
794
|
├── NotFoundError (404)
|
|
752
795
|
│ ├── AcademicPaperNotFoundError — input, paperErrorCode
|
|
753
796
|
│ └── NoPublicPDFError — input, paperTitle, doi, providerURL
|
|
@@ -790,7 +833,7 @@ Use `error.toAgentError()` or `JSON.stringify(error)` when you need a serializab
|
|
|
790
833
|
|------|--------|-------------|
|
|
791
834
|
| `BAD_REQUEST` | 400 | Input validation failed, including invalid URLs, unsupported formats, file size limits, page limits, invalid base64, and invalid JSON Schema |
|
|
792
835
|
| `UNAUTHORIZED` | 401 | Missing, invalid or deleted API key |
|
|
793
|
-
| `PAYMENT_REQUIRED` | 402 | The workspace has used all of its monthly credits
|
|
836
|
+
| `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
837
|
| `NOT_FOUND` | 404 | Resource not found, including academic paper IDs and papers without public PDFs |
|
|
795
838
|
| `CONFLICT` | 409 | Operation conflicts with the current state |
|
|
796
839
|
| `UNPROCESSABLE_CONTENT` | 422 | Document could not be processed, including empty documents, no readable text, and extraction failures |
|
|
@@ -853,12 +896,15 @@ import type {
|
|
|
853
896
|
} from "@pdfvector/instance-client";
|
|
854
897
|
```
|
|
855
898
|
|
|
856
|
-
|
|
899
|
+
Request and response types are inferred from the API contract, so `client.document.parse(...)` is fully typed without extra imports. With `skipLibCheck: false`, also install `@opentelemetry/api` (an optional type dependency of oRPC), or use `@pdfvector/client`. They reference the standard `fetch` types (`Blob`, `ReadableStream`, `AbortSignal`), so include the `dom` lib or `@types/node`.
|
|
900
|
+
|
|
901
|
+
The contract (oRPC router with zod schemas) and `pdfvectorModelSchema` are exported from the main entry:
|
|
857
902
|
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
903
|
+
```typescript
|
|
904
|
+
import { contract, pdfvectorModelSchema } from "@pdfvector/instance-client";
|
|
905
|
+
|
|
906
|
+
pdfvectorModelSchema.parse("nano"); // "nano" | "mini" | "pro" | "max"
|
|
907
|
+
```
|
|
862
908
|
|
|
863
909
|
## Support
|
|
864
910
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pdfvector/instance-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
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,7 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"main": ".tsc/lib/index.js",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@pdfvector/instance-contract": "^0.2.
|
|
36
|
+
"@pdfvector/instance-contract": "^0.2.17"
|
|
37
37
|
},
|
|
38
38
|
"types": ".tsc/lib/index.d.ts",
|
|
39
39
|
"files": [
|