@tammsyr/admin-api-client 1.0.15 → 1.0.17
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 +341 -341
- package/dist/ActivityLogs.d.ts.map +1 -1
- package/dist/AgentBranches.d.ts +1 -1
- package/dist/AgentBranches.d.ts.map +1 -1
- package/dist/Agents.d.ts +31 -1
- package/dist/Agents.d.ts.map +1 -1
- package/dist/Agents.js +48 -0
- package/dist/Agents.js.map +1 -1
- package/dist/FeeConfigs.d.ts +57 -0
- package/dist/FeeConfigs.d.ts.map +1 -0
- package/dist/FeeConfigs.js +107 -0
- package/dist/FeeConfigs.js.map +1 -0
- package/dist/Kyc.d.ts.map +1 -1
- package/dist/Notifications.d.ts.map +1 -1
- package/dist/Seed.d.ts +10 -0
- package/dist/Seed.d.ts.map +1 -1
- package/dist/Seed.js +15 -0
- package/dist/Seed.js.map +1 -1
- package/dist/SystemConfigs.d.ts +37 -0
- package/dist/SystemConfigs.d.ts.map +1 -0
- package/dist/SystemConfigs.js +72 -0
- package/dist/SystemConfigs.js.map +1 -0
- package/dist/Transactions.d.ts.map +1 -1
- package/dist/Users.d.ts.map +1 -1
- package/dist/Users.js.map +1 -1
- package/dist/data-contracts.d.ts +229 -9
- package/dist/data-contracts.d.ts.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,341 +1,341 @@
|
|
|
1
|
-
# @tammsyr/admin-api-client
|
|
2
|
-
|
|
3
|
-
TypeScript client for TAMM Admin Service API. Auto-generated from OpenAPI specification using [swagger-typescript-api](https://github.com/acacode/swagger-typescript-api).
|
|
4
|
-
|
|
5
|
-
## Table of Contents
|
|
6
|
-
|
|
7
|
-
- [Installation](#installation)
|
|
8
|
-
- [Requirements](#requirements)
|
|
9
|
-
- [Quick Start](#quick-start)
|
|
10
|
-
- [API Reference](#api-reference)
|
|
11
|
-
- [Authentication](#authentication)
|
|
12
|
-
- [Configuration](#configuration)
|
|
13
|
-
- [Error Handling](#error-handling)
|
|
14
|
-
- [Types](#types)
|
|
15
|
-
- [Generation & Publishing](#generation--publishing)
|
|
16
|
-
- [Prerequisites](#prerequisites)
|
|
17
|
-
- [Generating the Client](#generating-the-client)
|
|
18
|
-
- [Publishing to npm](#publishing-to-npm)
|
|
19
|
-
- [npm Authentication](#npm-authentication)
|
|
20
|
-
- [Troubleshooting](#troubleshooting)
|
|
21
|
-
|
|
22
|
-
## Installation
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
-
npm install @tammsyr/admin-api-client
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
**Peer dependency:** This package uses [axios](https://www.npmjs.com/package/axios) for HTTP requests. If your project doesn't already have it:
|
|
29
|
-
|
|
30
|
-
```bash
|
|
31
|
-
npm install axios
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## Requirements
|
|
35
|
-
|
|
36
|
-
- Node.js 18+
|
|
37
|
-
- TypeScript 5.x (optional, for type definitions)
|
|
38
|
-
|
|
39
|
-
## Quick Start
|
|
40
|
-
|
|
41
|
-
```typescript
|
|
42
|
-
import { AdminApiClient } from '@tammsyr/admin-api-client';
|
|
43
|
-
|
|
44
|
-
async function main() {
|
|
45
|
-
const adminClient = new AdminApiClient({
|
|
46
|
-
baseURL: 'http://localhost:3006/admin/v1',
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const loginResponse = await adminClient.auth.login({
|
|
50
|
-
email: 'admin@example.com',
|
|
51
|
-
password: 'password123',
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
adminClient.setToken(loginResponse.data.accessToken);
|
|
55
|
-
|
|
56
|
-
const admins = await adminClient.admins.getAll();
|
|
57
|
-
const roles = await adminClient.roles.getAll();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
main().catch(console.error);
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
**Important:** The `baseURL` must include the `/admin/v1` path. The Admin Service serves all routes under that prefix.
|
|
64
|
-
|
|
65
|
-
## API Reference
|
|
66
|
-
|
|
67
|
-
### Available APIs
|
|
68
|
-
|
|
69
|
-
| Property | Description |
|
|
70
|
-
| ------------------------------ | --------------------------------------- |
|
|
71
|
-
| `adminClient.auth` | Authentication (login, logout, refresh) |
|
|
72
|
-
| `adminClient.admins` | Admin user management |
|
|
73
|
-
| `adminClient.roles` | Role management |
|
|
74
|
-
| `adminClient.permissions` | Permission management |
|
|
75
|
-
| `adminClient.agents` | Agent management |
|
|
76
|
-
| `adminClient.agentBranches` | Agent branch management |
|
|
77
|
-
| `adminClient.agentSettlements` | Agent settlement management |
|
|
78
|
-
| `adminClient.kyc` | KYC management |
|
|
79
|
-
| `adminClient.notifications` | Notification management |
|
|
80
|
-
| `adminClient.activityLogs` | Activity log queries |
|
|
81
|
-
| `adminClient.seed` | Database seeding (dev only) |
|
|
82
|
-
|
|
83
|
-
## Authentication
|
|
84
|
-
|
|
85
|
-
```typescript
|
|
86
|
-
// Set token during initialization
|
|
87
|
-
const client = new AdminApiClient({
|
|
88
|
-
baseURL: 'http://localhost:3006/admin/v1',
|
|
89
|
-
token: 'your-token',
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
// Or set token after login
|
|
93
|
-
const res = await client.auth.login({ email, password });
|
|
94
|
-
client.setToken(res.data.accessToken);
|
|
95
|
-
|
|
96
|
-
// Update token later
|
|
97
|
-
client.setToken('new-token');
|
|
98
|
-
|
|
99
|
-
// Clear token
|
|
100
|
-
client.clearToken();
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
### Using Individual API Classes
|
|
104
|
-
|
|
105
|
-
```typescript
|
|
106
|
-
import { Admins, HttpClient } from '@tammsyr/admin-api-client';
|
|
107
|
-
|
|
108
|
-
const httpClient = new HttpClient({
|
|
109
|
-
baseURL: 'http://localhost:3006/admin/v1',
|
|
110
|
-
securityWorker: async (authData) => {
|
|
111
|
-
const token = authData?.token ?? localStorage.getItem('admin_token');
|
|
112
|
-
if (token) {
|
|
113
|
-
return { headers: { Authorization: `Bearer ${token}` } };
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
secure: true,
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
const adminsApi = new Admins(httpClient);
|
|
120
|
-
const allAdmins = await adminsApi.getAll();
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
## Configuration
|
|
124
|
-
|
|
125
|
-
```typescript
|
|
126
|
-
const client = new AdminApiClient({
|
|
127
|
-
baseURL: 'http://localhost:3006/admin/v1',
|
|
128
|
-
timeout: 10000,
|
|
129
|
-
token: 'your-jwt-token',
|
|
130
|
-
headers: {
|
|
131
|
-
'X-Custom-Header': 'value',
|
|
132
|
-
},
|
|
133
|
-
});
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
| Option | Type | Default | Description |
|
|
137
|
-
| --------- | ------------------------ | ---------------------------------- | ------------------------------------------------- |
|
|
138
|
-
| `baseURL` | `string` | `'http://localhost:3006/admin/v1'` | Admin Service base URL (must include `/admin/v1`) |
|
|
139
|
-
| `timeout` | `number` | `10000` | Request timeout in ms |
|
|
140
|
-
| `token` | `string` | — | JWT token for authenticated requests |
|
|
141
|
-
| `headers` | `Record<string, string>` | `{}` | Additional request headers |
|
|
142
|
-
|
|
143
|
-
**Environment-based URL example:**
|
|
144
|
-
|
|
145
|
-
```typescript
|
|
146
|
-
const baseURL = process.env.NODE_ENV === 'production' ? 'https://admin.tamm.com/admin/v1' : 'http://localhost:3006/admin/v1';
|
|
147
|
-
|
|
148
|
-
const client = new AdminApiClient({ baseURL });
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
## Error Handling
|
|
152
|
-
|
|
153
|
-
```typescript
|
|
154
|
-
try {
|
|
155
|
-
const response = await adminClient.admins.create(adminData);
|
|
156
|
-
console.log('Success:', response.data);
|
|
157
|
-
} catch (err: any) {
|
|
158
|
-
if (err.response) {
|
|
159
|
-
console.error('API Error:', err.response.status, err.response.data);
|
|
160
|
-
} else {
|
|
161
|
-
console.error('Network Error:', err.message);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
## Types
|
|
167
|
-
|
|
168
|
-
All request/response types are exported:
|
|
169
|
-
|
|
170
|
-
```typescript
|
|
171
|
-
import type {
|
|
172
|
-
AdminLoginRequestDto,
|
|
173
|
-
AdminUserDto,
|
|
174
|
-
AdminRoleDto,
|
|
175
|
-
AdminPermissionDto,
|
|
176
|
-
LoginData,
|
|
177
|
-
// ... other types
|
|
178
|
-
} from '@tammsyr/admin-api-client';
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
---
|
|
182
|
-
|
|
183
|
-
## Generation & Publishing
|
|
184
|
-
|
|
185
|
-
This section covers how to regenerate the client when the Admin Service API changes and how to publish a new version to npm.
|
|
186
|
-
|
|
187
|
-
### Prerequisites
|
|
188
|
-
|
|
189
|
-
All commands are run from the **monorepo root** (`tamm-microservices/`).
|
|
190
|
-
|
|
191
|
-
| Tool | Purpose |
|
|
192
|
-
| ------------------------ | ----------------------- |
|
|
193
|
-
| `swagger-typescript-api` | Generates the TS client |
|
|
194
|
-
| `typescript` | Compiles for publishing |
|
|
195
|
-
| `npm` account | Required for publishing |
|
|
196
|
-
|
|
197
|
-
Both tools are already listed in the root `devDependencies` — just run `npm install`.
|
|
198
|
-
|
|
199
|
-
### Generating the Client
|
|
200
|
-
|
|
201
|
-
#### Step 1 — Start the Admin Service
|
|
202
|
-
|
|
203
|
-
The OpenAPI spec is fetched from the running server's Swagger endpoint at `http://localhost:3006/admin/docs-json`.
|
|
204
|
-
|
|
205
|
-
```bash
|
|
206
|
-
npm run start:admin
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
Wait until the service is fully started before proceeding.
|
|
210
|
-
|
|
211
|
-
#### Step 2 — Fetch the OpenAPI Spec
|
|
212
|
-
|
|
213
|
-
```bash
|
|
214
|
-
npm run generate:admin-openapi-spec
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
This saves the spec to `admin-openapi.json` at the monorepo root. You can also set a custom URL via the `ADMIN_SERVICE_URL` environment variable.
|
|
218
|
-
|
|
219
|
-
#### Step 3 — Generate the TypeScript Client
|
|
220
|
-
|
|
221
|
-
```bash
|
|
222
|
-
npm run generate:admin-typescript-client
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
Output is written to `generated/admin-client/`.
|
|
226
|
-
|
|
227
|
-
#### Combined Shortcut
|
|
228
|
-
|
|
229
|
-
Run Steps 2 and 3 together (Admin Service must already be running):
|
|
230
|
-
|
|
231
|
-
```bash
|
|
232
|
-
npm run generate:admin-typescript-client:full
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
#### Review Changes
|
|
236
|
-
|
|
237
|
-
```bash
|
|
238
|
-
git diff admin-openapi.json
|
|
239
|
-
git diff generated/admin-client/
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
### Publishing to npm
|
|
243
|
-
|
|
244
|
-
#### 1. Bump the version and publish
|
|
245
|
-
|
|
246
|
-
```bash
|
|
247
|
-
npm run publish:admin-client -- --version=<new-version>
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
The script will:
|
|
251
|
-
|
|
252
|
-
1. Update the version in `generated/admin-client/package.json`
|
|
253
|
-
2. Run `tsc` to build the `dist/` folder
|
|
254
|
-
3. Publish `@tammsyr/admin-api-client` to the public npm registry
|
|
255
|
-
|
|
256
|
-
#### 2. Dry-run first (recommended)
|
|
257
|
-
|
|
258
|
-
Verify everything looks correct without actually publishing:
|
|
259
|
-
|
|
260
|
-
```bash
|
|
261
|
-
npm run publish:admin-client -- --dry-run
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
#### 3. Version and publish together
|
|
265
|
-
|
|
266
|
-
```bash
|
|
267
|
-
npm run publish:admin-client -- --version=1.0.6 --dry-run # verify
|
|
268
|
-
npm run publish:admin-client -- --version=1.0.6 # publish for real
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
### npm Authentication
|
|
272
|
-
|
|
273
|
-
You must be authenticated with npm to publish. There are two options:
|
|
274
|
-
|
|
275
|
-
#### Option A — npm login (interactive)
|
|
276
|
-
|
|
277
|
-
```bash
|
|
278
|
-
npm login
|
|
279
|
-
```
|
|
280
|
-
|
|
281
|
-
If 2FA is enabled on your account, you'll be prompted for a one-time password.
|
|
282
|
-
|
|
283
|
-
#### Option B — Access token (CI / non-interactive)
|
|
284
|
-
|
|
285
|
-
1. Create a **Granular Access Token** on [npmjs.com](https://www.npmjs.com) with publish permissions for `@tammsyr/*`
|
|
286
|
-
2. Set it as an environment variable before publishing:
|
|
287
|
-
|
|
288
|
-
```powershell
|
|
289
|
-
# PowerShell
|
|
290
|
-
$env:NPM_TOKEN="YOUR_TOKEN_HERE"
|
|
291
|
-
npm run publish:admin-client -- --version=1.0.6
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
```bash
|
|
295
|
-
# Bash / Linux / macOS
|
|
296
|
-
export NPM_TOKEN="YOUR_TOKEN_HERE"
|
|
297
|
-
npm run publish:admin-client -- --version=1.0.6
|
|
298
|
-
```
|
|
299
|
-
|
|
300
|
-
See [`docs/npm-2fa-setup.md`](../../docs/npm-2fa-setup.md) for detailed 2FA and token configuration.
|
|
301
|
-
|
|
302
|
-
### Full End-to-End Example
|
|
303
|
-
|
|
304
|
-
```bash
|
|
305
|
-
# 1. Start the Admin Service
|
|
306
|
-
npm run start:admin
|
|
307
|
-
|
|
308
|
-
# 2. (in another terminal) Generate the client
|
|
309
|
-
npm run generate:admin-typescript-client:full
|
|
310
|
-
|
|
311
|
-
# 3. Review changes
|
|
312
|
-
git diff admin-openapi.json generated/admin-client/
|
|
313
|
-
|
|
314
|
-
# 4. Dry-run publish
|
|
315
|
-
npm run publish:admin-client -- --version=1.0.6 --dry-run
|
|
316
|
-
|
|
317
|
-
# 5. Publish for real
|
|
318
|
-
npm run publish:admin-client -- --version=1.0.6
|
|
319
|
-
|
|
320
|
-
# 6. Commit
|
|
321
|
-
git add admin-openapi.json generated/admin-client/
|
|
322
|
-
git commit -m "chore: regenerate and publish admin client v1.0.6"
|
|
323
|
-
```
|
|
324
|
-
|
|
325
|
-
## Troubleshooting
|
|
326
|
-
|
|
327
|
-
| Problem | Solution |
|
|
328
|
-
| ------------------------------------ | ------------------------------------------------------------------------------------------------------- |
|
|
329
|
-
| `generate:admin-openapi-spec` fails | Make sure the Admin Service is running (`npm run start:admin`) and reachable at `http://localhost:3006` |
|
|
330
|
-
| Generated code has TypeScript errors | Verify the OpenAPI spec is valid — check Swagger UI at `http://localhost:3006/admin/docs` |
|
|
331
|
-
| `403 Forbidden` on publish | Check npm auth (`npm whoami`), org membership (`npm org ls tammsyr`), and 2FA/token setup |
|
|
332
|
-
| `Two-factor authentication required` | Enable 2FA on npmjs.com or use a granular access token with bypass-2FA enabled |
|
|
333
|
-
| Version conflict on publish | Ensure the `--version` you're publishing doesn't already exist on the registry |
|
|
334
|
-
|
|
335
|
-
## Versioning
|
|
336
|
-
|
|
337
|
-
This package follows [semantic versioning](https://semver.org/).
|
|
338
|
-
|
|
339
|
-
## License
|
|
340
|
-
|
|
341
|
-
MIT
|
|
1
|
+
# @tammsyr/admin-api-client
|
|
2
|
+
|
|
3
|
+
TypeScript client for TAMM Admin Service API. Auto-generated from OpenAPI specification using [swagger-typescript-api](https://github.com/acacode/swagger-typescript-api).
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Installation](#installation)
|
|
8
|
+
- [Requirements](#requirements)
|
|
9
|
+
- [Quick Start](#quick-start)
|
|
10
|
+
- [API Reference](#api-reference)
|
|
11
|
+
- [Authentication](#authentication)
|
|
12
|
+
- [Configuration](#configuration)
|
|
13
|
+
- [Error Handling](#error-handling)
|
|
14
|
+
- [Types](#types)
|
|
15
|
+
- [Generation & Publishing](#generation--publishing)
|
|
16
|
+
- [Prerequisites](#prerequisites)
|
|
17
|
+
- [Generating the Client](#generating-the-client)
|
|
18
|
+
- [Publishing to npm](#publishing-to-npm)
|
|
19
|
+
- [npm Authentication](#npm-authentication)
|
|
20
|
+
- [Troubleshooting](#troubleshooting)
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install @tammsyr/admin-api-client
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Peer dependency:** This package uses [axios](https://www.npmjs.com/package/axios) for HTTP requests. If your project doesn't already have it:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install axios
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Requirements
|
|
35
|
+
|
|
36
|
+
- Node.js 18+
|
|
37
|
+
- TypeScript 5.x (optional, for type definitions)
|
|
38
|
+
|
|
39
|
+
## Quick Start
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { AdminApiClient } from '@tammsyr/admin-api-client';
|
|
43
|
+
|
|
44
|
+
async function main() {
|
|
45
|
+
const adminClient = new AdminApiClient({
|
|
46
|
+
baseURL: 'http://localhost:3006/admin/v1',
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const loginResponse = await adminClient.auth.login({
|
|
50
|
+
email: 'admin@example.com',
|
|
51
|
+
password: 'password123',
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
adminClient.setToken(loginResponse.data.accessToken);
|
|
55
|
+
|
|
56
|
+
const admins = await adminClient.admins.getAll();
|
|
57
|
+
const roles = await adminClient.roles.getAll();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
main().catch(console.error);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**Important:** The `baseURL` must include the `/admin/v1` path. The Admin Service serves all routes under that prefix.
|
|
64
|
+
|
|
65
|
+
## API Reference
|
|
66
|
+
|
|
67
|
+
### Available APIs
|
|
68
|
+
|
|
69
|
+
| Property | Description |
|
|
70
|
+
| ------------------------------ | --------------------------------------- |
|
|
71
|
+
| `adminClient.auth` | Authentication (login, logout, refresh) |
|
|
72
|
+
| `adminClient.admins` | Admin user management |
|
|
73
|
+
| `adminClient.roles` | Role management |
|
|
74
|
+
| `adminClient.permissions` | Permission management |
|
|
75
|
+
| `adminClient.agents` | Agent management |
|
|
76
|
+
| `adminClient.agentBranches` | Agent branch management |
|
|
77
|
+
| `adminClient.agentSettlements` | Agent settlement management |
|
|
78
|
+
| `adminClient.kyc` | KYC management |
|
|
79
|
+
| `adminClient.notifications` | Notification management |
|
|
80
|
+
| `adminClient.activityLogs` | Activity log queries |
|
|
81
|
+
| `adminClient.seed` | Database seeding (dev only) |
|
|
82
|
+
|
|
83
|
+
## Authentication
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
// Set token during initialization
|
|
87
|
+
const client = new AdminApiClient({
|
|
88
|
+
baseURL: 'http://localhost:3006/admin/v1',
|
|
89
|
+
token: 'your-token',
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Or set token after login
|
|
93
|
+
const res = await client.auth.login({ email, password });
|
|
94
|
+
client.setToken(res.data.accessToken);
|
|
95
|
+
|
|
96
|
+
// Update token later
|
|
97
|
+
client.setToken('new-token');
|
|
98
|
+
|
|
99
|
+
// Clear token
|
|
100
|
+
client.clearToken();
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Using Individual API Classes
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { Admins, HttpClient } from '@tammsyr/admin-api-client';
|
|
107
|
+
|
|
108
|
+
const httpClient = new HttpClient({
|
|
109
|
+
baseURL: 'http://localhost:3006/admin/v1',
|
|
110
|
+
securityWorker: async (authData) => {
|
|
111
|
+
const token = authData?.token ?? localStorage.getItem('admin_token');
|
|
112
|
+
if (token) {
|
|
113
|
+
return { headers: { Authorization: `Bearer ${token}` } };
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
secure: true,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const adminsApi = new Admins(httpClient);
|
|
120
|
+
const allAdmins = await adminsApi.getAll();
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Configuration
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
const client = new AdminApiClient({
|
|
127
|
+
baseURL: 'http://localhost:3006/admin/v1',
|
|
128
|
+
timeout: 10000,
|
|
129
|
+
token: 'your-jwt-token',
|
|
130
|
+
headers: {
|
|
131
|
+
'X-Custom-Header': 'value',
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
| Option | Type | Default | Description |
|
|
137
|
+
| --------- | ------------------------ | ---------------------------------- | ------------------------------------------------- |
|
|
138
|
+
| `baseURL` | `string` | `'http://localhost:3006/admin/v1'` | Admin Service base URL (must include `/admin/v1`) |
|
|
139
|
+
| `timeout` | `number` | `10000` | Request timeout in ms |
|
|
140
|
+
| `token` | `string` | — | JWT token for authenticated requests |
|
|
141
|
+
| `headers` | `Record<string, string>` | `{}` | Additional request headers |
|
|
142
|
+
|
|
143
|
+
**Environment-based URL example:**
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
const baseURL = process.env.NODE_ENV === 'production' ? 'https://admin.tamm.com/admin/v1' : 'http://localhost:3006/admin/v1';
|
|
147
|
+
|
|
148
|
+
const client = new AdminApiClient({ baseURL });
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Error Handling
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
try {
|
|
155
|
+
const response = await adminClient.admins.create(adminData);
|
|
156
|
+
console.log('Success:', response.data);
|
|
157
|
+
} catch (err: any) {
|
|
158
|
+
if (err.response) {
|
|
159
|
+
console.error('API Error:', err.response.status, err.response.data);
|
|
160
|
+
} else {
|
|
161
|
+
console.error('Network Error:', err.message);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Types
|
|
167
|
+
|
|
168
|
+
All request/response types are exported:
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
import type {
|
|
172
|
+
AdminLoginRequestDto,
|
|
173
|
+
AdminUserDto,
|
|
174
|
+
AdminRoleDto,
|
|
175
|
+
AdminPermissionDto,
|
|
176
|
+
LoginData,
|
|
177
|
+
// ... other types
|
|
178
|
+
} from '@tammsyr/admin-api-client';
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## Generation & Publishing
|
|
184
|
+
|
|
185
|
+
This section covers how to regenerate the client when the Admin Service API changes and how to publish a new version to npm.
|
|
186
|
+
|
|
187
|
+
### Prerequisites
|
|
188
|
+
|
|
189
|
+
All commands are run from the **monorepo root** (`tamm-microservices/`).
|
|
190
|
+
|
|
191
|
+
| Tool | Purpose |
|
|
192
|
+
| ------------------------ | ----------------------- |
|
|
193
|
+
| `swagger-typescript-api` | Generates the TS client |
|
|
194
|
+
| `typescript` | Compiles for publishing |
|
|
195
|
+
| `npm` account | Required for publishing |
|
|
196
|
+
|
|
197
|
+
Both tools are already listed in the root `devDependencies` — just run `npm install`.
|
|
198
|
+
|
|
199
|
+
### Generating the Client
|
|
200
|
+
|
|
201
|
+
#### Step 1 — Start the Admin Service
|
|
202
|
+
|
|
203
|
+
The OpenAPI spec is fetched from the running server's Swagger endpoint at `http://localhost:3006/admin/docs-json`.
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
npm run start:admin
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Wait until the service is fully started before proceeding.
|
|
210
|
+
|
|
211
|
+
#### Step 2 — Fetch the OpenAPI Spec
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
npm run generate:admin-openapi-spec
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
This saves the spec to `admin-openapi.json` at the monorepo root. You can also set a custom URL via the `ADMIN_SERVICE_URL` environment variable.
|
|
218
|
+
|
|
219
|
+
#### Step 3 — Generate the TypeScript Client
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
npm run generate:admin-typescript-client
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Output is written to `generated/admin-client/`.
|
|
226
|
+
|
|
227
|
+
#### Combined Shortcut
|
|
228
|
+
|
|
229
|
+
Run Steps 2 and 3 together (Admin Service must already be running):
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
npm run generate:admin-typescript-client:full
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
#### Review Changes
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
git diff admin-openapi.json
|
|
239
|
+
git diff generated/admin-client/
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Publishing to npm
|
|
243
|
+
|
|
244
|
+
#### 1. Bump the version and publish
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
npm run publish:admin-client -- --version=<new-version>
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
The script will:
|
|
251
|
+
|
|
252
|
+
1. Update the version in `generated/admin-client/package.json`
|
|
253
|
+
2. Run `tsc` to build the `dist/` folder
|
|
254
|
+
3. Publish `@tammsyr/admin-api-client` to the public npm registry
|
|
255
|
+
|
|
256
|
+
#### 2. Dry-run first (recommended)
|
|
257
|
+
|
|
258
|
+
Verify everything looks correct without actually publishing:
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
npm run publish:admin-client -- --dry-run
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
#### 3. Version and publish together
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
npm run publish:admin-client -- --version=1.0.6 --dry-run # verify
|
|
268
|
+
npm run publish:admin-client -- --version=1.0.6 # publish for real
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### npm Authentication
|
|
272
|
+
|
|
273
|
+
You must be authenticated with npm to publish. There are two options:
|
|
274
|
+
|
|
275
|
+
#### Option A — npm login (interactive)
|
|
276
|
+
|
|
277
|
+
```bash
|
|
278
|
+
npm login
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
If 2FA is enabled on your account, you'll be prompted for a one-time password.
|
|
282
|
+
|
|
283
|
+
#### Option B — Access token (CI / non-interactive)
|
|
284
|
+
|
|
285
|
+
1. Create a **Granular Access Token** on [npmjs.com](https://www.npmjs.com) with publish permissions for `@tammsyr/*`
|
|
286
|
+
2. Set it as an environment variable before publishing:
|
|
287
|
+
|
|
288
|
+
```powershell
|
|
289
|
+
# PowerShell
|
|
290
|
+
$env:NPM_TOKEN="YOUR_TOKEN_HERE"
|
|
291
|
+
npm run publish:admin-client -- --version=1.0.6
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
```bash
|
|
295
|
+
# Bash / Linux / macOS
|
|
296
|
+
export NPM_TOKEN="YOUR_TOKEN_HERE"
|
|
297
|
+
npm run publish:admin-client -- --version=1.0.6
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
See [`docs/npm-2fa-setup.md`](../../docs/npm-2fa-setup.md) for detailed 2FA and token configuration.
|
|
301
|
+
|
|
302
|
+
### Full End-to-End Example
|
|
303
|
+
|
|
304
|
+
```bash
|
|
305
|
+
# 1. Start the Admin Service
|
|
306
|
+
npm run start:admin
|
|
307
|
+
|
|
308
|
+
# 2. (in another terminal) Generate the client
|
|
309
|
+
npm run generate:admin-typescript-client:full
|
|
310
|
+
|
|
311
|
+
# 3. Review changes
|
|
312
|
+
git diff admin-openapi.json generated/admin-client/
|
|
313
|
+
|
|
314
|
+
# 4. Dry-run publish
|
|
315
|
+
npm run publish:admin-client -- --version=1.0.6 --dry-run
|
|
316
|
+
|
|
317
|
+
# 5. Publish for real
|
|
318
|
+
npm run publish:admin-client -- --version=1.0.6
|
|
319
|
+
|
|
320
|
+
# 6. Commit
|
|
321
|
+
git add admin-openapi.json generated/admin-client/
|
|
322
|
+
git commit -m "chore: regenerate and publish admin client v1.0.6"
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
## Troubleshooting
|
|
326
|
+
|
|
327
|
+
| Problem | Solution |
|
|
328
|
+
| ------------------------------------ | ------------------------------------------------------------------------------------------------------- |
|
|
329
|
+
| `generate:admin-openapi-spec` fails | Make sure the Admin Service is running (`npm run start:admin`) and reachable at `http://localhost:3006` |
|
|
330
|
+
| Generated code has TypeScript errors | Verify the OpenAPI spec is valid — check Swagger UI at `http://localhost:3006/admin/docs` |
|
|
331
|
+
| `403 Forbidden` on publish | Check npm auth (`npm whoami`), org membership (`npm org ls tammsyr`), and 2FA/token setup |
|
|
332
|
+
| `Two-factor authentication required` | Enable 2FA on npmjs.com or use a granular access token with bypass-2FA enabled |
|
|
333
|
+
| Version conflict on publish | Ensure the `--version` you're publishing doesn't already exist on the registry |
|
|
334
|
+
|
|
335
|
+
## Versioning
|
|
336
|
+
|
|
337
|
+
This package follows [semantic versioning](https://semver.org/).
|
|
338
|
+
|
|
339
|
+
## License
|
|
340
|
+
|
|
341
|
+
MIT
|