@insignia-education/api-sdk-js 0.9.24 → 0.9.25

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/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ 24
package/AGENTS.md ADDED
@@ -0,0 +1,54 @@
1
+ # Insignia Education — API SDK (JavaScript)
2
+
3
+ ## Requirements
4
+ - Node 24 LTS (`nvm use 24`)
5
+
6
+ ## Quick start
7
+ ```bash
8
+ nvm use 24
9
+ npm install
10
+ npm test # runs Jest test suite
11
+ npm run lint # ESLint
12
+ ```
13
+
14
+ ## What this is
15
+ A zero-dependency JavaScript SDK that wraps the Insignia Education API (`/api/v1`).
16
+ Consumed by `insignia-education/front` via `@insignia-education/api-sdk-js`.
17
+
18
+ ## Structure
19
+ ```
20
+ src/
21
+ ├── index.js ← main export
22
+ ├── api/v1/
23
+ │ ├── index.js ← InsigniaApiV1 class (root client)
24
+ │ ├── Auth.js ← /auth endpoints
25
+ │ ├── Courses.js ← /courses endpoints
26
+ │ ├── Users.js ← /users endpoints
27
+ │ └── ... ← one file per API resource
28
+ ```
29
+
30
+ ## Usage pattern
31
+ ```js
32
+ import InsigniaApiV1 from '@insignia-education/api-sdk-js/api/v1';
33
+ const api = new InsigniaApiV1('http://localhost:8000');
34
+
35
+ api.auth.login({ email, password });
36
+ api.courses.get(null, { page: 1 });
37
+ api.users.cashReceivers();
38
+ ```
39
+
40
+ ## Conventions
41
+ - One class per API resource
42
+ - Methods match HTTP verbs: `get`, `post`, `put`, `patch`, `delete`
43
+ - No external runtime dependencies — only Node built-ins
44
+ - ESM modules (`"type": "module"`)
45
+
46
+ ## Adding a new resource
47
+ 1. Create `src/api/v1/ResourceName.js` with a class that receives the client
48
+ 2. Register it in `src/api/v1/index.js`
49
+ 3. Write tests in `src/api/v1/__tests__/ResourceName.test.js`
50
+
51
+ ## Never do
52
+ - Don't add runtime dependencies
53
+ - Don't change the constructor signature of `InsigniaApiV1`
54
+ - Don't hardcode API base URLs — always receive from constructor
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@insignia-education/api-sdk-js",
3
- "version": "0.9.24",
3
+ "version": "0.9.25",
4
4
  "description": "JavaScript SDK for the Insignia Education API",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -20,7 +20,7 @@
20
20
  "author": "Insignia Education",
21
21
  "license": "MIT",
22
22
  "engines": {
23
- "node": ">=25.5.0"
23
+ "node": ">=24"
24
24
  },
25
25
  "bugs": {
26
26
  "url": "https://github.com/insignia-education/api-sdk-js/issues"
package/src/Client.js CHANGED
@@ -76,6 +76,12 @@ export default class InsigniaClient {
76
76
  if (body !== null) options.body = JSON.stringify(body);
77
77
  const response = await fetch(`${this.#baseUrl}${path}`, options);
78
78
  this.#storeCookies(response);
79
+ if (!response.ok) {
80
+ const err = new Error(`HTTP ${response.status}`);
81
+ err.status = response.status;
82
+ try { err.data = await this.#parseResponse(response); } catch (_) {}
83
+ throw err;
84
+ }
79
85
  const data = await this.#parseResponse(response);
80
86
  return data?.success ? data.response : data;
81
87
  }