@aifabrix/miso-client 1.0.1 → 1.0.3

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 (55) hide show
  1. package/README.md +393 -82
  2. package/dist/examples/env-config-example.d.ts +2 -0
  3. package/dist/examples/env-config-example.d.ts.map +1 -0
  4. package/dist/examples/env-config-example.js +31 -0
  5. package/dist/examples/env-config-example.js.map +1 -0
  6. package/dist/examples/manual-config-example.d.ts +2 -0
  7. package/dist/examples/manual-config-example.d.ts.map +1 -0
  8. package/dist/examples/manual-config-example.js +34 -0
  9. package/dist/examples/manual-config-example.js.map +1 -0
  10. package/dist/examples/step-3-authentication.d.ts +8 -0
  11. package/dist/examples/step-3-authentication.d.ts.map +1 -0
  12. package/dist/examples/step-3-authentication.js +41 -0
  13. package/dist/examples/step-3-authentication.js.map +1 -0
  14. package/dist/examples/step-4-rbac.d.ts +8 -0
  15. package/dist/examples/step-4-rbac.d.ts.map +1 -0
  16. package/dist/examples/step-4-rbac.js +46 -0
  17. package/dist/examples/step-4-rbac.js.map +1 -0
  18. package/dist/examples/step-5-logging.d.ts +8 -0
  19. package/dist/examples/step-5-logging.d.ts.map +1 -0
  20. package/dist/examples/step-5-logging.js +57 -0
  21. package/dist/examples/step-5-logging.js.map +1 -0
  22. package/dist/examples/step-6-audit.d.ts +8 -0
  23. package/dist/examples/step-6-audit.d.ts.map +1 -0
  24. package/dist/examples/step-6-audit.js +83 -0
  25. package/dist/examples/step-6-audit.js.map +1 -0
  26. package/dist/src/index.d.ts +19 -0
  27. package/dist/src/index.d.ts.map +1 -1
  28. package/dist/src/index.js +37 -6
  29. package/dist/src/index.js.map +1 -1
  30. package/dist/src/services/auth.service.d.ts +12 -2
  31. package/dist/src/services/auth.service.d.ts.map +1 -1
  32. package/dist/src/services/auth.service.js +84 -17
  33. package/dist/src/services/auth.service.js.map +1 -1
  34. package/dist/src/services/logger.service.d.ts +2 -2
  35. package/dist/src/services/logger.service.d.ts.map +1 -1
  36. package/dist/src/services/logger.service.js +18 -15
  37. package/dist/src/services/logger.service.js.map +1 -1
  38. package/dist/src/services/permission.service.d.ts +7 -2
  39. package/dist/src/services/permission.service.d.ts.map +1 -1
  40. package/dist/src/services/permission.service.js +49 -23
  41. package/dist/src/services/permission.service.js.map +1 -1
  42. package/dist/src/services/role.service.d.ts +7 -2
  43. package/dist/src/services/role.service.d.ts.map +1 -1
  44. package/dist/src/services/role.service.js +47 -21
  45. package/dist/src/services/role.service.js.map +1 -1
  46. package/dist/src/types/config.types.d.ts +8 -4
  47. package/dist/src/types/config.types.d.ts.map +1 -1
  48. package/dist/src/utils/config-loader.d.ts.map +1 -1
  49. package/dist/src/utils/config-loader.js +11 -6
  50. package/dist/src/utils/config-loader.js.map +1 -1
  51. package/dist/src/utils/http-client.d.ts +16 -2
  52. package/dist/src/utils/http-client.d.ts.map +1 -1
  53. package/dist/src/utils/http-client.js +90 -9
  54. package/dist/src/utils/http-client.js.map +1 -1
  55. package/package.json +2 -1
