@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.
- package/LICENSE +21 -21
- package/README.md +448 -147
- package/dist/examples/step-3-authentication.d.ts +8 -0
- package/dist/examples/step-3-authentication.d.ts.map +1 -0
- package/dist/examples/step-3-authentication.js +45 -0
- package/dist/examples/step-3-authentication.js.map +1 -0
- package/dist/examples/step-4-rbac.d.ts +8 -0
- package/dist/examples/step-4-rbac.d.ts.map +1 -0
- package/dist/examples/step-4-rbac.js +54 -0
- package/dist/examples/step-4-rbac.js.map +1 -0
- package/dist/examples/step-5-logging.d.ts +8 -0
- package/dist/examples/step-5-logging.d.ts.map +1 -0
- package/dist/examples/step-5-logging.js +66 -0
- package/dist/examples/step-5-logging.js.map +1 -0
- package/dist/examples/step-6-audit.d.ts +8 -0
- package/dist/examples/step-6-audit.d.ts.map +1 -0
- package/dist/examples/step-6-audit.js +97 -0
- package/dist/examples/step-6-audit.js.map +1 -0
- package/dist/examples/usage.d.ts +6 -0
- package/dist/examples/usage.d.ts.map +1 -0
- package/dist/examples/usage.js +65 -0
- package/dist/examples/usage.js.map +1 -0
- package/dist/{index.d.ts → src/index.d.ts} +1 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/{index.js → src/index.js} +4 -1
- package/dist/src/index.js.map +1 -0
- package/dist/src/services/auth.service.d.ts.map +1 -0
- package/dist/src/services/auth.service.js.map +1 -0
- package/dist/src/services/logger.service.d.ts.map +1 -0
- package/dist/{services → src/services}/logger.service.js +9 -7
- package/dist/{services → src/services}/logger.service.js.map +1 -1
- package/dist/src/services/permission.service.d.ts.map +1 -0
- package/dist/src/services/permission.service.js.map +1 -0
- package/dist/src/services/redis.service.d.ts.map +1 -0
- package/dist/src/services/redis.service.js.map +1 -0
- package/dist/src/services/role.service.d.ts.map +1 -0
- package/dist/src/services/role.service.js.map +1 -0
- package/dist/src/types/config.types.d.ts.map +1 -0
- package/dist/src/types/config.types.js.map +1 -0
- package/dist/src/utils/config-loader.d.ts +11 -0
- package/dist/src/utils/config-loader.d.ts.map +1 -0
- package/dist/src/utils/config-loader.js +39 -0
- package/dist/src/utils/config-loader.js.map +1 -0
- package/dist/src/utils/data-masker.d.ts.map +1 -0
- package/dist/src/utils/data-masker.js.map +1 -0
- package/dist/src/utils/http-client.d.ts.map +1 -0
- package/dist/src/utils/http-client.js.map +1 -0
- package/package.json +60 -60
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/services/auth.service.d.ts.map +0 -1
- package/dist/services/auth.service.js.map +0 -1
- package/dist/services/logger.service.d.ts.map +0 -1
- package/dist/services/permission.service.d.ts.map +0 -1
- package/dist/services/permission.service.js.map +0 -1
- package/dist/services/redis.service.d.ts.map +0 -1
- package/dist/services/redis.service.js.map +0 -1
- package/dist/services/role.service.d.ts.map +0 -1
- package/dist/services/role.service.js.map +0 -1
- package/dist/types/config.types.d.ts.map +0 -1
- package/dist/types/config.types.js.map +0 -1
- package/dist/utils/data-masker.d.ts.map +0 -1
- package/dist/utils/data-masker.js.map +0 -1
- package/dist/utils/http-client.d.ts.map +0 -1
- package/dist/utils/http-client.js.map +0 -1
- /package/dist/{services → src/services}/auth.service.d.ts +0 -0
- /package/dist/{services → src/services}/auth.service.js +0 -0
- /package/dist/{services → src/services}/logger.service.d.ts +0 -0
- /package/dist/{services → src/services}/permission.service.d.ts +0 -0
- /package/dist/{services → src/services}/permission.service.js +0 -0
- /package/dist/{services → src/services}/redis.service.d.ts +0 -0
- /package/dist/{services → src/services}/redis.service.js +0 -0
- /package/dist/{services → src/services}/role.service.d.ts +0 -0
- /package/dist/{services → src/services}/role.service.js +0 -0
- /package/dist/{types → src/types}/config.types.d.ts +0 -0
- /package/dist/{types → src/types}/config.types.js +0 -0
- /package/dist/{utils → src/utils}/data-masker.d.ts +0 -0
- /package/dist/{utils → src/utils}/data-masker.js +0 -0
- /package/dist/{utils → src/utils}/http-client.d.ts +0 -0
- /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
|
-
[](https://badge.fury.io/js/%40aifabrix%2Fmiso-client)
|
|
4
|
-
[](https://opensource.org/licenses/MIT)
|
|
5
|
-
|
|
6
|
-
The **AI Fabrix Miso Client SDK**
|
|
7
|
-
|
|
8
|
-
##
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
-
|
|
100
|
-
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
1
|
+
# AI Fabrix Miso Client SDK
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/%40aifabrix%2Fmiso-client)
|
|
4
|
+
[](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 @@
|
|
|
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"}
|