@apowerb/apowerb-sdk 0.0.0 → 0.0.2
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/LICENSE +21 -21
- package/README.md +53 -53
- package/package.json +44 -44
- package/src/api.js +830 -830
- package/src/authStorage.js +770 -770
- package/src/config.js +86 -86
- package/src/index.js +26 -26
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 apowerb
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 apowerb
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
# @apowerb/apowerb-sdk
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
## Usage
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
```js
|
|
14
|
-
import { listAgents } from "@apowerb/apowerb-sdk";
|
|
15
|
-
|
|
16
|
-
const agents = await listAgents(); // GET /api/agents
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
```js
|
|
22
|
-
import { configureClient, listAgents } from "@apowerb/apowerb-sdk";
|
|
23
|
-
|
|
24
|
-
configureClient({
|
|
25
|
-
baseUrl: "https://
|
|
26
|
-
storage: { getToken: () => process.env.
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const agents = await listAgents(); // GET https://
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## Configuration
|
|
33
|
-
|
|
34
|
-
`configureClient(options)` —
|
|
35
|
-
|
|
36
|
-
| Option |
|
|
37
|
-
|---|---|---|
|
|
38
|
-
| `baseUrl` | `""` |
|
|
39
|
-
| `storage` | `authStorage` (localStorage) |
|
|
40
|
-
| `onUnauthorized` |
|
|
41
|
-
|
|
42
|
-
`getClientConfig()`
|
|
43
|
-
|
|
44
|
-
##
|
|
45
|
-
|
|
46
|
-
-
|
|
47
|
-
-
|
|
48
|
-
-
|
|
49
|
-
-
|
|
50
|
-
|
|
51
|
-
## Format
|
|
52
|
-
|
|
53
|
-
ESM
|
|
1
|
+
# @apowerb/apowerb-sdk
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
## Why this package
|
|
6
|
+
|
|
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
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
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
|
+
|
|
13
|
+
```js
|
|
14
|
+
import { listAgents } from "@apowerb/apowerb-sdk";
|
|
15
|
+
|
|
16
|
+
const agents = await listAgents(); // GET /api/agents
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Anywhere else, point it at the backend of your choice:
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
import { configureClient, listAgents } from "@apowerb/apowerb-sdk";
|
|
23
|
+
|
|
24
|
+
configureClient({
|
|
25
|
+
baseUrl: "https://your-apowerb-host",
|
|
26
|
+
storage: { getToken: () => process.env.APOWERB_TOKEN },
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const agents = await listAgents(); // GET https://your-apowerb-host/api/agents
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Configuration
|
|
33
|
+
|
|
34
|
+
`configureClient(options)` — omitted keys keep their current value.
|
|
35
|
+
|
|
36
|
+
| Option | Default | Role |
|
|
37
|
+
|---|---|---|
|
|
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
|
+
|
|
42
|
+
`getClientConfig()` returns the current configuration; `resetClientConfig()` restores the defaults, which is useful between tests.
|
|
43
|
+
|
|
44
|
+
## What the client handles for you
|
|
45
|
+
|
|
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
|
+
|
|
51
|
+
## Format
|
|
52
|
+
|
|
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,44 +1,44 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@apowerb/apowerb-sdk",
|
|
3
|
-
"version": "0.0.
|
|
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
|
-
"license": "MIT",
|
|
6
|
-
"repository": {
|
|
7
|
-
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/apowerb/apowerb-ui.git",
|
|
9
|
-
"directory": "packages/apowerb-sdk"
|
|
10
|
-
},
|
|
11
|
-
"homepage": "https://github.com/apowerb/apowerb-ui/tree/main/packages/apowerb-sdk#readme",
|
|
12
|
-
"bugs": {
|
|
13
|
-
"url": "https://github.com/apowerb/apowerb-ui/issues"
|
|
14
|
-
},
|
|
15
|
-
"type": "module",
|
|
16
|
-
"main": "./src/index.js",
|
|
17
|
-
"module": "./src/index.js",
|
|
18
|
-
"exports": {
|
|
19
|
-
".": "./src/index.js",
|
|
20
|
-
"./config": "./src/config.js",
|
|
21
|
-
"./authStorage": "./src/authStorage.js"
|
|
22
|
-
},
|
|
23
|
-
"files": [
|
|
24
|
-
"src",
|
|
25
|
-
"!src/__tests__",
|
|
26
|
-
"README.md",
|
|
27
|
-
"LICENSE"
|
|
28
|
-
],
|
|
29
|
-
"keywords": [
|
|
30
|
-
"apowerb",
|
|
31
|
-
"thaink2",
|
|
32
|
-
"sdk",
|
|
33
|
-
"api",
|
|
34
|
-
"agents",
|
|
35
|
-
"rag"
|
|
36
|
-
],
|
|
37
|
-
"sideEffects": false,
|
|
38
|
-
"engines": {
|
|
39
|
-
"node": ">=18"
|
|
40
|
-
},
|
|
41
|
-
"publishConfig": {
|
|
42
|
-
"access": "public"
|
|
43
|
-
}
|
|
44
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@apowerb/apowerb-sdk",
|
|
3
|
+
"version": "0.0.2",
|
|
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
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/apowerb/apowerb-ui.git",
|
|
9
|
+
"directory": "packages/apowerb-sdk"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/apowerb/apowerb-ui/tree/main/packages/apowerb-sdk#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/apowerb/apowerb-ui/issues"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "./src/index.js",
|
|
17
|
+
"module": "./src/index.js",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": "./src/index.js",
|
|
20
|
+
"./config": "./src/config.js",
|
|
21
|
+
"./authStorage": "./src/authStorage.js"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"src",
|
|
25
|
+
"!src/__tests__",
|
|
26
|
+
"README.md",
|
|
27
|
+
"LICENSE"
|
|
28
|
+
],
|
|
29
|
+
"keywords": [
|
|
30
|
+
"apowerb",
|
|
31
|
+
"thaink2",
|
|
32
|
+
"sdk",
|
|
33
|
+
"api",
|
|
34
|
+
"agents",
|
|
35
|
+
"rag"
|
|
36
|
+
],
|
|
37
|
+
"sideEffects": false,
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=18"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
}
|
|
44
|
+
}
|