@aifabrix/miso-client 1.0.0 → 1.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.
Files changed (80) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +448 -147
  3. package/dist/examples/step-3-authentication.d.ts +8 -0
  4. package/dist/examples/step-3-authentication.d.ts.map +1 -0
  5. package/dist/examples/step-3-authentication.js +45 -0
  6. package/dist/examples/step-3-authentication.js.map +1 -0
  7. package/dist/examples/step-4-rbac.d.ts +8 -0
  8. package/dist/examples/step-4-rbac.d.ts.map +1 -0
  9. package/dist/examples/step-4-rbac.js +54 -0
  10. package/dist/examples/step-4-rbac.js.map +1 -0
  11. package/dist/examples/step-5-logging.d.ts +8 -0
  12. package/dist/examples/step-5-logging.d.ts.map +1 -0
  13. package/dist/examples/step-5-logging.js +66 -0
  14. package/dist/examples/step-5-logging.js.map +1 -0
  15. package/dist/examples/step-6-audit.d.ts +8 -0
  16. package/dist/examples/step-6-audit.d.ts.map +1 -0
  17. package/dist/examples/step-6-audit.js +97 -0
  18. package/dist/examples/step-6-audit.js.map +1 -0
  19. package/dist/examples/usage.d.ts +6 -0
  20. package/dist/examples/usage.d.ts.map +1 -0
  21. package/dist/examples/usage.js +65 -0
  22. package/dist/examples/usage.js.map +1 -0
  23. package/dist/{index.d.ts → src/index.d.ts} +1 -0
  24. package/dist/src/index.d.ts.map +1 -0
  25. package/dist/{index.js → src/index.js} +4 -1
  26. package/dist/src/index.js.map +1 -0
  27. package/dist/src/services/auth.service.d.ts.map +1 -0
  28. package/dist/src/services/auth.service.js.map +1 -0
  29. package/dist/src/services/logger.service.d.ts.map +1 -0
  30. package/dist/{services → src/services}/logger.service.js +9 -7
  31. package/dist/{services → src/services}/logger.service.js.map +1 -1
  32. package/dist/src/services/permission.service.d.ts.map +1 -0
  33. package/dist/src/services/permission.service.js.map +1 -0
  34. package/dist/src/services/redis.service.d.ts.map +1 -0
  35. package/dist/src/services/redis.service.js.map +1 -0
  36. package/dist/src/services/role.service.d.ts.map +1 -0
  37. package/dist/src/services/role.service.js.map +1 -0
  38. package/dist/src/types/config.types.d.ts.map +1 -0
  39. package/dist/src/types/config.types.js.map +1 -0
  40. package/dist/src/utils/config-loader.d.ts +11 -0
  41. package/dist/src/utils/config-loader.d.ts.map +1 -0
  42. package/dist/src/utils/config-loader.js +39 -0
  43. package/dist/src/utils/config-loader.js.map +1 -0
  44. package/dist/src/utils/data-masker.d.ts.map +1 -0
  45. package/dist/src/utils/data-masker.js.map +1 -0
  46. package/dist/src/utils/http-client.d.ts.map +1 -0
  47. package/dist/src/utils/http-client.js.map +1 -0
  48. package/package.json +60 -60
  49. package/dist/index.d.ts.map +0 -1
  50. package/dist/index.js.map +0 -1
  51. package/dist/services/auth.service.d.ts.map +0 -1
  52. package/dist/services/auth.service.js.map +0 -1
  53. package/dist/services/logger.service.d.ts.map +0 -1
  54. package/dist/services/permission.service.d.ts.map +0 -1
  55. package/dist/services/permission.service.js.map +0 -1
  56. package/dist/services/redis.service.d.ts.map +0 -1
  57. package/dist/services/redis.service.js.map +0 -1
  58. package/dist/services/role.service.d.ts.map +0 -1
  59. package/dist/services/role.service.js.map +0 -1
  60. package/dist/types/config.types.d.ts.map +0 -1
  61. package/dist/types/config.types.js.map +0 -1
  62. package/dist/utils/data-masker.d.ts.map +0 -1
  63. package/dist/utils/data-masker.js.map +0 -1
  64. package/dist/utils/http-client.d.ts.map +0 -1
  65. package/dist/utils/http-client.js.map +0 -1
  66. /package/dist/{services → src/services}/auth.service.d.ts +0 -0
  67. /package/dist/{services → src/services}/auth.service.js +0 -0
  68. /package/dist/{services → src/services}/logger.service.d.ts +0 -0
  69. /package/dist/{services → src/services}/permission.service.d.ts +0 -0
  70. /package/dist/{services → src/services}/permission.service.js +0 -0
  71. /package/dist/{services → src/services}/redis.service.d.ts +0 -0
  72. /package/dist/{services → src/services}/redis.service.js +0 -0
  73. /package/dist/{services → src/services}/role.service.d.ts +0 -0
  74. /package/dist/{services → src/services}/role.service.js +0 -0
  75. /package/dist/{types → src/types}/config.types.d.ts +0 -0
  76. /package/dist/{types → src/types}/config.types.js +0 -0
  77. /package/dist/{utils → src/utils}/data-masker.d.ts +0 -0
  78. /package/dist/{utils → src/utils}/data-masker.js +0 -0
  79. /package/dist/{utils → src/utils}/http-client.d.ts +0 -0
  80. /package/dist/{utils → src/utils}/http-client.js +0 -0
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 eSystems Nordic Ltd.
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) 2025 eSystems Nordic Ltd.
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,147 +1,448 @@
1
- # AI Fabrix Miso Client SDK
2
-
3
- [![npm version](https://badge.fury.io/js/%40aifabrix%2Fmiso-client.svg)](https://badge.fury.io/js/%40aifabrix%2Fmiso-client)
4
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
-
6
- The **AI Fabrix Miso Client SDK** is a TypeScript/JavaScript library that provides authentication, authorization, and logging capabilities for applications integrated with the AI Fabrix platform. It offers seamless integration with Keycloak authentication, Redis caching, and centralized logging.
7
-
8
- ## 🚀 Features
9
-
10
- - **🔐 Authentication**: Token validation and user management
11
- - **🛡️ Authorization**: Role and permission-based access control
12
- - **📊 Logging**: Centralized logging with audit trails and API key authentication
13
- - **⚡ Caching**: Redis-based caching for improved performance
14
- - **🔄 Fallback**: Automatic fallback to controller when Redis is unavailable
15
- - **🔑 API Key Security**: Secure API key authentication for application logging
16
- - **📱 Multi-platform**: Works in Node.js and browser environments
17
- - **🔧 TypeScript**: Full TypeScript support with type definitions
18
-
19
- ## 📚 Documentation
20
-
21
- - **[Getting Started](docs/getting-started.md)** - Installation and basic setup
22
- - **[API Reference](docs/api-reference.md)** - Complete API documentation
23
- - **[Configuration](docs/configuration.md)** - Configuration options and examples
24
- - **[Examples](docs/examples.md)** - Practical usage examples
25
- - **[Troubleshooting](docs/troubleshooting.md)** - Common issues and solutions
26
-
27
- ## 🏃‍♂️ Quick Start
28
-
29
- ```bash
30
- npm install @aifabrix/miso-client
31
- ```
32
-
33
- ```typescript
34
- import { MisoClient } from '@aifabrix/miso-client';
35
-
36
- const client = new MisoClient({
37
- controllerUrl: 'https://controller.aifabrix.ai',
38
- environment: 'dev',
39
- applicationKey: 'your-app-key',
40
- applicationId: 'your-app-id-123', // NEW: Application GUID
41
- apiKey: 'your-api-key', // NEW: API key for logging
42
- redis: {
43
- host: 'localhost',
44
- port: 6379,
45
- password: 'your-redis-password'
46
- }
47
- });
48
-
49
- await client.initialize();
50
-
51
- // Validate user token
52
- const isValid = await client.validateToken(userToken);
53
- if (isValid) {
54
- const user = await client.getUser(userToken);
55
- const roles = await client.getRoles(userToken);
56
-
57
- // Check permissions
58
- const canEdit = await client.hasPermission(userToken, 'edit:content');
59
-
60
- // Log events (now with API key authentication)
61
- client.log.audit('user.login', 'authentication', { userId: user.id });
62
- }
63
- ```
64
-
65
- ## 🏗️ Architecture
66
-
67
- The Miso Client SDK consists of several core services:
68
-
69
- - **AuthService**: Handles token validation and user authentication
70
- - **RoleService**: Manages user roles with Redis caching
71
- - **PermissionService**: Handles fine-grained permissions
72
- - **LoggerService**: Centralized logging and audit trails
73
- - **RedisService**: Caching and queue management
74
-
75
- ## 🔧 Configuration
76
-
77
- The SDK supports flexible configuration options:
78
-
79
- ```typescript
80
- interface MisoClientConfig {
81
- controllerUrl: string; // AI Fabrix controller URL
82
- environment: 'dev' | 'tst' | 'pro'; // Environment
83
- applicationKey: string; // Your application identifier
84
- applicationId: string; // NEW: Application GUID
85
- apiKey?: string; // NEW: API key for logging authentication
86
- redis?: RedisConfig; // Optional Redis configuration
87
- logLevel?: 'debug' | 'info' | 'warn' | 'error';
88
- cache?: {
89
- roleTTL?: number; // Role cache TTL (default: 15 minutes)
90
- permissionTTL?: number; // Permission cache TTL (default: 15 minutes)
91
- };
92
- }
93
- ```
94
-
95
- ## 🌐 Environments
96
-
97
- The SDK supports three environments:
98
-
99
- - **`dev`** - Development environment
100
- - **`tst`** - Test environment
101
- - **`pro`** - Production environment
102
-
103
- ## 📦 Installation
104
-
105
- ### NPM
106
-
107
- ```bash
108
- npm install @aifabrix/miso-client
109
- ```
110
-
111
- ### Yarn
112
-
113
- ```bash
114
- yarn add @aifabrix/miso-client
115
- ```
116
-
117
- ### PNPM
118
-
119
- ```bash
120
- pnpm add @aifabrix/miso-client
121
- ```
122
-
123
- ## 🔗 Links
124
-
125
- - **GitHub Repository**: [https://github.com/aifabrix/aifabrix-miso](https://github.com/aifabrix/aifabrix-miso)
126
- - **Documentation**: [https://docs.aifabrix.ai](https://docs.aifabrix.ai)
127
- - **Issues**: [https://github.com/aifabrix/aifabrix-miso/issues](https://github.com/aifabrix/aifabrix-miso/issues)
128
-
129
- ## 📄 License
130
-
131
- This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
132
-
133
- ## 🤝 Contributing
134
-
135
- Contributions are welcome! Please read our contributing guidelines and submit pull requests to our GitHub repository.
136
-
137
- ## 📞 Support
138
-
139
- For support and questions:
140
-
141
- - **Email**: <support@aifabrix.ai>
142
- - **Documentation**: [https://docs.aifabrix.ai](https://docs.aifabrix.ai)
143
- - **GitHub Issues**: [https://github.com/aifabrix/aifabrix-miso/issues](https://github.com/aifabrix/aifabrix-miso/issues)
144
-
145
- ---
146
-
147
- **Made with ❤️ by the AI Fabrix Team**
1
+ # AI Fabrix Miso Client SDK
2
+
3
+ [![npm version](https://badge.fury.io/js/%40aifabrix%2Fmiso-client.svg)](https://badge.fury.io/js/%40aifabrix%2Fmiso-client)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ The **AI Fabrix Miso Client SDK** provides authentication, authorization, and logging for applications integrated with the AI Fabrix platform.
7
+
8
+ ## Benefits
9
+
10
+ ### 🔐 Enterprise Security
11
+
12
+ **SSO and Federated Identity**
13
+ - Single Sign-On (SSO) with Keycloak
14
+ - OAuth 2.0 and OpenID Connect (OIDC) support
15
+ - Multi-factor authentication (MFA) ready
16
+ - Social login integration (Google, Microsoft, etc.)
17
+
18
+ **Centralized Access Control**
19
+ - Role-based access control (RBAC)
20
+ - Fine-grained permissions
21
+ - Dynamic policy enforcement
22
+ - Attribute-based access control (ABAC)
23
+
24
+ **API Security**
25
+ - JWT token validation
26
+ - API key authentication
27
+ - Token revocation support
28
+ - Secure token storage
29
+
30
+ ### 📊 Compliance & Audit
31
+
32
+ **ISO 27001 Compliance**
33
+ - Comprehensive audit trails for all user actions
34
+ - Data access logging and monitoring
35
+ - Security event tracking
36
+ - Accountability and non-repudiation
37
+
38
+ **Regulatory Compliance**
39
+ - GDPR-ready data protection
40
+ - HIPAA-compliant audit logging
41
+ - SOC 2 audit trail requirements
42
+ - Industry-standard security controls
43
+
44
+ **Audit Capabilities**
45
+ - Real-time audit event logging
46
+ - Immutable audit records
47
+ - Forensic analysis support
48
+ - Compliance reporting automation
49
+
50
+ ### ⚡ Performance & Scalability
51
+
52
+ **Intelligent Caching**
53
+ - Redis-based role and permission caching
54
+ - Configurable cache TTL (default: 15 minutes)
55
+ - Automatic cache invalidation
56
+ - Fallback to controller when Redis unavailable
57
+
58
+ **High Availability**
59
+ - Automatic failover to controller
60
+ - Redundant infrastructure support
61
+ - Load balancing compatible
62
+ - Zero-downtime deployments
63
+
64
+ **Optimized Network**
65
+ - Efficient API calls with caching
66
+ - Batch operations support
67
+ - Connection pooling
68
+ - Minimal latency
69
+
70
+ ### 🛠️ Developer Experience
71
+
72
+ **Easy Integration**
73
+ - Progressive activation (6-step setup)
74
+ - Works with any framework (Express, Next.js, NestJS, Fastify)
75
+ - TypeScript-first with full type definitions
76
+ - Browser and Node.js support
77
+
78
+ **Flexible Configuration**
79
+ - Environment-based configuration
80
+ - Support for dev, test, and production environments
81
+ - Docker and Kubernetes ready
82
+ - CI/CD friendly
83
+
84
+ **Observability**
85
+ - Centralized logging with correlation IDs
86
+ - Performance tracking and metrics
87
+ - Error tracking and debugging
88
+ - Health monitoring
89
+
90
+ ---
91
+
92
+ ## 🚀 Quick Start
93
+
94
+ Get your application secured in 6 steps.
95
+
96
+ ### Step 1: Set Up Your Environment
97
+
98
+ **What you need:**
99
+ - Keycloak running for authentication
100
+ - AI Fabrix Miso Controller running
101
+
102
+ **First time setting up?** Use the [AI Fabrix Builder Quick Start](https://github.com/esystemsdev/aifabrix-builder/blob/main/docs/QUICK-START.md):
103
+
104
+ ```bash
105
+ # Start infrastructure (Postgres, Redis)
106
+ aifabrix up
107
+
108
+ # Install Keycloak for authentication
109
+ aifabrix create keycloak --port 8082 --database --template platform
110
+ aifabrix build keycloak
111
+ aifabrix run keycloak
112
+
113
+ # Install Miso Controller
114
+ aifabrix create miso-controller --port 3000 --database --redis --template platform
115
+ aifabrix build miso-controller
116
+ aifabrix run miso-controller
117
+ ```
118
+
119
+ → [Infrastructure Guide](https://github.com/esystemsdev/aifabrix-builder/blob/main/docs/INFRASTRUCTURE.md)
120
+
121
+ **Already have Keycloak and Controller?** Skip to Step 2.
122
+
123
+ ---
124
+
125
+ ### Step 2: Install Miso Client
126
+
127
+ ```bash
128
+ npm install @aifabrix/miso-client
129
+ ```
130
+
131
+ **What you get:**
132
+ - Authentication with Keycloak
133
+ - Role-based access control (RBAC)
134
+ - Centralized logging
135
+ - Redis caching for performance
136
+
137
+ ---
138
+
139
+ ### Step 3: Activate Authentication
140
+
141
+ **What happens:** Your app validates user tokens from Keycloak.
142
+
143
+ ```typescript
144
+ import { MisoClient } from '@aifabrix/miso-client';
145
+
146
+ // Create client
147
+ const client = new MisoClient({
148
+ controllerUrl: 'https://controller.aifabrix.ai',
149
+ environment: 'dev',
150
+ applicationKey: 'my-app',
151
+ applicationId: 'my-app-id-123',
152
+ });
153
+
154
+ await client.initialize();
155
+
156
+ // Validate token from request
157
+ const token = req.headers.authorization?.replace('Bearer ', '');
158
+ const isValid = await client.validateToken(token);
159
+
160
+ if (isValid) {
161
+ const user = await client.getUser(token);
162
+ console.log('User:', user);
163
+ }
164
+ ```
165
+
166
+ **Where to get tokens?** Users authenticate via Keycloak, then your app receives JWTs in the `Authorization` header.
167
+
168
+ → [Complete authentication example](examples/step-3-authentication.ts)
169
+
170
+ ---
171
+
172
+ ### Step 4: Activate RBAC (Roles)
173
+
174
+ **What happens:** Check user roles to control access. Roles are cached in Redis for performance.
175
+
176
+ ```typescript
177
+ // Build on Step 3 - add Redis for caching
178
+ const client = new MisoClient({
179
+ controllerUrl: 'https://controller.aifabrix.ai',
180
+ environment: 'dev',
181
+ applicationKey: 'my-app',
182
+ applicationId: 'my-app-id-123',
183
+ redis: { host: 'localhost', port: 6379 }, // Add Redis
184
+ });
185
+
186
+ await client.initialize();
187
+
188
+ const token = req.headers.authorization?.replace('Bearer ', '');
189
+
190
+ // Check if user has role
191
+ const isAdmin = await client.hasRole(token, 'admin');
192
+ const roles = await client.getRoles(token);
193
+
194
+ // Gate features by role
195
+ if (isAdmin) {
196
+ // Show admin panel
197
+ }
198
+ ```
199
+
200
+ **Pro tip:** Without Redis, checks go to the controller. Add Redis to cache role lookups (15-minute default TTL).
201
+
202
+ → [Complete RBAC example](examples/step-4-rbac.ts)
203
+ → [RBAC Configuration](https://github.com/esystemsdev/aifabrix-builder/blob/main/docs/QUICK-START.md#step-3-create-your-app)
204
+
205
+ ---
206
+
207
+ ### Step 5: Activate Logging
208
+
209
+ **What happens:** Application logs are sent to the Miso Controller with API key authentication.
210
+
211
+ ```typescript
212
+ // Add API key for logging
213
+ const client = new MisoClient({
214
+ controllerUrl: 'https://controller.aifabrix.ai',
215
+ environment: 'dev',
216
+ applicationKey: 'my-app',
217
+ applicationId: 'my-app-id-123',
218
+ apiKey: 'dev-my-app-my-app-id-123-a1b2c3d4e5f6', // NEW: API key
219
+ redis: { host: 'localhost', port: 6379 },
220
+ });
221
+
222
+ await client.initialize();
223
+
224
+ const token = req.headers.authorization?.replace('Bearer ', '');
225
+ const user = await client.getUser(token);
226
+
227
+ // Log messages
228
+ await client.log.info('User accessed dashboard', { userId: user?.id });
229
+ await client.log.error('Operation failed', { error: err.message });
230
+ await client.log.warn('Unusual activity', { details: '...' });
231
+ ```
232
+
233
+ **API key format:** `{environment}-{applicationKey}-{applicationId}-{randomString}`
234
+
235
+ **What happens to logs?** They're sent to the Miso Controller for centralized monitoring and analysis.
236
+
237
+ → [Complete logging example](examples/step-5-logging.ts)
238
+ → [Logging Reference](docs/api-reference.md#logger-service)
239
+
240
+ ---
241
+
242
+ ### Step 6: Activate Audit
243
+
244
+ **What happens:** Create audit trails for compliance and security monitoring.
245
+
246
+ ```typescript
247
+ // Complete configuration
248
+ const client = new MisoClient({
249
+ controllerUrl: 'https://controller.aifabrix.ai',
250
+ environment: 'dev',
251
+ applicationKey: 'my-app',
252
+ applicationId: 'my-app-id-123',
253
+ apiKey: 'dev-my-app-my-app-id-123-a1b2c3d4e5f6',
254
+ redis: { host: 'localhost', port: 6379, password: 'optional' },
255
+ logLevel: 'info',
256
+ cache: { roleTTL: 900, permissionTTL: 900 },
257
+ });
258
+
259
+ await client.initialize();
260
+
261
+ const token = req.headers.authorization?.replace('Bearer ', '');
262
+ const isValid = await client.validateToken(token);
263
+ const canEdit = await client.hasPermission(token, 'edit:content');
264
+
265
+ // Audit: User actions
266
+ await client.log.audit('user.login', 'authentication', {
267
+ userId: user?.id,
268
+ ip: req.ip,
269
+ userAgent: req.headers['user-agent'],
270
+ });
271
+
272
+ // Audit: Content changes
273
+ await client.log.audit('post.created', 'content', {
274
+ userId: user?.id,
275
+ postId: 'post-123',
276
+ postTitle: req.body.title,
277
+ });
278
+
279
+ // Audit: Permission checks
280
+ await client.log.audit('access.denied', 'authorization', {
281
+ userId: user?.id,
282
+ requiredPermission: 'edit:content',
283
+ resource: 'posts',
284
+ });
285
+ ```
286
+
287
+ **What to audit:** Login/logout, permission checks, content creation/deletion, role changes, sensitive operations.
288
+
289
+ → [Complete audit example](examples/step-6-audit.ts)
290
+ → [Best Practices](docs/getting-started.md#common-patterns)
291
+
292
+ ---
293
+
294
+ ## 🔧 Configuration
295
+
296
+ ```typescript
297
+ interface MisoClientConfig {
298
+ controllerUrl: string; // Required: Controller URL
299
+ environment: 'dev' | 'tst' | 'pro'; // Required: Environment
300
+ applicationKey: string; // Required: App identifier
301
+ applicationId: string; // Required: App GUID
302
+ apiKey?: string; // Optional: For logging
303
+ redis?: RedisConfig; // Optional: For caching
304
+ logLevel?: 'debug' | 'info' | 'warn' | 'error';
305
+ cache?: {
306
+ roleTTL?: number; // Role cache TTL (default: 900s)
307
+ permissionTTL?: number; // Permission cache TTL (default: 900s)
308
+ };
309
+ }
310
+ ```
311
+
312
+ → [Complete Configuration Reference](docs/configuration.md)
313
+
314
+ ---
315
+
316
+ ## 📚 Documentation
317
+
318
+ - **[Getting Started](docs/getting-started.md)** - Detailed setup guide
319
+ - **[API Reference](docs/api-reference.md)** - Complete API documentation
320
+ - **[Configuration](docs/configuration.md)** - Configuration options
321
+ - **[Examples](docs/examples.md)** - Framework-specific examples
322
+ - **[Troubleshooting](docs/troubleshooting.md)** - Common issues and solutions
323
+
324
+ ---
325
+
326
+ ## 🏗️ Architecture
327
+
328
+ The SDK consists of five core services:
329
+
330
+ - **AuthService** - Token validation and user authentication
331
+ - **RoleService** - Role management with Redis caching
332
+ - **PermissionService** - Fine-grained permissions
333
+ - **LoggerService** - Centralized logging with API key authentication
334
+ - **RedisService** - Caching and queue management (optional)
335
+
336
+ → [Architecture Details](docs/api-reference.md#architecture)
337
+
338
+ ---
339
+
340
+ ## 🌐 Environments
341
+
342
+ The SDK supports three environments:
343
+
344
+ - **`dev`** - Development environment
345
+ - **`tst`** - Test environment
346
+ - **`pro`** - Production environment
347
+
348
+ Each environment uses different controller endpoints and API keys.
349
+
350
+ ---
351
+
352
+ ## 💡 Next Steps
353
+
354
+ ### Learn More
355
+ - [Express.js Middleware](docs/examples.md#expressjs-middleware) - Protect API routes
356
+ - [React Authentication](docs/examples.md#react-authentication) - Frontend auth
357
+ - [NestJS Guards](docs/examples.md#nestjs-guards) - Decorator-based auth
358
+ - [Error Handling](docs/examples.md#error-handling) - Best practices
359
+
360
+ ### Common Tasks
361
+
362
+ **Add authentication middleware:**
363
+ ```typescript
364
+ app.use(async (req, res, next) => {
365
+ const token = req.headers.authorization?.replace('Bearer ', '');
366
+ const isValid = await client.validateToken(token);
367
+ if (isValid) {
368
+ req.user = await client.getUser(token);
369
+ }
370
+ next();
371
+ });
372
+ ```
373
+
374
+ **Protect routes by role:**
375
+ ```typescript
376
+ app.get('/admin', async (req, res) => {
377
+ const token = req.headers.authorization?.replace('Bearer ', '');
378
+ const isAdmin = await client.hasRole(token, 'admin');
379
+ if (!isAdmin) return res.status(403).json({ error: 'Forbidden' });
380
+ // Admin only code
381
+ });
382
+ ```
383
+
384
+ **Use environment variables:**
385
+ ```bash
386
+ MISO_CONTROLLER_URL=https://controller.aifabrix.ai
387
+ MISO_ENVIRONMENT=dev
388
+ MISO_APPLICATION_KEY=my-app
389
+ MISO_APPLICATION_ID=my-app-id-123
390
+ MISO_API_KEY=dev-my-app-my-app-id-123-a1b2c3d4e5f6
391
+ REDIS_HOST=localhost
392
+ REDIS_PORT=6379
393
+ ```
394
+
395
+ ---
396
+
397
+ ## 🐛 Troubleshooting
398
+
399
+ **"Cannot connect to controller"**
400
+ → Verify `controllerUrl` is correct and accessible
401
+ → Check network connectivity
402
+
403
+ **"Redis connection failed"**
404
+ → SDK falls back to controller-only mode (slower but works)
405
+ → Fix: `aifabrix up` to start Redis
406
+
407
+ **"Invalid API key for logging"**
408
+ → Check API key format: `{environment}-{applicationKey}-{applicationId}-{randomString}`
409
+ → Verify key is configured in controller
410
+
411
+ **"Token validation fails"**
412
+ → Ensure Keycloak is running and configured correctly
413
+ → Verify token is from correct Keycloak instance
414
+
415
+ → [More Help](docs/troubleshooting.md)
416
+
417
+ ---
418
+
419
+ ## 📦 Installation
420
+
421
+ ```bash
422
+ # NPM
423
+ npm install @aifabrix/miso-client
424
+
425
+ # Yarn
426
+ yarn add @aifabrix/miso-client
427
+
428
+ # PNPM
429
+ pnpm add @aifabrix/miso-client
430
+ ```
431
+
432
+ ---
433
+
434
+ ## 🔗 Links
435
+
436
+ - **GitHub Repository**: [https://github.com/esystemsdev/aifabrix-miso-client](https://github.com/esystemsdev/aifabrix-miso-client)
437
+ - **Builder Documentation**: [https://github.com/esystemsdev/aifabrix-builder](https://github.com/esystemsdev/aifabrix-builder)
438
+ - **Issues**: [https://github.com/esystemsdev/aifabrix-miso-client/issues](https://github.com/esystemsdev/aifabrix-miso-client/issues)
439
+
440
+ ---
441
+
442
+ ## 📄 License
443
+
444
+ This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
445
+
446
+ ---
447
+
448
+ **Made with ❤️ by eSystems Nordic Ltd.**
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Step 3: Activate Authentication
3
+ *
4
+ * Basic token validation to verify user identity.
5
+ */
6
+ declare function authenticationExample(): Promise<void>;
7
+ export { authenticationExample };
8
+ //# sourceMappingURL=step-3-authentication.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"step-3-authentication.d.ts","sourceRoot":"","sources":["../../examples/step-3-authentication.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,iBAAe,qBAAqB,kBAoCnC;AAED,OAAO,EAAE,qBAAqB,EAAE,CAAC"}