@podosoft/podokit-api-client 0.4.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 +34 -0
- package/dist/index.d.ts +1680 -0
- package/dist/index.js +87 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @podosoft/podokit-api-client
|
|
2
|
+
|
|
3
|
+
Typed API client for PodoKit backends. Every frontend talks to the backend
|
|
4
|
+
through this single entry point — never with a raw `fetch`.
|
|
5
|
+
|
|
6
|
+
- `client.auth` — the [better-auth](https://better-auth.com) client (email/password,
|
|
7
|
+
sessions, and the admin plugin: `listUsers`, `banUser`, `setRole`, `listUserSessions`, …).
|
|
8
|
+
- `client.get/post/put/patch/del` — the app's REST endpoints, parsing the standard
|
|
9
|
+
error envelope and throwing `ApiError` on failure.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { createApiClient } from "@podosoft/podokit-api-client";
|
|
13
|
+
|
|
14
|
+
// Browser (same-origin, through the SvelteKit proxy)
|
|
15
|
+
const api = createApiClient();
|
|
16
|
+
const health = await api.get("/health");
|
|
17
|
+
await api.auth.signIn.email({ email, password });
|
|
18
|
+
|
|
19
|
+
// Server-side (SSR): point at the internal backend and forward cookies
|
|
20
|
+
const api = createApiClient({ baseUrl: process.env.BACKEND_INTERNAL_URL, fetch });
|
|
21
|
+
const session = await api.auth.getSession();
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Options
|
|
25
|
+
|
|
26
|
+
| Option | Default | Purpose |
|
|
27
|
+
| --- | --- | --- |
|
|
28
|
+
| `baseUrl` | `""` | API origin. Empty = same-origin (browser via proxy); absolute URL for SSR. |
|
|
29
|
+
| `apiBasePath` | `/api` | Prefix for REST endpoints. |
|
|
30
|
+
| `authBasePath` | `/api/auth` | Prefix for the better-auth handler. |
|
|
31
|
+
| `fetch` | global `fetch` | Inject on the server to forward cookies. |
|
|
32
|
+
| `credentials` | `include` | Send cookies with requests. |
|
|
33
|
+
|
|
34
|
+
Errors are thrown as `ApiError` (`code`, `message`, `statusCode`, `details`).
|