@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 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
- Client JavaScript du backend th2agent : agents, outils, RAG, BI, webhooks, facturation, skills. **139 fonctions**, aucune dépendance, aucun code React ni Next — utilisable dans un navigateur comme dans Node.
4
-
5
- ## Pourquoi ce paquet
6
-
7
- Cette couche vivait dans `src/lib/api.js` de l'application Next, avec `const BASE = ""` codé en dur : toutes les requêtes partaient en relatif vers `/api/...`, ce qui suppose d'être servi par l'app qui proxie ces routes. La partie la plus réutilisable du dépôt était donc prisonnière du front.
8
-
9
- ## Usage
10
-
11
- Sans configuration, le comportement est celui d'originerequêtes relatives, jeton lu dans `localStorage` — donc l'application Next ne change pas d'un octet :
12
-
13
- ```js
14
- import { listAgents } from "@apowerb/apowerb-sdk";
15
-
16
- const agents = await listAgents(); // GET /api/agents
17
- ```
18
-
19
- Ailleurs, on pointe le backend de son choix :
20
-
21
- ```js
22
- import { configureClient, listAgents } from "@apowerb/apowerb-sdk";
23
-
24
- configureClient({
25
- baseUrl: "https://agent.thaink2.com",
26
- storage: { getToken: () => process.env.TH2AGENT_TOKEN },
27
- });
28
-
29
- const agents = await listAgents(); // GET https://agent.thaink2.com/api/agents
30
- ```
31
-
32
- ## Configuration
33
-
34
- `configureClient(options)` — les clés omises gardent leur valeur courante.
35
-
36
- | Option | Défaut | Rôle |
37
- |---|---|---|
38
- | `baseUrl` | `""` | Racine du backend. Vide = requêtes relatives. Un slash final est toléré. |
39
- | `storage` | `authStorage` (localStorage) | Doit exposer `getToken()`, idéalement `setToken()` et `clear()`. |
40
- | `onUnauthorized` | évènement `auth:unauthorized` sur `window` | Appelé sur un 401 définitif. Sans DOM, ne fait rien. |
41
-
42
- `getClientConfig()` retourne la configuration courante, `resetClientConfig()` rétablit les défauts (utile entre deux tests).
43
-
44
- ## Ce que le client gère pour vous
45
-
46
- - injection de l'en-tête `Authorization` ;
47
- - rafraîchissement du jeton sur 401, avec verrou pour éviter les rafraîchissements concurrents, puis rejeu de la requête ;
48
- - réponses non-JSON des reverse proxies (502/503/504) converties en `Error` propres portant `status` ;
49
- - upload de fichiers, y compris en morceaux.
50
-
51
- ## Format
52
-
53
- ESM pur, publié tel quel pas d'étape de build. Les fichiers ne contiennent ni JSX ni syntaxe propriétaire, donc Node comme n'importe quel bundler les consomment directement.
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-isno 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.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
+ }