package/README.md CHANGED
@@ -3,145 +3,456 @@
3
3
  [![npm version](https://badge.fury.io/js/%40aifabrix%2Fmiso-client.svg)](https://badge.fury.io/js/%40aifabrix%2Fmiso-client)
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
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.
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
7
89
 
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
90
+ ---
18
91
 
19
- ## 📚 Documentation
92
+ ## 🚀 Quick Start
20
93
 
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
94
+ Get your application secured in 30 seconds.
26
95
 
27
- ## 🏃‍♂️ Quick Start
96
+ ### Step 1: Install
28
97
 
29
98
  ```bash
30
99
  npm install @aifabrix/miso-client
31
100
  ```
32
101
 
102
+ ### Step 2: Create `.env`
103
+
104
+ ```bash
105
+ MISO_CLIENTID=ctrl-dev-my-app
106
+ MISO_CLIENTSECRET=your-secret
107
+ MISO_CONTROLLER_URL=http://localhost:3000
108
+ REDIS_HOST=localhost
109
+ ```
110
+
111
+ ### Step 3: Use It
112
+
113
+ ```typescript
114
+ import { MisoClient, loadConfig } from '@aifabrix/miso-client';
115
+
116
+ const client = new MisoClient(loadConfig());
117
+ await client.initialize();
118
+
119
+ const isValid = await client.auth.validateToken(token);
120
+ ```
121
+
122
+ **That's it!** You now have authentication, roles, and logging.
123
+
124
+ → [Full Getting Started Guide](docs/getting-started.md)
125
+
126
+ ---
127
+
128
+ ### Infrastructure Setup
129
+
130
+ **First time?** You'll need Keycloak and Miso Controller running.
131
+
132
+ Use the [AI Fabrix Builder](https://github.com/esystemsdev/aifabrix-builder/blob/main/docs/QUICK-START.md):
133
+
134
+ ```bash
135
+ # Start infrastructure (Postgres, Redis)
136
+ aifabrix up
137
+
138
+ # Install Keycloak for authentication
139
+ aifabrix create keycloak --port 8082 --database --template platform
140
+ aifabrix build keycloak
141
+ aifabrix run keycloak
142
+
143
+ # Install Miso Controller
144
+ aifabrix create miso-controller --port 3000 --database --redis --template platform
145
+ aifabrix build miso-controller
146
+ aifabrix run miso-controller
147
+ ```
148
+
149
+ → [Infrastructure Guide](https://github.com/esystemsdev/aifabrix-builder/blob/main/docs/INFRASTRUCTURE.md)
150
+
151
+ **Already have Keycloak and Controller?** Use the Quick Start above.
152
+
153
+ ---
154
+
155
+ ## 📚 Documentation
156
+
157
+ **What happens:** Your app validates user tokens from Keycloak.
158
+
33
159
  ```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'
160
+ import { MisoClient, loadConfig } from '@aifabrix/miso-client';
161
+
162
+ // Create client (loads from .env automatically)
163
+ const client = new MisoClient(loadConfig());
164
+ await client.initialize();
165
+
166
+ // Get token from request (helper method)
167
+ const token = client.getToken(req);
168
+
169
+ if (token) {
170
+ const isValid = await client.validateToken(token);
171
+ if (isValid) {
172
+ const user = await client.getUser(token);
173
+ console.log('User:', user);
46
174
  }
47
- });
175
+ }
176
+ ```
177
+
178
+ **Where to get tokens?** Users authenticate via Keycloak, then your app receives JWTs in the `Authorization` header.
179
+
180
+ → [Complete authentication example](examples/step-3-authentication.ts)
181
+
182
+ ---
183
+
184
+ ### Step 4: Activate RBAC (Roles)
48
185
 
186
+ **What happens:** Check user roles to control access. Roles are cached in Redis for performance.
187
+
188
+ ```typescript
189
+ import { MisoClient, loadConfig } from '@aifabrix/miso-client';
190
+
191
+ // Build on Step 3 - add Redis in .env file
192
+ const client = new MisoClient(loadConfig());
49
193
  await client.initialize();
50
194
 
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);
195
+ const token = client.getToken(req);
56
196
 
57
- // Check permissions
58
- const canEdit = await client.hasPermission(userToken, 'edit:content');
197
+ // Check if user has role
198
+ const isAdmin = await client.hasRole(token, 'admin');
199
+ const roles = await client.getRoles(token);
59
200
 
60
- // Log events (now with API key authentication)
61
- client.log.audit('user.login', 'authentication', { userId: user.id });
201
+ // Gate features by role
202
+ if (isAdmin) {
203
+ // Show admin panel
62
204
  }
63
205
  ```
64
206
 
65
- ## 🏗️ Architecture
207
+ **Pro tip:** Without Redis, checks go to the controller. Add Redis to cache role lookups (15-minute default TTL).
66
208
 
67
- The Miso Client SDK consists of several core services:
209
+ [Complete RBAC example](examples/step-4-rbac.ts)
210
+ → [AI Fabrix Builder Quick Start](https://github.com/esystemsdev/aifabrix-builder/blob/main/docs/QUICK-START.md)
68
211
 
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
212
+ ---
74
213
 
75
- ## 🔧 Configuration
214
+ ### Step 5: Activate Logging
76
215
 
77
- The SDK supports flexible configuration options:
216
+ **What happens:** Application logs are sent to the Miso Controller with client token authentication.
217
+
218
+ ```typescript
219
+ import { MisoClient, loadConfig } from '@aifabrix/miso-client';
220
+
221
+ // Client token is automatically managed - no API key needed
222
+ const client = new MisoClient(loadConfig());
223
+ await client.initialize();
224
+
225
+ const token = client.getToken(req);
226
+ const user = await client.getUser(token);
227
+
228
+ // Log messages
229
+ await client.log.info('User accessed dashboard', { userId: user?.id });
230
+ await client.log.error('Operation failed', { error: err.message });
231
+ await client.log.warn('Unusual activity', { details: '...' });
232
+ ```
233
+
234
+ **What happens to logs?** They're sent to the Miso Controller for centralized monitoring and analysis. Client token is automatically included.
235
+
236
+ → [Complete logging example](examples/step-5-logging.ts)
237
+ → [Logging Reference](docs/api-reference.md#logger-service)
238
+
239
+ ---
240
+
241
+ ### Step 6: Activate Audit
242
+
243
+ **What happens:** Create audit trails for compliance and security monitoring.
244
+
245
+ ```typescript
246
+ import { MisoClient, loadConfig } from '@aifabrix/miso-client';
247
+
248
+ // Complete configuration (all in .env)
249
+ const client = new MisoClient(loadConfig());
250
+ await client.initialize();
251
+
252
+ const token = client.getToken(req);
253
+ const isValid = await client.validateToken(token);
254
+ const canEdit = await client.hasPermission(token, 'edit:content');
255
+ const user = await client.getUser(token);
256
+
257
+ // Audit: User actions
258
+ await client.log.audit('user.login', 'authentication', {
259
+ userId: user?.id,
260
+ ip: req.ip,
261
+ userAgent: req.headers['user-agent'],
262
+ });
263
+
264
+ // Audit: Content changes
265
+ await client.log.audit('post.created', 'content', {
266
+ userId: user?.id,
267
+ postId: 'post-123',
268
+ postTitle: req.body.title,
269
+ });
270
+
271
+ // Audit: Permission checks
272
+ await client.log.audit('access.denied', 'authorization', {
273
+ userId: user?.id,
274
+ requiredPermission: 'edit:content',
275
+ resource: 'posts',
276
+ });
277
+ ```
278
+
279
+ **What to audit:** Login/logout, permission checks, content creation/deletion, role changes, sensitive operations.
280
+
281
+ → [Complete audit example](examples/step-6-audit.ts)
282
+ → [Best Practices](docs/getting-started.md#common-patterns)
283
+
284
+ ---
285
+
286
+ ## 🔧 Configuration
78
287
 
79
288
  ```typescript
80
289
  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
290
+ controllerUrl: string; // Required: Controller URL
291
+ clientId: string; // Required: Client ID (e.g., 'ctrl-dev-my-app')
292
+ clientSecret: string; // Required: Client secret
293
+ redis?: RedisConfig; // Optional: For caching
87
294
  logLevel?: 'debug' | 'info' | 'warn' | 'error';
88
295
  cache?: {
89
- roleTTL?: number; // Role cache TTL (default: 15 minutes)
90
- permissionTTL?: number; // Permission cache TTL (default: 15 minutes)
296
+ roleTTL?: number; // Role cache TTL (default: 900s)
297
+ permissionTTL?: number; // Permission cache TTL (default: 900s)
91
298
  };
92
299
  }
93
300
  ```
94
301
 
95
- ## 🌐 Environments
302
+ **Recommended:** Use `loadConfig()` to load from `.env` file automatically.
96
303
 
97
- The SDK supports three environments:
304
+ [Complete Configuration Reference](docs/configuration.md)
98
305
 
99
- - **`dev`** - Development environment
100
- - **`tst`** - Test environment
101
- - **`pro`** - Production environment
306
+ ---
102
307
 
103
- ## 📦 Installation
308
+ ## 📚 Documentation
104
309
 
105
- ### NPM
310
+ - **[Getting Started](docs/getting-started.md)** - Detailed setup guide
311
+ - **[API Reference](docs/api-reference.md)** - Complete API documentation
312
+ - **[Configuration](docs/configuration.md)** - Configuration options
313
+ - **[Examples](docs/examples.md)** - Framework-specific examples
314
+ - **[Troubleshooting](docs/troubleshooting.md)** - Common issues and solutions
106
315
 
107
- ```bash
108
- npm install @aifabrix/miso-client
316
+ ---
317
+
318
+ ## 🏗️ Architecture
319
+
320
+ The SDK consists of five core services:
321
+
322
+ - **AuthService** - Token validation and user authentication
323
+ - **RoleService** - Role management with Redis caching
324
+ - **PermissionService** - Fine-grained permissions
325
+ - **LoggerService** - Centralized logging with API key authentication
326
+ - **RedisService** - Caching and queue management (optional)
327
+
328
+ → [Architecture Details](docs/api-reference.md#architecture)
329
+
330
+ ---
331
+
332
+ ## 🌐 Setup Your Application
333
+
334
+ **First time setup?** Use the AI Fabrix Builder:
335
+
336
+ 1. **Create your app:**
337
+ ```bash
338
+ aifabrix create myapp --port 3000 --database --language typescript
339
+ ```
340
+
341
+ 2. **Login to controller:**
342
+ ```bash
343
+ aifabrix login
344
+ ```
345
+
346
+ 3. **Register your application:**
347
+ ```bash
348
+ aifabrix app register myapp --environment dev
349
+ ```
350
+
351
+ 4. **Start development** and then deploy to Docker or Azure.
352
+
353
+ → [Full Quick Start Guide](https://github.com/esystemsdev/aifabrix-builder/blob/main/docs/QUICK-START.md)
354
+
355
+ ---
356
+
357
+ ## 💡 Next Steps
358
+
359
+ ### Learn More
360
+ - [Express.js Middleware](docs/examples.md#expressjs-middleware) - Protect API routes
361
+ - [React Authentication](docs/examples.md#react-authentication) - Frontend auth
362
+ - [NestJS Guards](docs/examples.md#nestjs-guards) - Decorator-based auth
363
+ - [Error Handling](docs/examples.md#error-handling) - Best practices
364
+
365
+ ### Common Tasks
366
+
367
+ **Add authentication middleware:**
368
+ ```typescript
369
+ app.use(async (req, res, next) => {
370
+ const token = client.getToken(req);
371
+ if (token) {
372
+ const isValid = await client.validateToken(token);
373
+ if (isValid) {
374
+ req.user = await client.getUser(token);
375
+ }
376
+ }
377
+ next();
378
+ });
109
379
  ```
110
380
 
111
- ### Yarn
381
+ **Protect routes by role:**
382
+ ```typescript
383
+ app.get('/admin', async (req, res) => {
384
+ const token = client.getToken(req);
385
+ if (!token) return res.status(401).json({ error: 'Unauthorized' });
386
+
387
+ const isAdmin = await client.hasRole(token, 'admin');
388
+ if (!isAdmin) return res.status(403).json({ error: 'Forbidden' });
389
+
390
+ // Admin only code
391
+ res.json({ message: 'Admin panel' });
392
+ });
393
+ ```
112
394
 
395
+ **Use environment variables:**
113
396
  ```bash
114
- yarn add @aifabrix/miso-client
397
+ MISO_CLIENTID=ctrl-dev-my-app
398
+ MISO_CLIENTSECRET=your-secret
399
+ MISO_CONTROLLER_URL=http://localhost:3000
400
+ REDIS_HOST=localhost
401
+ REDIS_PORT=6379
402
+ MISO_LOG_LEVEL=info
115
403
  ```
116
404
 
117
- ### PNPM
405
+ ---
406
+
407
+ ## 🐛 Troubleshooting
408
+
409
+ **"Cannot connect to controller"**
410
+ → Verify `controllerUrl` is correct and accessible
411
+ → Check network connectivity
412
+
413
+ **"Redis connection failed"**
414
+ → SDK falls back to controller-only mode (slower but works)
415
+ → Fix: `aifabrix up` to start Redis
416
+
417
+ **"Client token fetch failed"**
418
+ → Check `MISO_CLIENTID` and `MISO_CLIENTSECRET` are correct
419
+ → Verify credentials are configured in controller
420
+
421
+ **"Token validation fails"**
422
+ → Ensure Keycloak is running and configured correctly
423
+ → Verify token is from correct Keycloak instance
424
+
425
+ → [More Help](docs/troubleshooting.md)
426
+
427
+ ---
428
+
429
+ ## 📦 Installation
118
430
 
119
431
  ```bash
432
+ # NPM
433
+ npm install @aifabrix/miso-client
434
+
435
+ # Yarn
436
+ yarn add @aifabrix/miso-client
437
+
438
+ # PNPM
120
439
  pnpm add @aifabrix/miso-client
121
440
  ```
122
441
 
442
+ ---
443
+
123
444
  ## 🔗 Links
124
445
 
125
446
  - **GitHub Repository**: [https://github.com/esystemsdev/aifabrix-miso-client](https://github.com/esystemsdev/aifabrix-miso-client)
126
- - **Documentation**: [https://github.com/esystemsdev/aifabrix-miso-client](https://github.com/esystemsdev/aifabrix-miso-client)
447
+ - **Builder Documentation**: [https://github.com/esystemsdev/aifabrix-builder](https://github.com/esystemsdev/aifabrix-builder)
127
448
  - **Issues**: [https://github.com/esystemsdev/aifabrix-miso-client/issues](https://github.com/esystemsdev/aifabrix-miso-client/issues)
128
449
 
450
+ ---
451
+
129
452
  ## 📄 License
130
453
 
131
454
  This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
132
455
 
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@esystemsnordic.com>
142
- - **Documentation**: [https://github.com/esystemsdev/aifabrix-miso-client](https://github.com/esystemsdev/aifabrix-miso-client)
143
- - **GitHub Issues**: [https://github.com/esystemsdev/aifabrix-miso-client/issues](https://github.com/esystemsdev/aifabrix-miso-client/issues)
144
-
145
456
  ---
146
457
 
147
458
  **Made with ❤️ by eSystems Nordic Ltd.**
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=env-config-example.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env-config-example.d.ts","sourceRoot":"","sources":["../../examples/env-config-example.ts"],"names":[],"mappings":""}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Example: Configuration from .env
5
+ * Shows how to use loadConfig() for automatic .env loading
6
+ */
7
+ const index_1 = require("../src/index");
8
+ async function envConfigExample() {
9
+ // Auto-load from .env file - that's it!
10
+ const client = new index_1.MisoClient((0, index_1.loadConfig)());
11
+ try {
12
+ await client.initialize();
13
+ console.log('✅ Client initialized from .env');
14
+ const token = 'your-jwt-token';
15
+ const isValid = await client.validateToken(token);
16
+ if (isValid) {
17
+ const user = await client.getUser(token);
18
+ const roles = await client.getRoles(token);
19
+ console.log('👤 User:', user);
20
+ console.log('🔑 Roles:', roles);
21
+ await client.log.info('User accessed app', {
22
+ userId: user?.id,
23
+ });
24
+ }
25
+ }
26
+ finally {
27
+ await client.disconnect();
28
+ }
29
+ }
30
+ envConfigExample().catch(console.error);
31
+ //# sourceMappingURL=env-config-example.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env-config-example.js","sourceRoot":"","sources":["../../examples/env-config-example.ts"],"names":[],"mappings":";;AAAA;;;GAGG;AACH,wCAAsD;AAEtD,KAAK,UAAU,gBAAgB;IAC7B,wCAAwC;IACxC,MAAM,MAAM,GAAG,IAAI,kBAAU,CAAC,IAAA,kBAAU,GAAE,CAAC,CAAC;IAE5C,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC;QAC1B,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;QAE9C,MAAM,KAAK,GAAG,gBAAgB,CAAC;QAC/B,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAElD,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACzC,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAC3C,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;YAC9B,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;YAEhC,MAAM,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,EAAE;gBACzC,MAAM,EAAE,IAAI,EAAE,EAAE;aACjB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC;IAC5B,CAAC;AACH,CAAC;AAED,gBAAgB,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=manual-config-example.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manual-config-example.d.ts","sourceRoot":"","sources":["../../examples/manual-config-example.ts"],"names":[],"mappings":""}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Example: Manual Configuration
5
+ * Shows how to configure client with explicit parameters
6
+ */
7
+ const index_1 = require("../src/index");
8
+ async function manualConfigExample() {
9
+ const client = new index_1.MisoClient({
10
+ controllerUrl: 'http://localhost:3000',
11
+ clientId: 'ctrl-dev-my-app',
12
+ clientSecret: 'your-secret-here',
13
+ redis: {
14
+ host: 'localhost',
15
+ port: 6379,
16
+ },
17
+ logLevel: 'info',
18
+ });
19
+ try {
20
+ await client.initialize();
21
+ console.log('✅ Client initialized');
22
+ const token = 'your-jwt-token';
23
+ const isValid = await client.validateToken(token);
24
+ if (isValid) {
25
+ const user = await client.getUser(token);
26
+ console.log('👤 User:', user);
27
+ }
28
+ }
29
+ finally {
30
+ await client.disconnect();
31
+ }
32
+ }
33
+ manualConfigExample().catch(console.error);
34
+ //# sourceMappingURL=manual-config-example.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manual-config-example.js","sourceRoot":"","sources":["../../examples/manual-config-example.ts"],"names":[],"mappings":";;AAAA;;;GAGG;AACH,wCAA0C;AAE1C,KAAK,UAAU,mBAAmB;IAChC,MAAM,MAAM,GAAG,IAAI,kBAAU,CAAC;QAC5B,aAAa,EAAE,uBAAuB;QACtC,QAAQ,EAAE,iBAAiB;QAC3B,YAAY,EAAE,kBAAkB;QAChC,KAAK,EAAE;YACL,IAAI,EAAE,WAAW;YACjB,IAAI,EAAE,IAAI;SACX;QACD,QAAQ,EAAE,MAAM;KACjB,CAAC,CAAC;IAEH,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC;QAC1B,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;QAEpC,MAAM,KAAK,GAAG,gBAAgB,CAAC;QAC/B,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAElD,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACzC,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC;IAC5B,CAAC;AACH,CAAC;AAED,mBAAmB,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
@@ -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,kBAgCnC;AAED,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ /**
3
+ * Step 3: Activate Authentication
4
+ *
5
+ * Basic token validation to verify user identity.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.authenticationExample = authenticationExample;
9
+ const index_1 = require("../src/index");
10
+ async function authenticationExample() {
11
+ // Create client - loads from .env automatically
12
+ // Or manually: new MisoClient({ controllerUrl, clientId, clientSecret })
13
+ const client = new index_1.MisoClient((0, index_1.loadConfig)());
14
+ try {
15
+ // Initialize the client
16
+ await client.initialize();
17
+ console.log('✅ Client initialized successfully');
18
+ // Get token from your application (e.g., from HTTP request header)
19
+ // In real usage: const token = client.getToken(req);
20
+ const token = 'your-jwt-token-here';
21
+ // Validate the token
22
+ const isValid = await client.validateToken(token);
23
+ if (isValid) {
24
+ console.log('✅ Token is valid');
25
+ // Get user information
26
+ const user = await client.getUser(token);
27
+ console.log('👤 User:', user);
28
+ }
29
+ else {
30
+ console.log('❌ Token is invalid');
31
+ }
32
+ }
33
+ catch (error) {
34
+ console.error('❌ Authentication error:', error);
35
+ }
36
+ finally {
37
+ // Clean up connections
38
+ await client.disconnect();
39
+ }
40
+ }
41
+ //# sourceMappingURL=step-3-authentication.js.map