win-portal-auth-sdk 1.0.0
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 -0
- package/README.md +239 -0
- package/dist/client/api/auth.api.d.ts +34 -0
- package/dist/client/api/auth.api.d.ts.map +1 -0
- package/dist/client/api/auth.api.js +48 -0
- package/dist/client/api/event-log.api.d.ts +24 -0
- package/dist/client/api/event-log.api.d.ts.map +1 -0
- package/dist/client/api/event-log.api.js +29 -0
- package/dist/client/api/files.api.d.ts +59 -0
- package/dist/client/api/files.api.d.ts.map +1 -0
- package/dist/client/api/files.api.js +77 -0
- package/dist/client/api/health.api.d.ts +21 -0
- package/dist/client/api/health.api.d.ts.map +1 -0
- package/dist/client/api/health.api.js +35 -0
- package/dist/client/api/index.d.ts +11 -0
- package/dist/client/api/index.d.ts.map +1 -0
- package/dist/client/api/index.js +18 -0
- package/dist/client/api/system-config.api.d.ts +37 -0
- package/dist/client/api/system-config.api.d.ts.map +1 -0
- package/dist/client/api/system-config.api.js +45 -0
- package/dist/client/auth-client.d.ts +67 -0
- package/dist/client/auth-client.d.ts.map +1 -0
- package/dist/client/auth-client.js +133 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +8 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/types/auth.types.d.ts +76 -0
- package/dist/types/auth.types.d.ts.map +1 -0
- package/dist/types/auth.types.js +7 -0
- package/dist/types/event-log.interfaces.d.ts +108 -0
- package/dist/types/event-log.interfaces.d.ts.map +1 -0
- package/dist/types/event-log.interfaces.js +7 -0
- package/dist/types/event-log.types.d.ts +64 -0
- package/dist/types/event-log.types.d.ts.map +1 -0
- package/dist/types/event-log.types.js +66 -0
- package/dist/types/file.types.d.ts +75 -0
- package/dist/types/file.types.d.ts.map +1 -0
- package/dist/types/file.types.js +7 -0
- package/dist/types/index.d.ts +71 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +28 -0
- package/dist/types/system-config.types.d.ts +42 -0
- package/dist/types/system-config.types.d.ts.map +1 -0
- package/dist/types/system-config.types.js +7 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 MBS Business Solutions
|
|
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
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
# @win-portal/auth-sdk
|
|
2
|
+
|
|
3
|
+
Shared authentication SDK for Win Portal applications using API Key authentication.
|
|
4
|
+
|
|
5
|
+
> **Note:** The main Win Portal API already supports API Key authentication through `HybridAuthGuard`.
|
|
6
|
+
> This SDK provides convenient client libraries for external applications.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- 🔐 **API Key Authentication** - Secure authentication using application API keys
|
|
11
|
+
- 🎯 **Frontend Client** - HTTP client with automatic API key injection for Next.js/React
|
|
12
|
+
- 📦 **Lightweight** - Minimal dependencies
|
|
13
|
+
- 🔧 **TypeScript Support** - Full type definitions included
|
|
14
|
+
|
|
15
|
+
## How It Works
|
|
16
|
+
|
|
17
|
+
The Win Portal main API (`apps/api`) has built-in API key support:
|
|
18
|
+
|
|
19
|
+
- All endpoints with `@Auth()` decorator accept `X-API-Key` header
|
|
20
|
+
- Uses `HybridAuthGuard` which tries API Key → JWT → OAuth
|
|
21
|
+
- No additional validation endpoint needed
|
|
22
|
+
|
|
23
|
+
This SDK helps external apps (`template-web`, `template-api`) easily integrate with the main API.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# Using pnpm (recommended for monorepo)
|
|
29
|
+
pnpm add @win-portal/auth-sdk
|
|
30
|
+
|
|
31
|
+
# Using npm
|
|
32
|
+
npm install @win-portal/auth-sdk
|
|
33
|
+
|
|
34
|
+
# Using yarn
|
|
35
|
+
yarn add @win-portal/auth-sdk
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
### Frontend (Next.js / React)
|
|
41
|
+
|
|
42
|
+
#### 1. Setup Client
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { AuthClient } from '@win-portal/auth-sdk';
|
|
46
|
+
|
|
47
|
+
// Initialize the client
|
|
48
|
+
const authClient = new AuthClient({
|
|
49
|
+
apiKey: process.env.NEXT_PUBLIC_API_KEY!,
|
|
50
|
+
baseURL: process.env.NEXT_PUBLIC_API_URL,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export default authClient;
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
#### 2. Make Authenticated Requests
|
|
57
|
+
|
|
58
|
+
The SDK uses **namespaced methods** for better organization:
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import authClient from '@/lib/auth-client';
|
|
62
|
+
|
|
63
|
+
// Authentication
|
|
64
|
+
const loginResult = await authClient.auth.login('user@example.com', 'password');
|
|
65
|
+
const profile = await authClient.auth.profile();
|
|
66
|
+
const refreshed = await authClient.auth.refresh(refreshToken);
|
|
67
|
+
await authClient.auth.logout();
|
|
68
|
+
|
|
69
|
+
// User Management
|
|
70
|
+
const users = await authClient.user.search({
|
|
71
|
+
search: 'john',
|
|
72
|
+
page: 1,
|
|
73
|
+
page_size: 20,
|
|
74
|
+
});
|
|
75
|
+
const user = await authClient.user.get(userId);
|
|
76
|
+
const newUser = await authClient.user.create(userData);
|
|
77
|
+
const updated = await authClient.user.update(userId, userData);
|
|
78
|
+
await authClient.user.delete(userId);
|
|
79
|
+
|
|
80
|
+
// Health Check
|
|
81
|
+
const health = await authClient.health.check();
|
|
82
|
+
const isValid = await authClient.health.validateApiKey();
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**For custom endpoints, use direct HTTP methods:**
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
// GET request
|
|
89
|
+
const response = await authClient.get('/api/v1/custom/endpoint');
|
|
90
|
+
|
|
91
|
+
// POST request
|
|
92
|
+
const response = await authClient.post('/api/v1/custom/endpoint', data);
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
#### 3. Use with Next.js API Routes
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
// app/api/users/route.ts
|
|
99
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
100
|
+
import authClient from '@/lib/auth-client';
|
|
101
|
+
|
|
102
|
+
export async function GET(request: NextRequest) {
|
|
103
|
+
try {
|
|
104
|
+
const response = await authClient.post('/api/v1/users/search', {
|
|
105
|
+
page: 1,
|
|
106
|
+
page_size: 20,
|
|
107
|
+
});
|
|
108
|
+
return NextResponse.json(response.data);
|
|
109
|
+
} catch (error: any) {
|
|
110
|
+
return NextResponse.json(
|
|
111
|
+
{ error: error.response?.data?.message || 'Failed to fetch users' },
|
|
112
|
+
{ status: error.response?.status || 500 },
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
#### 4. Environment Variables
|
|
119
|
+
|
|
120
|
+
```env
|
|
121
|
+
# .env.local
|
|
122
|
+
NEXT_PUBLIC_API_KEY=app_your_api_key_here
|
|
123
|
+
NEXT_PUBLIC_API_URL=https://api.yourdomain.com
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Backend (NestJS - Optional)
|
|
127
|
+
|
|
128
|
+
For template-api that needs to call main API:
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
import { AuthClient } from '@win-portal/auth-sdk';
|
|
132
|
+
import { Injectable } from '@nestjs/common';
|
|
133
|
+
|
|
134
|
+
@Injectable()
|
|
135
|
+
export class ExternalApiService {
|
|
136
|
+
private authClient: AuthClient;
|
|
137
|
+
|
|
138
|
+
constructor() {
|
|
139
|
+
this.authClient = new AuthClient({
|
|
140
|
+
apiKey: process.env.MAIN_API_KEY!,
|
|
141
|
+
baseURL: process.env.MAIN_API_URL,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async fetchFromMainApi() {
|
|
146
|
+
const response = await this.authClient.get('/api/v1/resources');
|
|
147
|
+
return response.data;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## API Reference
|
|
153
|
+
|
|
154
|
+
### `AuthClient`
|
|
155
|
+
|
|
156
|
+
HTTP client with automatic API key injection.
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
const client = new AuthClient({
|
|
160
|
+
apiKey: string; // Required: Your API key
|
|
161
|
+
baseURL?: string; // Optional: Base URL for requests
|
|
162
|
+
apiKeyHeader?: string; // Optional: Custom header name (default: 'X-API-Key')
|
|
163
|
+
timeout?: number; // Optional: Request timeout (default: 30000ms)
|
|
164
|
+
})
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
#### HTTP Methods
|
|
168
|
+
|
|
169
|
+
- `get<T>(url, config?)` - GET request
|
|
170
|
+
- `post<T>(url, data?, config?)` - POST request
|
|
171
|
+
- `put<T>(url, data?, config?)` - PUT request
|
|
172
|
+
- `patch<T>(url, data?, config?)` - PATCH request
|
|
173
|
+
- `delete<T>(url, config?)` - DELETE request
|
|
174
|
+
|
|
175
|
+
#### Convenience Methods
|
|
176
|
+
|
|
177
|
+
**Authentication:**
|
|
178
|
+
|
|
179
|
+
- `auth.login(email, password)` - Login user
|
|
180
|
+
- `auth.logout()` - Logout current session
|
|
181
|
+
- `auth.profile()` - Get current user profile
|
|
182
|
+
- `auth.refresh(refreshToken)` - Refresh access token
|
|
183
|
+
|
|
184
|
+
**User Management:**
|
|
185
|
+
|
|
186
|
+
- `user.search(params?)` - Search users with pagination
|
|
187
|
+
- `user.get(userId)` - Get user by ID
|
|
188
|
+
- `user.create(userData)` - Create new user
|
|
189
|
+
- `user.update(userId, userData)` - Update user
|
|
190
|
+
- `user.delete(userId)` - Delete user
|
|
191
|
+
|
|
192
|
+
**Health & Validation:**
|
|
193
|
+
|
|
194
|
+
- `health.check()` - Check API health
|
|
195
|
+
- `health.validateApiKey()` - Validate if API key is still active
|
|
196
|
+
|
|
197
|
+
#### Utility Methods
|
|
198
|
+
|
|
199
|
+
- `setApiKey(apiKey)` - Update API key
|
|
200
|
+
- `getApiKeyMasked()` - Get masked API key for display
|
|
201
|
+
- `getAxiosInstance()` - Get underlying axios instance
|
|
202
|
+
|
|
203
|
+
## Security Best Practices
|
|
204
|
+
|
|
205
|
+
1. **Never commit API keys** - Use environment variables
|
|
206
|
+
2. **Rotate keys regularly** - Update API keys periodically through main API
|
|
207
|
+
3. **Use different keys per environment** - Separate keys for dev, staging, production
|
|
208
|
+
4. **Monitor key usage** - Track usage through main API dashboard
|
|
209
|
+
5. **Set expiration dates** - Configure key expiration in main API
|
|
210
|
+
6. **Whitelist IPs** - Configure IP restrictions in main API
|
|
211
|
+
|
|
212
|
+
## Error Handling
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
try {
|
|
216
|
+
const response = await authClient.get('/api/v1/data');
|
|
217
|
+
} catch (error: any) {
|
|
218
|
+
if (error.response?.status === 401) {
|
|
219
|
+
console.error('Invalid or expired API key');
|
|
220
|
+
} else if (error.response?.status === 429) {
|
|
221
|
+
console.error('Rate limit exceeded');
|
|
222
|
+
} else {
|
|
223
|
+
console.error('Request failed:', error.message);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## How to Get API Key
|
|
229
|
+
|
|
230
|
+
1. Login to the main Win Portal application
|
|
231
|
+
2. Navigate to **Applications** section
|
|
232
|
+
3. Create or select your application
|
|
233
|
+
4. Generate a new API key
|
|
234
|
+
5. Copy and save the key (shown only once)
|
|
235
|
+
6. Configure the key in your environment variables
|
|
236
|
+
|
|
237
|
+
## License
|
|
238
|
+
|
|
239
|
+
MIT
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication API
|
|
3
|
+
*
|
|
4
|
+
* Handles authentication operations:
|
|
5
|
+
* - Login
|
|
6
|
+
* - Logout
|
|
7
|
+
* - Profile
|
|
8
|
+
* - Token refresh
|
|
9
|
+
*/
|
|
10
|
+
import { AuthClient } from '../auth-client';
|
|
11
|
+
import { LoginResponseDto, UserProfileResponseDto, TokenRefreshResponseDto } from '../../types';
|
|
12
|
+
export declare class AuthAPI {
|
|
13
|
+
private client;
|
|
14
|
+
constructor(client: AuthClient);
|
|
15
|
+
/**
|
|
16
|
+
* Login with email and password
|
|
17
|
+
*/
|
|
18
|
+
login(email: string, password: string): Promise<LoginResponseDto>;
|
|
19
|
+
/**
|
|
20
|
+
* Logout current session
|
|
21
|
+
*/
|
|
22
|
+
logout(): Promise<{
|
|
23
|
+
message: string;
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* Get current user profile
|
|
27
|
+
*/
|
|
28
|
+
profile(): Promise<UserProfileResponseDto>;
|
|
29
|
+
/**
|
|
30
|
+
* Refresh access token
|
|
31
|
+
*/
|
|
32
|
+
refresh(refreshToken: string): Promise<TokenRefreshResponseDto>;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=auth.api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.api.d.ts","sourceRoot":"","sources":["../../../src/client/api/auth.api.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAEL,gBAAgB,EAChB,sBAAsB,EAEtB,uBAAuB,EACxB,MAAM,aAAa,CAAC;AAErB,qBAAa,OAAO;IACN,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,UAAU;IAEtC;;OAEG;IACG,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAMvE;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAK5C;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,sBAAsB,CAAC;IAKhD;;OAEG;IACG,OAAO,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC;CAKtE"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Authentication API
|
|
4
|
+
*
|
|
5
|
+
* Handles authentication operations:
|
|
6
|
+
* - Login
|
|
7
|
+
* - Logout
|
|
8
|
+
* - Profile
|
|
9
|
+
* - Token refresh
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AuthAPI = void 0;
|
|
13
|
+
class AuthAPI {
|
|
14
|
+
constructor(client) {
|
|
15
|
+
this.client = client;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Login with email and password
|
|
19
|
+
*/
|
|
20
|
+
async login(email, password) {
|
|
21
|
+
const payload = { username: email, password };
|
|
22
|
+
const response = await this.client.post('/auth/login', payload);
|
|
23
|
+
return response.data;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Logout current session
|
|
27
|
+
*/
|
|
28
|
+
async logout() {
|
|
29
|
+
const response = await this.client.post('/auth/logout');
|
|
30
|
+
return response.data;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get current user profile
|
|
34
|
+
*/
|
|
35
|
+
async profile() {
|
|
36
|
+
const response = await this.client.get('/auth/me');
|
|
37
|
+
return response.data;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Refresh access token
|
|
41
|
+
*/
|
|
42
|
+
async refresh(refreshToken) {
|
|
43
|
+
const payload = { refresh_token: refreshToken };
|
|
44
|
+
const response = await this.client.post('/auth/refresh', payload);
|
|
45
|
+
return response.data;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.AuthAPI = AuthAPI;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AuthClient } from '../auth-client';
|
|
2
|
+
import { CreateEventLogRequestDto, EventLogResponseDto } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* Event Log API Client
|
|
5
|
+
*
|
|
6
|
+
* Centralized event logging client for microservices
|
|
7
|
+
* Sends all event logs to main API for centralized storage
|
|
8
|
+
*/
|
|
9
|
+
export declare class EventLogApi {
|
|
10
|
+
private readonly client;
|
|
11
|
+
constructor(client: AuthClient);
|
|
12
|
+
/**
|
|
13
|
+
* Log event to centralized event log system
|
|
14
|
+
*/
|
|
15
|
+
logEvent(eventData: CreateEventLogRequestDto): Promise<EventLogResponseDto>;
|
|
16
|
+
/**
|
|
17
|
+
* Batch log multiple events (for performance)
|
|
18
|
+
*/
|
|
19
|
+
logEvents(events: CreateEventLogRequestDto[]): Promise<{
|
|
20
|
+
success: number;
|
|
21
|
+
failed: number;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=event-log.api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-log.api.d.ts","sourceRoot":"","sources":["../../../src/client/api/event-log.api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAE5E;;;;;GAKG;AACH,qBAAa,WAAW;IACV,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,UAAU;IAE/C;;OAEG;IACG,QAAQ,CAAC,SAAS,EAAE,wBAAwB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAKjF;;OAEG;IACG,SAAS,CAAC,MAAM,EAAE,wBAAwB,EAAE,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAIlG"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventLogApi = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Event Log API Client
|
|
6
|
+
*
|
|
7
|
+
* Centralized event logging client for microservices
|
|
8
|
+
* Sends all event logs to main API for centralized storage
|
|
9
|
+
*/
|
|
10
|
+
class EventLogApi {
|
|
11
|
+
constructor(client) {
|
|
12
|
+
this.client = client;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Log event to centralized event log system
|
|
16
|
+
*/
|
|
17
|
+
async logEvent(eventData) {
|
|
18
|
+
const response = await this.client.post('/event-logs', eventData);
|
|
19
|
+
return response.data;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Batch log multiple events (for performance)
|
|
23
|
+
*/
|
|
24
|
+
async logEvents(events) {
|
|
25
|
+
const response = await this.client.post('/event-logs/batch', { events });
|
|
26
|
+
return response.data;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.EventLogApi = EventLogApi;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { AuthClient } from '../auth-client';
|
|
3
|
+
import { FileResponseDto, FileUpdateRequestDto, FileSearchParams } from '../../types';
|
|
4
|
+
/**
|
|
5
|
+
* Files API
|
|
6
|
+
* Methods for file management operations
|
|
7
|
+
* Based on: apps/api/src/modules/features/files/controllers/files.controller.ts
|
|
8
|
+
*/
|
|
9
|
+
export declare class FilesAPI {
|
|
10
|
+
private client;
|
|
11
|
+
constructor(client: AuthClient);
|
|
12
|
+
/**
|
|
13
|
+
* POST /files - อัปโหลดไฟล์ใหม่
|
|
14
|
+
* Supports both authenticated and anonymous uploads
|
|
15
|
+
*/
|
|
16
|
+
upload(formData: FormData): Promise<FileResponseDto>;
|
|
17
|
+
/**
|
|
18
|
+
* GET /files/:id - ดูข้อมูลไฟล์
|
|
19
|
+
* Public access (supports both authenticated and anonymous)
|
|
20
|
+
*/
|
|
21
|
+
getById(id: string): Promise<FileResponseDto>;
|
|
22
|
+
/**
|
|
23
|
+
* GET /files/:id/content - ดึง file content (รูปภาพ, เอกสาร)
|
|
24
|
+
* Returns the actual file content or redirects to cloud storage URL
|
|
25
|
+
* Public access based on file.is_public flag
|
|
26
|
+
*/
|
|
27
|
+
getContentUrl(id: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* PUT /files/:id - อัปเดตข้อมูลไฟล์
|
|
30
|
+
* Requires authentication
|
|
31
|
+
*/
|
|
32
|
+
update(id: string, updateData: FileUpdateRequestDto): Promise<FileResponseDto>;
|
|
33
|
+
/**
|
|
34
|
+
* DELETE /files/:id - ลบไฟล์
|
|
35
|
+
* Requires authentication
|
|
36
|
+
*/
|
|
37
|
+
delete(id: string): Promise<{
|
|
38
|
+
message: string;
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* POST /files/search - ค้นหาไฟล์แบบ advanced
|
|
42
|
+
* Public access (supports both authenticated and anonymous)
|
|
43
|
+
*/
|
|
44
|
+
search(searchParams?: FileSearchParams): Promise<{
|
|
45
|
+
data: FileResponseDto[];
|
|
46
|
+
total: number;
|
|
47
|
+
page: number;
|
|
48
|
+
page_size: number;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* DELETE /files/bulk - ลบไฟล์หลายไฟล์
|
|
52
|
+
* Requires authentication
|
|
53
|
+
*/
|
|
54
|
+
bulkDelete(ids: string[]): Promise<{
|
|
55
|
+
message: string;
|
|
56
|
+
deleted_count: number;
|
|
57
|
+
}>;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=files.api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.api.d.ts","sourceRoot":"","sources":["../../../src/client/api/files.api.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEtF;;;;GAIG;AACH,qBAAa,QAAQ;IACP,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,UAAU;IAEtC;;;OAGG;IACG,MAAM,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,eAAe,CAAC;IAS1D;;;OAGG;IACG,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAKnD;;;;OAIG;IACH,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM;IAKjC;;;OAGG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,oBAAoB,GAAG,OAAO,CAAC,eAAe,CAAC;IAKpF;;;OAGG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAKtD;;;OAGG;IACG,MAAM,CAAC,YAAY,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC;QACrD,IAAI,EAAE,eAAe,EAAE,CAAC;QACxB,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IAKF;;;OAGG;IACG,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE,CAAC;CAMrF"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FilesAPI = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Files API
|
|
6
|
+
* Methods for file management operations
|
|
7
|
+
* Based on: apps/api/src/modules/features/files/controllers/files.controller.ts
|
|
8
|
+
*/
|
|
9
|
+
class FilesAPI {
|
|
10
|
+
constructor(client) {
|
|
11
|
+
this.client = client;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* POST /files - อัปโหลดไฟล์ใหม่
|
|
15
|
+
* Supports both authenticated and anonymous uploads
|
|
16
|
+
*/
|
|
17
|
+
async upload(formData) {
|
|
18
|
+
const response = await this.client.post('/files', formData, {
|
|
19
|
+
headers: {
|
|
20
|
+
'Content-Type': 'multipart/form-data',
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
return response.data;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* GET /files/:id - ดูข้อมูลไฟล์
|
|
27
|
+
* Public access (supports both authenticated and anonymous)
|
|
28
|
+
*/
|
|
29
|
+
async getById(id) {
|
|
30
|
+
const response = await this.client.get(`/files/${id}`);
|
|
31
|
+
return response.data;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* GET /files/:id/content - ดึง file content (รูปภาพ, เอกสาร)
|
|
35
|
+
* Returns the actual file content or redirects to cloud storage URL
|
|
36
|
+
* Public access based on file.is_public flag
|
|
37
|
+
*/
|
|
38
|
+
getContentUrl(id) {
|
|
39
|
+
const baseURL = this.client.getAxiosInstance().defaults.baseURL || '';
|
|
40
|
+
return `${baseURL}/files/${id}/content`;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* PUT /files/:id - อัปเดตข้อมูลไฟล์
|
|
44
|
+
* Requires authentication
|
|
45
|
+
*/
|
|
46
|
+
async update(id, updateData) {
|
|
47
|
+
const response = await this.client.put(`/files/${id}`, updateData);
|
|
48
|
+
return response.data;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* DELETE /files/:id - ลบไฟล์
|
|
52
|
+
* Requires authentication
|
|
53
|
+
*/
|
|
54
|
+
async delete(id) {
|
|
55
|
+
const response = await this.client.delete(`/files/${id}`);
|
|
56
|
+
return response.data;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* POST /files/search - ค้นหาไฟล์แบบ advanced
|
|
60
|
+
* Public access (supports both authenticated and anonymous)
|
|
61
|
+
*/
|
|
62
|
+
async search(searchParams) {
|
|
63
|
+
const response = await this.client.post('/files/search', searchParams || {});
|
|
64
|
+
return response.data;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* DELETE /files/bulk - ลบไฟล์หลายไฟล์
|
|
68
|
+
* Requires authentication
|
|
69
|
+
*/
|
|
70
|
+
async bulkDelete(ids) {
|
|
71
|
+
const response = await this.client.delete('/files/bulk', {
|
|
72
|
+
data: { ids },
|
|
73
|
+
});
|
|
74
|
+
return response.data;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.FilesAPI = FilesAPI;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Health & Validation API
|
|
3
|
+
*
|
|
4
|
+
* Handles health check and API key validation:
|
|
5
|
+
* - Health check
|
|
6
|
+
* - API key validation
|
|
7
|
+
*/
|
|
8
|
+
import { AuthClient } from '../auth-client';
|
|
9
|
+
export declare class HealthAPI {
|
|
10
|
+
private client;
|
|
11
|
+
constructor(client: AuthClient);
|
|
12
|
+
/**
|
|
13
|
+
* Check API health
|
|
14
|
+
*/
|
|
15
|
+
check(): Promise<any>;
|
|
16
|
+
/**
|
|
17
|
+
* Validate if API key is still active
|
|
18
|
+
*/
|
|
19
|
+
validateApiKey(): Promise<boolean>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=health.api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.api.d.ts","sourceRoot":"","sources":["../../../src/client/api/health.api.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,qBAAa,SAAS;IACR,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,UAAU;IAEtC;;OAEG;IACG,KAAK;IAKX;;OAEG;IACG,cAAc;CAQrB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Health & Validation API
|
|
4
|
+
*
|
|
5
|
+
* Handles health check and API key validation:
|
|
6
|
+
* - Health check
|
|
7
|
+
* - API key validation
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.HealthAPI = void 0;
|
|
11
|
+
class HealthAPI {
|
|
12
|
+
constructor(client) {
|
|
13
|
+
this.client = client;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Check API health
|
|
17
|
+
*/
|
|
18
|
+
async check() {
|
|
19
|
+
const response = await this.client.get('/health');
|
|
20
|
+
return response.data;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Validate if API key is still active
|
|
24
|
+
*/
|
|
25
|
+
async validateApiKey() {
|
|
26
|
+
try {
|
|
27
|
+
await this.check();
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.HealthAPI = HealthAPI;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Namespace Exports
|
|
3
|
+
*
|
|
4
|
+
* Central export point for all API namespaces
|
|
5
|
+
*/
|
|
6
|
+
export { AuthAPI } from './auth.api';
|
|
7
|
+
export { HealthAPI } from './health.api';
|
|
8
|
+
export { SystemConfigAPI } from './system-config.api';
|
|
9
|
+
export { FilesAPI } from './files.api';
|
|
10
|
+
export { EventLogApi } from './event-log.api';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/api/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* API Namespace Exports
|
|
4
|
+
*
|
|
5
|
+
* Central export point for all API namespaces
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.EventLogApi = exports.FilesAPI = exports.SystemConfigAPI = exports.HealthAPI = exports.AuthAPI = void 0;
|
|
9
|
+
var auth_api_1 = require("./auth.api");
|
|
10
|
+
Object.defineProperty(exports, "AuthAPI", { enumerable: true, get: function () { return auth_api_1.AuthAPI; } });
|
|
11
|
+
var health_api_1 = require("./health.api");
|
|
12
|
+
Object.defineProperty(exports, "HealthAPI", { enumerable: true, get: function () { return health_api_1.HealthAPI; } });
|
|
13
|
+
var system_config_api_1 = require("./system-config.api");
|
|
14
|
+
Object.defineProperty(exports, "SystemConfigAPI", { enumerable: true, get: function () { return system_config_api_1.SystemConfigAPI; } });
|
|
15
|
+
var files_api_1 = require("./files.api");
|
|
16
|
+
Object.defineProperty(exports, "FilesAPI", { enumerable: true, get: function () { return files_api_1.FilesAPI; } });
|
|
17
|
+
var event_log_api_1 = require("./event-log.api");
|
|
18
|
+
Object.defineProperty(exports, "EventLogApi", { enumerable: true, get: function () { return event_log_api_1.EventLogApi; } });
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { AuthClient } from '../auth-client';
|
|
2
|
+
import { SystemConfigResponseDto, SystemConfigSearchParams, SystemConfigCategoryResponse } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* System Config API
|
|
5
|
+
* Methods for retrieving system configurations
|
|
6
|
+
* Based on: apps/api/src/modules/shared/core/controllers/system-config.controller.ts
|
|
7
|
+
*/
|
|
8
|
+
export declare class SystemConfigAPI {
|
|
9
|
+
private client;
|
|
10
|
+
constructor(client: AuthClient);
|
|
11
|
+
/**
|
|
12
|
+
* GET /system-configs
|
|
13
|
+
* ดึงรายการ system configs (with pagination)
|
|
14
|
+
*/
|
|
15
|
+
search(params?: SystemConfigSearchParams): Promise<{
|
|
16
|
+
data: SystemConfigResponseDto[];
|
|
17
|
+
total: number;
|
|
18
|
+
page: number;
|
|
19
|
+
page_size: number;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* GET /system-configs/categories/:category
|
|
23
|
+
* ดึง configs ตาม category - ส่ง object ที่รวมทุก key เป็น { key1: value1, key2: value2 }
|
|
24
|
+
*/
|
|
25
|
+
getByCategory(category: string): Promise<SystemConfigCategoryResponse>;
|
|
26
|
+
/**
|
|
27
|
+
* GET /system-configs/categories/:category/:key
|
|
28
|
+
* ดึง config ตาม category และ key - ส่ง full metadata row
|
|
29
|
+
*/
|
|
30
|
+
getByCategoryAndKey(category: string, key: string): Promise<SystemConfigResponseDto>;
|
|
31
|
+
/**
|
|
32
|
+
* GET /system-configs/categories/security
|
|
33
|
+
* ดึง security configs ทั้งหมด (convenience method)
|
|
34
|
+
*/
|
|
35
|
+
security(): Promise<SystemConfigCategoryResponse>;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=system-config.api.d.ts.map
|