@apowerb/apowerb-sdk 0.0.1 → 0.1.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 +20 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# @apowerb/apowerb-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
JavaScript client for the apowerb backend: agents, tools, RAG, BI, webhooks, billing, skills. **143 functions**, no dependencies, no React and no Next code — usable in a browser as well as in Node.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Why this package
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
This layer used to live in `src/lib/api.js` inside the Next application, with `const BASE = ""` hard-coded: every request went out relative to `/api/...`, which assumes being served by the app that proxies those routes. The most reusable part of the repository was therefore trapped inside the front end.
|
|
8
8
|
|
|
9
9
|
## Usage
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
With no configuration the behaviour is the original one — relative requests, token read from `localStorage` — so the Next application does not change by a single byte:
|
|
12
12
|
|
|
13
13
|
```js
|
|
14
14
|
import { listAgents } from "@apowerb/apowerb-sdk";
|
|
@@ -16,38 +16,38 @@ import { listAgents } from "@apowerb/apowerb-sdk";
|
|
|
16
16
|
const agents = await listAgents(); // GET /api/agents
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
Anywhere else, point it at the backend of your choice:
|
|
20
20
|
|
|
21
21
|
```js
|
|
22
22
|
import { configureClient, listAgents } from "@apowerb/apowerb-sdk";
|
|
23
23
|
|
|
24
24
|
configureClient({
|
|
25
|
-
baseUrl: "https://
|
|
26
|
-
storage: { getToken: () => process.env.
|
|
25
|
+
baseUrl: "https://your-apowerb-host",
|
|
26
|
+
storage: { getToken: () => process.env.APOWERB_TOKEN },
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
const agents = await listAgents(); // GET https://
|
|
29
|
+
const agents = await listAgents(); // GET https://your-apowerb-host/api/agents
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
## Configuration
|
|
33
33
|
|
|
34
|
-
`configureClient(options)` —
|
|
34
|
+
`configureClient(options)` — omitted keys keep their current value.
|
|
35
35
|
|
|
36
|
-
| Option |
|
|
36
|
+
| Option | Default | Role |
|
|
37
37
|
|---|---|---|
|
|
38
|
-
| `baseUrl` | `""` |
|
|
39
|
-
| `storage` | `authStorage` (localStorage) |
|
|
40
|
-
| `onUnauthorized` |
|
|
38
|
+
| `baseUrl` | `""` | Backend root. Empty means relative requests. A trailing slash is tolerated. |
|
|
39
|
+
| `storage` | `authStorage` (localStorage) | Must expose `getToken()`, ideally `setToken()` and `clear()`. |
|
|
40
|
+
| `onUnauthorized` | `auth:unauthorized` event on `window` | Called on a final 401. With no DOM, it does nothing. |
|
|
41
41
|
|
|
42
|
-
`getClientConfig()`
|
|
42
|
+
`getClientConfig()` returns the current configuration; `resetClientConfig()` restores the defaults, which is useful between tests.
|
|
43
43
|
|
|
44
|
-
##
|
|
44
|
+
## What the client handles for you
|
|
45
45
|
|
|
46
|
-
-
|
|
47
|
-
-
|
|
48
|
-
-
|
|
49
|
-
-
|
|
46
|
+
- injecting the `Authorization` header;
|
|
47
|
+
- refreshing the token on a 401, with a lock so concurrent refreshes cannot pile up, then replaying the request;
|
|
48
|
+
- non-JSON responses from reverse proxies (502/503/504), turned into clean `Error` objects carrying `status`;
|
|
49
|
+
- file uploads, including chunked ones.
|
|
50
50
|
|
|
51
51
|
## Format
|
|
52
52
|
|
|
53
|
-
ESM
|
|
53
|
+
Pure ESM, published as-is — no build step. The files contain neither JSX nor any proprietary syntax, so Node and any bundler consume them directly.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apowerb/apowerb-sdk",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "JavaScript SDK for the apowerb backend: agents, tools, RAG, BI, webhooks and billing. Dependency-free, runs in the browser and in Node.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|