@xberg-io/sdk 0.0.1 → 0.5.0
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/README.md +163 -9
- package/dist/index.d.ts +31515 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1649 -0
- package/dist/index.js.map +1 -0
- package/package.json +42 -5
package/README.md
CHANGED
|
@@ -1,14 +1,168 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/gh/xberg-io/assets@v1/banner/readme-banner-dark.svg">
|
|
4
|
+
<img alt="Xberg" width="420" src="https://cdn.jsdelivr.net/gh/xberg-io/assets@v1/banner/readme-banner-light.svg">
|
|
5
|
+
</picture>
|
|
6
|
+
</p>
|
|
7
|
+
|
|
1
8
|
# @xberg-io/sdk
|
|
2
9
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
10
|
+
<div align="center">
|
|
11
|
+
|
|
12
|
+
<img width="3384" height="573" alt="Xberg Enterprise" src="https://github.com/user-attachments/assets/1b6c6ad7-3b6d-4171-b1c9-f2026cc9deb8">
|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
<div align="center" style="display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 20px 0;">
|
|
17
|
+
|
|
18
|
+
<a href="https://pypi.org/project/xberg-io-sdk/"><img src="https://img.shields.io/pypi/v/xberg-io-sdk?label=PyPI&color=007ec6" alt="PyPI"></a>
|
|
19
|
+
<a href="https://www.npmjs.com/package/@xberg-io/sdk"><img src="https://img.shields.io/npm/v/%40xberg-io%2Fsdk?label=npm&color=007ec6" alt="npm"></a>
|
|
20
|
+
<a href="https://pkg.go.dev/github.com/xberg-io/sdks/packages/go"><img src="https://img.shields.io/badge/Go-pkg.go.dev-007ec6?logo=go&logoColor=white" alt="Go Reference"></a>
|
|
21
|
+
<a href="https://github.com/xberg-io/sdks/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-MIT-007ec6" alt="License"></a>
|
|
22
|
+
<a href="https://docs.sdks.xberg.io"><img src="https://img.shields.io/badge/docs-docs.sdks.xberg.io-007ec6" alt="Documentation"></a>
|
|
23
|
+
<a href="https://github.com/xberg-io/sdks/actions/workflows/validate.yml"><img src="https://github.com/xberg-io/sdks/actions/workflows/validate.yml/badge.svg" alt="CI"></a>
|
|
24
|
+
|
|
25
|
+
</div>
|
|
26
|
+
|
|
27
|
+
<div align="center" style="margin-top: 20px;">
|
|
28
|
+
|
|
29
|
+
<a href="https://discord.gg/xt9WY3GnKR"><img height="22" src="https://img.shields.io/badge/Discord-Join%20our%20community-7289da?logo=discord&logoColor=white" alt="Discord"></a>
|
|
30
|
+
|
|
31
|
+
</div>
|
|
32
|
+
|
|
33
|
+
Official TypeScript / Node.js client for the [Xberg Enterprise](https://xberg.io)
|
|
34
|
+
and Xberg Pro document-processing APIs. One `XbergClient` speaks to either
|
|
35
|
+
product: the shared surface (extraction, jobs, audit, curated presets, RAG) is
|
|
36
|
+
written once, and tier-specific methods are capability-gated.
|
|
37
|
+
|
|
38
|
+
- ESM-only, modern (Node 22+, Bun, Deno, Cloudflare Workers)
|
|
39
|
+
- Dual-target: two generated schema sets (Enterprise + Pro), never merged
|
|
40
|
+
- Generated types via `openapi-typescript`, runtime via `openapi-fetch`
|
|
41
|
+
- Tree-shakable, no bundled dependencies
|
|
42
|
+
|
|
43
|
+
## Install
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
pnpm add @xberg-io/sdk
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Targets
|
|
50
|
+
|
|
51
|
+
`XbergClient` defaults to Xberg Enterprise (`baseUrl` defaults to
|
|
52
|
+
`https://api.xberg.io`). To talk to a self-hosted Xberg Pro instance, pass
|
|
53
|
+
`target: "pro"` with an explicit `baseUrl`:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { XbergClient } from "@xberg-io/sdk";
|
|
57
|
+
|
|
58
|
+
const pro = new XbergClient({ apiKey: process.env.XBERG_API_KEY!, target: "pro", baseUrl: "https://pro.example.com" });
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
When `target` is omitted the tier is discovered lazily from `GET /healthz`.
|
|
62
|
+
Calling a method not available on the connected tier (e.g. `usage()` on Pro, or
|
|
63
|
+
`login()` on Enterprise) throws a clear "not available on this tier" error.
|
|
64
|
+
|
|
65
|
+
## Quickstart — single file
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import { XbergClient } from "@xberg-io/sdk";
|
|
69
|
+
import { readFile } from "node:fs/promises";
|
|
70
|
+
|
|
71
|
+
const client = new XbergClient({ apiKey: process.env.XBERG_API_KEY! });
|
|
72
|
+
|
|
73
|
+
const data = await readFile("invoice.pdf");
|
|
74
|
+
const result = await client.extractAndWait({
|
|
75
|
+
file: { name: "invoice.pdf", data, mimeType: "application/pdf" },
|
|
76
|
+
});
|
|
77
|
+
console.log(result.result?.content);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Quickstart — batch + parallel wait
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { XbergClient } from "@xberg-io/sdk";
|
|
84
|
+
import { readFile } from "node:fs/promises";
|
|
85
|
+
|
|
86
|
+
const client = new XbergClient({ apiKey: process.env.XBERG_API_KEY! });
|
|
87
|
+
|
|
88
|
+
const files = await Promise.all(
|
|
89
|
+
["a.pdf", "b.pdf", "c.pdf"].map(async (name) => ({
|
|
90
|
+
name,
|
|
91
|
+
data: await readFile(name),
|
|
92
|
+
})),
|
|
93
|
+
);
|
|
94
|
+
const jobs = await client.extractBatch({ files });
|
|
95
|
+
const results = await client.waitForJobs(jobs.map((j) => j.id));
|
|
96
|
+
for (const r of results) console.log(r.id, r.status);
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## API
|
|
100
|
+
|
|
101
|
+
Shared surface (both tiers):
|
|
102
|
+
|
|
103
|
+
| Method | Returns |
|
|
104
|
+
|---|---|
|
|
105
|
+
| `extract({ file, options? })` | `Promise<Job>` |
|
|
106
|
+
| `extractBatch({ files, options? })` | `Promise<Job[]>` |
|
|
107
|
+
| `getJob(jobId)` | `Promise<Job>` |
|
|
108
|
+
| `getJobResult(jobId)` | `Promise<JobResult>` |
|
|
109
|
+
| `waitForJob(jobId, opts?)` | `Promise<Job>` |
|
|
110
|
+
| `waitForJobs(jobIds, opts?)` | `Promise<Job[]>` |
|
|
111
|
+
| `extractAndWait({ file, options?, ...waitOpts })` | `Promise<Job>` |
|
|
112
|
+
| `listJobs({ limit?, offset? })` | `Promise<ListJobsResponse>` |
|
|
113
|
+
| `cancelJob(jobId)` | `Promise<void>` |
|
|
114
|
+
| `audit({ action?, limit?, offset? })` | `Promise<ListAuditEntriesResponse>` |
|
|
115
|
+
| `presets()`, `getPreset(id)`, `getPresetSample(id, name)` | Curated preset registry |
|
|
116
|
+
| `listSavedPresets({ limit?, offset? })`, `createSavedPreset(body)`, `getSavedPreset(id)`, `updateSavedPreset(id, body)`, `deleteSavedPreset(id)` | Project-owned saved presets |
|
|
117
|
+
| `listAutoTuneJobs({ limit?, offset? })`, `submitAutoTune({ request, files })`, `getAutoTuneCapabilities()`, `getAutoTuneStatus(id)`, `getAutoTuneResult(id)`, `promoteAutoTuneProfile(id, body)`, `deleteAutoTuneJob(id)` | Auto-tune |
|
|
118
|
+
| `listTuningProfiles({ limit?, offset? })`, `getTuningProfile(id)`, `deleteTuningProfile(id)` | Tuning profiles |
|
|
119
|
+
| `listRagCollections()`, `createRagCollection(body)`, `deleteRagCollection(name)`, `ragRetrieve(name, body)`, `deleteRagDocuments(name, body)`, … | RAG surface |
|
|
120
|
+
|
|
121
|
+
`Job` is the job envelope (`GET /v1/jobs/{id}`); `JobResult` is the stored
|
|
122
|
+
extraction result (`GET /v1/jobs/{id}/result`). They are different schemas — the
|
|
123
|
+
polling helpers return the former, `getJobResult` the latter.
|
|
124
|
+
|
|
125
|
+
Saved presets are shared but the two products spell the route differently —
|
|
126
|
+
Enterprise serves `/v1/saved_presets`, Pro `/v1/saved-presets`, with identical
|
|
127
|
+
schemas. The client resolves the tier and picks the spelling for you.
|
|
128
|
+
|
|
129
|
+
Xberg Pro only: `login`, `authConfig`, `getRagConfig` / `setRagConfig`, and the
|
|
130
|
+
control plane — `listProjects` / `createProject`, `listApiKeys` / `createApiKey` /
|
|
131
|
+
`revokeApiKey`, `listIntegrations` / `createIntegration` / `getIntegration` /
|
|
132
|
+
`deleteIntegration`, `connectIntegration` / `disconnectIntegration`,
|
|
133
|
+
`listIntegrationDocuments` / `fetchIntegrationDocument`.
|
|
134
|
+
|
|
135
|
+
Xberg Enterprise only: `getDocument`, `versions`, `diff` / `getDiffJob`,
|
|
136
|
+
`presignUpload` / `confirmUpload`, `usage`, `listExtractionEvents`, `getJobPage`,
|
|
137
|
+
`submitEnrich` / `getEnrichStatus`, `streamCrawlEvents` (an `AsyncIterable` over
|
|
138
|
+
a Server-Sent Events stream).
|
|
139
|
+
|
|
140
|
+
`getPresetSample`, `fetchIntegrationDocument`, and `getJobPage` return raw
|
|
141
|
+
`Uint8Array` bytes rather than JSON; `getJobPage` serves `image/png`.
|
|
142
|
+
|
|
143
|
+
### Not covered
|
|
144
|
+
|
|
145
|
+
A few documented endpoints are deliberately left out of the client:
|
|
146
|
+
|
|
147
|
+
- `GET /readyz` — an infrastructure readiness probe for orchestrators, not
|
|
148
|
+
application surface. `GET /healthz` *is* used: it backs the tier probe.
|
|
149
|
+
- `GET /v1/oauth/callback` and `DELETE /auth/account` (Pro) — browser
|
|
150
|
+
redirect/cookie flows, not API-key surface. `POST /auth/login`, which does
|
|
151
|
+
work with a verified ID token, is exposed.
|
|
152
|
+
|
|
153
|
+
Errors throw subclasses of `XbergError` (`AuthError`, `RateLimitError`,
|
|
154
|
+
`ValidationError`, `NotFoundError`, `ServerError`, `TimeoutError`). Each
|
|
155
|
+
carries `status: number` and `body: unknown`. `RateLimitError.retryAfter`
|
|
156
|
+
is parsed from the `Retry-After` response header.
|
|
157
|
+
|
|
158
|
+
The low-level `createClient(...)` factory (a thin `openapi-fetch` wrapper)
|
|
159
|
+
is still exported for direct OpenAPI access.
|
|
160
|
+
|
|
161
|
+
## Docs
|
|
6
162
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
[xberg-io/sdks](https://github.com/xberg-io/sdks/tree/main/packages/typescript).
|
|
163
|
+
- SDK docs: <https://docs.sdks.xberg.io>
|
|
164
|
+
- Product overview: <https://xberg.io>
|
|
10
165
|
|
|
11
|
-
|
|
12
|
-
- Issues: https://github.com/xberg-io/sdks/issues
|
|
166
|
+
## License
|
|
13
167
|
|
|
14
|
-
MIT
|
|
168
|
+
MIT — © Kreuzberg, Inc.
|