win-portal-auth-sdk 1.0.0 → 1.1.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/README.md +146 -1
- package/TYPE_SAFETY.md +97 -0
- package/dist/client/api/auth.api.d.ts +58 -4
- package/dist/client/api/auth.api.d.ts.map +1 -1
- package/dist/client/api/auth.api.js +64 -2
- package/dist/client/api/files.api.d.ts +5 -5
- package/dist/client/api/files.api.d.ts.map +1 -1
- package/dist/client/api/index.d.ts +5 -0
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/client/api/index.js +8 -1
- package/dist/client/api/line.api.d.ts +150 -0
- package/dist/client/api/line.api.d.ts.map +1 -0
- package/dist/client/api/line.api.js +114 -0
- package/dist/client/api/oauth.api.d.ts +221 -0
- package/dist/client/api/oauth.api.d.ts.map +1 -0
- package/dist/client/api/oauth.api.js +258 -0
- package/dist/client/api/system-config.api.d.ts +4 -14
- package/dist/client/api/system-config.api.d.ts.map +1 -1
- package/dist/client/api/system-config.api.js +0 -8
- package/dist/client/auth-client.d.ts +16 -1
- package/dist/client/auth-client.d.ts.map +1 -1
- package/dist/client/auth-client.js +16 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/middleware/express.middleware.d.ts +62 -0
- package/dist/middleware/express.middleware.d.ts.map +1 -0
- package/dist/middleware/express.middleware.js +185 -0
- package/dist/middleware/express.types.d.ts +28 -0
- package/dist/middleware/express.types.d.ts.map +1 -0
- package/dist/middleware/express.types.js +7 -0
- package/dist/middleware/index.d.ts +8 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +26 -0
- package/dist/middleware/nestjs.decorators.d.ts +31 -0
- package/dist/middleware/nestjs.decorators.d.ts.map +1 -0
- package/dist/middleware/nestjs.decorators.js +56 -0
- package/dist/middleware/nestjs.guard.d.ts +55 -0
- package/dist/middleware/nestjs.guard.d.ts.map +1 -0
- package/dist/middleware/nestjs.guard.js +188 -0
- package/dist/middleware/types.d.ts +59 -0
- package/dist/middleware/types.d.ts.map +1 -0
- package/dist/middleware/types.js +5 -0
- package/dist/types/auth.types.d.ts +16 -13
- package/dist/types/auth.types.d.ts.map +1 -1
- package/dist/types/auth.types.js +2 -2
- package/dist/types/file.types.d.ts +13 -9
- package/dist/types/file.types.d.ts.map +1 -1
- package/dist/types/file.types.js +2 -2
- package/dist/types/system-config.types.d.ts +8 -18
- package/dist/types/system-config.types.d.ts.map +1 -1
- package/dist/types/system-config.types.js +2 -2
- package/package.json +8 -2
package/README.md
CHANGED
|
@@ -9,8 +9,10 @@ Shared authentication SDK for Win Portal applications using API Key authenticati
|
|
|
9
9
|
|
|
10
10
|
- 🔐 **API Key Authentication** - Secure authentication using application API keys
|
|
11
11
|
- 🎯 **Frontend Client** - HTTP client with automatic API key injection for Next.js/React
|
|
12
|
+
- 🛡️ **Backend Middleware** - Express & NestJS middleware for easy authentication
|
|
12
13
|
- 📦 **Lightweight** - Minimal dependencies
|
|
13
14
|
- 🔧 **TypeScript Support** - Full type definitions included
|
|
15
|
+
- ✨ **Type Safety** - Express Request augmentation with full IntelliSense
|
|
14
16
|
|
|
15
17
|
## How It Works
|
|
16
18
|
|
|
@@ -66,6 +68,39 @@ const profile = await authClient.auth.profile();
|
|
|
66
68
|
const refreshed = await authClient.auth.refresh(refreshToken);
|
|
67
69
|
await authClient.auth.logout();
|
|
68
70
|
|
|
71
|
+
// TOTP (Two-Factor Authentication)
|
|
72
|
+
// 1. Setup TOTP for user
|
|
73
|
+
const totpSetup = await authClient.auth.setupTotp('My App');
|
|
74
|
+
console.log('QR Code:', totpSetup.qr_code);
|
|
75
|
+
console.log('Backup Codes:', totpSetup.backup_codes);
|
|
76
|
+
|
|
77
|
+
// 2. Verify TOTP setup with code from authenticator app
|
|
78
|
+
await authClient.auth.verifyTotpSetup('123456');
|
|
79
|
+
|
|
80
|
+
// 3. Get TOTP status
|
|
81
|
+
const status = await authClient.auth.getTotpStatus();
|
|
82
|
+
console.log('TOTP Enabled:', status.is_enabled);
|
|
83
|
+
|
|
84
|
+
// 4. Login with TOTP (2-step authentication)
|
|
85
|
+
const loginResult = await authClient.auth.login('user@example.com', 'password');
|
|
86
|
+
if (loginResult.totp_required) {
|
|
87
|
+
// User has TOTP enabled, need to verify
|
|
88
|
+
const totpToken = '123456'; // From authenticator app
|
|
89
|
+
const session = await authClient.auth.verifyTotpLogin(
|
|
90
|
+
totpToken,
|
|
91
|
+
undefined, // backup_code (optional)
|
|
92
|
+
loginResult.access_token, // temp_token from initial login
|
|
93
|
+
);
|
|
94
|
+
console.log('Login successful:', session.user);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 5. Disable TOTP
|
|
98
|
+
await authClient.auth.disableTotp();
|
|
99
|
+
|
|
100
|
+
// 6. Regenerate backup codes
|
|
101
|
+
const newCodes = await authClient.auth.regenerateTotpBackupCodes();
|
|
102
|
+
console.log('New backup codes:', newCodes.backup_codes);
|
|
103
|
+
|
|
69
104
|
// User Management
|
|
70
105
|
const users = await authClient.user.search({
|
|
71
106
|
search: 'john',
|
|
@@ -80,6 +115,21 @@ await authClient.user.delete(userId);
|
|
|
80
115
|
// Health Check
|
|
81
116
|
const health = await authClient.health.check();
|
|
82
117
|
const isValid = await authClient.health.validateApiKey();
|
|
118
|
+
|
|
119
|
+
// LINE Messaging
|
|
120
|
+
await authClient.line.sendTextMessage({
|
|
121
|
+
userId: 'user-123',
|
|
122
|
+
message: 'สวัสดีครับ!',
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
await authClient.line.sendNotification({
|
|
126
|
+
userId: 'user-123',
|
|
127
|
+
title: 'งานใหม่',
|
|
128
|
+
message: 'คุณมีงานใหม่ที่ต้องดำเนินการ',
|
|
129
|
+
type: 'info',
|
|
130
|
+
action_url: 'https://app.example.com/tasks/123',
|
|
131
|
+
priority: 'high',
|
|
132
|
+
});
|
|
83
133
|
```
|
|
84
134
|
|
|
85
135
|
**For custom endpoints, use direct HTTP methods:**
|
|
@@ -123,7 +173,79 @@ NEXT_PUBLIC_API_KEY=app_your_api_key_here
|
|
|
123
173
|
NEXT_PUBLIC_API_URL=https://api.yourdomain.com
|
|
124
174
|
```
|
|
125
175
|
|
|
126
|
-
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## Backend Middleware (Express & NestJS)
|
|
179
|
+
|
|
180
|
+
The SDK provides middleware for **Express** and **Guards** for **NestJS** to easily authenticate requests using JWT tokens.
|
|
181
|
+
|
|
182
|
+
### Quick Start - Express
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import express from 'express';
|
|
186
|
+
import { authMiddleware } from '@win-portal/auth-sdk';
|
|
187
|
+
|
|
188
|
+
const app = express();
|
|
189
|
+
|
|
190
|
+
// Apply middleware globally
|
|
191
|
+
app.use(
|
|
192
|
+
authMiddleware({
|
|
193
|
+
baseURL: 'https://api.example.com',
|
|
194
|
+
apiKey: 'your-api-key',
|
|
195
|
+
}),
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
// Now all routes have access to req.user and req.token
|
|
199
|
+
app.get('/profile', (req, res) => {
|
|
200
|
+
const user = req.user; // User
|
|
201
|
+
res.json({
|
|
202
|
+
email: user.email,
|
|
203
|
+
permissions: user.permissions,
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Quick Start - NestJS
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
// auth/guards/auth.guard.ts
|
|
212
|
+
import { createAuthGuard } from '@win-portal/auth-sdk';
|
|
213
|
+
|
|
214
|
+
export const AuthGuard = createAuthGuard({
|
|
215
|
+
baseURL: process.env.API_BASE_URL!,
|
|
216
|
+
apiKey: process.env.API_KEY!,
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// In controller
|
|
220
|
+
@Controller('users')
|
|
221
|
+
export class UsersController {
|
|
222
|
+
@Get('profile')
|
|
223
|
+
@UseGuards(AuthGuard)
|
|
224
|
+
getProfile(@CurrentUser() user: User) {
|
|
225
|
+
return user;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### 📖 Complete Middleware Documentation
|
|
231
|
+
|
|
232
|
+
For complete documentation, examples, and advanced usage:
|
|
233
|
+
|
|
234
|
+
**[View Full Middleware Guide →](./docs/MIDDLEWARE_USAGE.md)**
|
|
235
|
+
|
|
236
|
+
Includes:
|
|
237
|
+
|
|
238
|
+
- Express middleware configuration
|
|
239
|
+
- NestJS guards and decorators
|
|
240
|
+
- Optional authentication
|
|
241
|
+
- Custom token extractors
|
|
242
|
+
- Cache management
|
|
243
|
+
- Permission checking patterns
|
|
244
|
+
- Full working examples
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## Backend (NestJS - API Client)
|
|
127
249
|
|
|
128
250
|
For template-api that needs to call main API:
|
|
129
251
|
|
|
@@ -189,6 +311,17 @@ const client = new AuthClient({
|
|
|
189
311
|
- `user.update(userId, userData)` - Update user
|
|
190
312
|
- `user.delete(userId)` - Delete user
|
|
191
313
|
|
|
314
|
+
**LINE Messaging:**
|
|
315
|
+
|
|
316
|
+
- `line.sendTextMessage({ userId, message })` - Send text message
|
|
317
|
+
- `line.sendSticker({ userId, packageId, stickerId })` - Send LINE sticker
|
|
318
|
+
- `line.sendImage({ userId, originalContentUrl, previewImageUrl })` - Send image
|
|
319
|
+
- `line.sendMessages({ userId, messages })` - Send multiple messages (max 5)
|
|
320
|
+
- `line.sendNotification({ userId, title, message, type?, action_url?, priority? })` - Send formatted notification
|
|
321
|
+
- `line.checkMessagingAvailability(userId)` - Check if user can receive LINE messages
|
|
322
|
+
|
|
323
|
+
> 📖 **[LINE Messaging Guide →](./docs/line-messaging.md)** - Complete documentation with examples
|
|
324
|
+
|
|
192
325
|
**Health & Validation:**
|
|
193
326
|
|
|
194
327
|
- `health.check()` - Check API health
|
|
@@ -234,6 +367,18 @@ try {
|
|
|
234
367
|
5. Copy and save the key (shown only once)
|
|
235
368
|
6. Configure the key in your environment variables
|
|
236
369
|
|
|
370
|
+
## Documentation
|
|
371
|
+
|
|
372
|
+
📚 **[Complete Documentation →](./docs/README.md)**
|
|
373
|
+
|
|
374
|
+
- [Frontend Examples](./docs/FRONTEND_EXAMPLES.md) - Next.js, React usage
|
|
375
|
+
- [Middleware Guide](./docs/MIDDLEWARE_USAGE.md) - Express & NestJS
|
|
376
|
+
- [Type Safety Guide](./TYPE_SAFETY.md) - Express type augmentation 🆕
|
|
377
|
+
- [Type Names Guide](./TYPE_NAMES.md) - SDK-friendly type names 🆕
|
|
378
|
+
- [Code Examples](./EXAMPLE.md) - Real-world usage examples 🆕
|
|
379
|
+
- [Thai Documentation](./docs/USAGE_TH.md) - คู่มือภาษาไทย
|
|
380
|
+
- [Publishing Guide](./docs/NPM_PUBLISH_GUIDE.md) - How to publish updates
|
|
381
|
+
|
|
237
382
|
## License
|
|
238
383
|
|
|
239
384
|
MIT
|
package/TYPE_SAFETY.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Type Safety Guide
|
|
2
|
+
|
|
3
|
+
## Express Type Augmentation
|
|
4
|
+
|
|
5
|
+
The SDK automatically extends Express's `Request` interface to include auth properties.
|
|
6
|
+
|
|
7
|
+
### What's Included
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
declare global {
|
|
11
|
+
namespace Express {
|
|
12
|
+
interface Request {
|
|
13
|
+
user?: UserProfileResponseDto | null;
|
|
14
|
+
token?: string | null;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Usage
|
|
21
|
+
|
|
22
|
+
After installing the SDK, TypeScript will automatically recognize `req.user` and `req.token`:
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import express from 'express';
|
|
26
|
+
import { authMiddleware } from 'win-portal-auth-sdk';
|
|
27
|
+
|
|
28
|
+
const app = express();
|
|
29
|
+
|
|
30
|
+
app.use(
|
|
31
|
+
authMiddleware({
|
|
32
|
+
baseURL: process.env.API_URL,
|
|
33
|
+
apiKey: process.env.API_KEY,
|
|
34
|
+
}),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
app.get('/profile', (req, res) => {
|
|
38
|
+
// ✅ TypeScript knows about req.user
|
|
39
|
+
if (req.user) {
|
|
40
|
+
// ✅ Full IntelliSense for user properties
|
|
41
|
+
res.json({
|
|
42
|
+
email: req.user.email,
|
|
43
|
+
name: req.user.displayName,
|
|
44
|
+
permissions: req.user.permissions,
|
|
45
|
+
});
|
|
46
|
+
} else {
|
|
47
|
+
res.status(401).json({ error: 'Not authenticated' });
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### States
|
|
53
|
+
|
|
54
|
+
- `undefined` - Middleware not applied to this route
|
|
55
|
+
- `null` - Middleware applied but no token provided (when `optional: true`)
|
|
56
|
+
- `UserProfileResponseDto` - Successfully authenticated
|
|
57
|
+
|
|
58
|
+
### Helper Functions
|
|
59
|
+
|
|
60
|
+
For guaranteed non-null user:
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { requireAuth } from 'win-portal-auth-sdk';
|
|
64
|
+
|
|
65
|
+
app.get('/protected', (req, res) => {
|
|
66
|
+
const { user } = requireAuth(req);
|
|
67
|
+
// ✅ user is guaranteed to be UserProfileResponseDto (not null)
|
|
68
|
+
res.json({ email: user.email });
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
For optional auth:
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { getAuth } from 'win-portal-auth-sdk';
|
|
76
|
+
|
|
77
|
+
app.get('/optional', (req, res) => {
|
|
78
|
+
const { user, token } = getAuth(req);
|
|
79
|
+
|
|
80
|
+
if (user) {
|
|
81
|
+
res.json({ authenticated: true, email: user.email });
|
|
82
|
+
} else {
|
|
83
|
+
res.json({ authenticated: false });
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Benefits
|
|
89
|
+
|
|
90
|
+
1. **IntelliSense** - Full autocomplete for `req.user` properties
|
|
91
|
+
2. **Type Safety** - Compile-time errors for typos
|
|
92
|
+
3. **Better DX** - No need to cast or assert types manually
|
|
93
|
+
4. **Standard Pattern** - Follows Express best practices
|
|
94
|
+
|
|
95
|
+
## No Express Dependency
|
|
96
|
+
|
|
97
|
+
The SDK does NOT depend on Express itself - it only augments the types when Express is present in your project. This keeps the SDK lightweight and flexible.
|
|
@@ -6,16 +6,17 @@
|
|
|
6
6
|
* - Logout
|
|
7
7
|
* - Profile
|
|
8
8
|
* - Token refresh
|
|
9
|
+
* - TOTP (Two-Factor Authentication)
|
|
9
10
|
*/
|
|
10
11
|
import { AuthClient } from '../auth-client';
|
|
11
|
-
import {
|
|
12
|
+
import { AuthSession, User, AuthTokens } from '../../types';
|
|
12
13
|
export declare class AuthAPI {
|
|
13
14
|
private client;
|
|
14
15
|
constructor(client: AuthClient);
|
|
15
16
|
/**
|
|
16
17
|
* Login with email and password
|
|
17
18
|
*/
|
|
18
|
-
login(email: string, password: string): Promise<
|
|
19
|
+
login(email: string, password: string): Promise<AuthSession>;
|
|
19
20
|
/**
|
|
20
21
|
* Logout current session
|
|
21
22
|
*/
|
|
@@ -25,10 +26,63 @@ export declare class AuthAPI {
|
|
|
25
26
|
/**
|
|
26
27
|
* Get current user profile
|
|
27
28
|
*/
|
|
28
|
-
profile(): Promise<
|
|
29
|
+
profile(): Promise<User>;
|
|
29
30
|
/**
|
|
30
31
|
* Refresh access token
|
|
31
32
|
*/
|
|
32
|
-
refresh(
|
|
33
|
+
refresh(refresh_token: string): Promise<AuthTokens>;
|
|
34
|
+
/**
|
|
35
|
+
* Setup TOTP for user account
|
|
36
|
+
* Returns QR code and backup codes
|
|
37
|
+
*/
|
|
38
|
+
setupTotp(serviceName?: string): Promise<{
|
|
39
|
+
secret: string;
|
|
40
|
+
qr_code: string;
|
|
41
|
+
backup_codes: string[];
|
|
42
|
+
setup_uri: string;
|
|
43
|
+
}>;
|
|
44
|
+
/**
|
|
45
|
+
* Verify TOTP setup with a token from authenticator app
|
|
46
|
+
*/
|
|
47
|
+
verifyTotpSetup(token: string): Promise<{
|
|
48
|
+
verified: boolean;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* Get TOTP status for current user
|
|
52
|
+
*/
|
|
53
|
+
getTotpStatus(): Promise<{
|
|
54
|
+
is_enabled: boolean;
|
|
55
|
+
is_verified: boolean;
|
|
56
|
+
backup_codes_remaining: number;
|
|
57
|
+
last_used_at?: Date;
|
|
58
|
+
algorithm: string;
|
|
59
|
+
digits: number;
|
|
60
|
+
period: number;
|
|
61
|
+
}>;
|
|
62
|
+
/**
|
|
63
|
+
* Verify TOTP code (for general verification when already logged in)
|
|
64
|
+
*/
|
|
65
|
+
verifyTotp(token: string): Promise<{
|
|
66
|
+
verified: boolean;
|
|
67
|
+
}>;
|
|
68
|
+
/**
|
|
69
|
+
* Verify TOTP code after login (2-step authentication)
|
|
70
|
+
* Use this when login returns totp_required: true
|
|
71
|
+
*/
|
|
72
|
+
verifyTotpLogin(token: string | undefined, backupCode: string | undefined, tempToken: string): Promise<AuthSession>;
|
|
73
|
+
/**
|
|
74
|
+
* Disable TOTP for current user
|
|
75
|
+
*/
|
|
76
|
+
disableTotp(): Promise<{
|
|
77
|
+
disabled: boolean;
|
|
78
|
+
}>;
|
|
79
|
+
/**
|
|
80
|
+
* Regenerate backup codes
|
|
81
|
+
* Old backup codes will be invalidated
|
|
82
|
+
*/
|
|
83
|
+
regenerateTotpBackupCodes(): Promise<{
|
|
84
|
+
backup_codes: string[];
|
|
85
|
+
message: string;
|
|
86
|
+
}>;
|
|
33
87
|
}
|
|
34
88
|
//# sourceMappingURL=auth.api.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.api.d.ts","sourceRoot":"","sources":["../../../src/client/api/auth.api.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"auth.api.d.ts","sourceRoot":"","sources":["../../../src/client/api/auth.api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAoB,WAAW,EAAE,IAAI,EAAuB,UAAU,EAAE,MAAM,aAAa,CAAC;AAEnG,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,WAAW,CAAC;IAMlE;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAK5C;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAK9B;;OAEG;IACG,OAAO,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAUzD;;;OAGG;IACG,SAAS,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;QAC7C,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,YAAY,EAAE,MAAM,EAAE,CAAC;QACvB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IAOF;;OAEG;IACG,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,QAAQ,EAAE,OAAO,CAAA;KAAE,CAAC;IAKpE;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC;QAC7B,UAAU,EAAE,OAAO,CAAC;QACpB,WAAW,EAAE,OAAO,CAAC;QACrB,sBAAsB,EAAE,MAAM,CAAC;QAC/B,YAAY,CAAC,EAAE,IAAI,CAAC;QACpB,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;IAKF;;OAEG;IACG,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,QAAQ,EAAE,OAAO,CAAA;KAAE,CAAC;IAK/D;;;OAGG;IACG,eAAe,CACnB,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,WAAW,CAAC;IASvB;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC;QAAE,QAAQ,EAAE,OAAO,CAAA;KAAE,CAAC;IAKnD;;;OAGG;IACG,yBAAyB,IAAI,OAAO,CAAC;QACzC,YAAY,EAAE,MAAM,EAAE,CAAC;QACvB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CAIH"}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* - Logout
|
|
8
8
|
* - Profile
|
|
9
9
|
* - Token refresh
|
|
10
|
+
* - TOTP (Two-Factor Authentication)
|
|
10
11
|
*/
|
|
11
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
13
|
exports.AuthAPI = void 0;
|
|
@@ -39,10 +40,71 @@ class AuthAPI {
|
|
|
39
40
|
/**
|
|
40
41
|
* Refresh access token
|
|
41
42
|
*/
|
|
42
|
-
async refresh(
|
|
43
|
-
const payload = { refresh_token
|
|
43
|
+
async refresh(refresh_token) {
|
|
44
|
+
const payload = { refresh_token };
|
|
44
45
|
const response = await this.client.post('/auth/refresh', payload);
|
|
45
46
|
return response.data;
|
|
46
47
|
}
|
|
48
|
+
// ==========================================
|
|
49
|
+
// TOTP (Two-Factor Authentication) Methods
|
|
50
|
+
// ==========================================
|
|
51
|
+
/**
|
|
52
|
+
* Setup TOTP for user account
|
|
53
|
+
* Returns QR code and backup codes
|
|
54
|
+
*/
|
|
55
|
+
async setupTotp(serviceName) {
|
|
56
|
+
const response = await this.client.post('/auth/totp/setup', {
|
|
57
|
+
service_name: serviceName || 'Win Portal',
|
|
58
|
+
});
|
|
59
|
+
return response.data;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Verify TOTP setup with a token from authenticator app
|
|
63
|
+
*/
|
|
64
|
+
async verifyTotpSetup(token) {
|
|
65
|
+
const response = await this.client.post('/auth/totp/verify-setup', { token });
|
|
66
|
+
return response.data;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get TOTP status for current user
|
|
70
|
+
*/
|
|
71
|
+
async getTotpStatus() {
|
|
72
|
+
const response = await this.client.get('/auth/totp/status');
|
|
73
|
+
return response.data;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Verify TOTP code (for general verification when already logged in)
|
|
77
|
+
*/
|
|
78
|
+
async verifyTotp(token) {
|
|
79
|
+
const response = await this.client.post('/auth/totp/verify', { token });
|
|
80
|
+
return response.data;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Verify TOTP code after login (2-step authentication)
|
|
84
|
+
* Use this when login returns totp_required: true
|
|
85
|
+
*/
|
|
86
|
+
async verifyTotpLogin(token, backupCode, tempToken) {
|
|
87
|
+
const response = await this.client.post('/auth/login/verify-totp', {
|
|
88
|
+
token,
|
|
89
|
+
backup_code: backupCode,
|
|
90
|
+
temp_token: tempToken,
|
|
91
|
+
});
|
|
92
|
+
return response.data;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Disable TOTP for current user
|
|
96
|
+
*/
|
|
97
|
+
async disableTotp() {
|
|
98
|
+
const response = await this.client.delete('/auth/totp');
|
|
99
|
+
return response.data;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Regenerate backup codes
|
|
103
|
+
* Old backup codes will be invalidated
|
|
104
|
+
*/
|
|
105
|
+
async regenerateTotpBackupCodes() {
|
|
106
|
+
const response = await this.client.post('/auth/totp/regenerate-backup-codes');
|
|
107
|
+
return response.data;
|
|
108
|
+
}
|
|
47
109
|
}
|
|
48
110
|
exports.AuthAPI = AuthAPI;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { AuthClient } from '../auth-client';
|
|
3
|
-
import {
|
|
3
|
+
import { File, FileUpdateData, FileSearchParams } from '../../types';
|
|
4
4
|
/**
|
|
5
5
|
* Files API
|
|
6
6
|
* Methods for file management operations
|
|
@@ -13,12 +13,12 @@ export declare class FilesAPI {
|
|
|
13
13
|
* POST /files - อัปโหลดไฟล์ใหม่
|
|
14
14
|
* Supports both authenticated and anonymous uploads
|
|
15
15
|
*/
|
|
16
|
-
upload(formData: FormData): Promise<
|
|
16
|
+
upload(formData: FormData): Promise<File>;
|
|
17
17
|
/**
|
|
18
18
|
* GET /files/:id - ดูข้อมูลไฟล์
|
|
19
19
|
* Public access (supports both authenticated and anonymous)
|
|
20
20
|
*/
|
|
21
|
-
getById(id: string): Promise<
|
|
21
|
+
getById(id: string): Promise<File>;
|
|
22
22
|
/**
|
|
23
23
|
* GET /files/:id/content - ดึง file content (รูปภาพ, เอกสาร)
|
|
24
24
|
* Returns the actual file content or redirects to cloud storage URL
|
|
@@ -29,7 +29,7 @@ export declare class FilesAPI {
|
|
|
29
29
|
* PUT /files/:id - อัปเดตข้อมูลไฟล์
|
|
30
30
|
* Requires authentication
|
|
31
31
|
*/
|
|
32
|
-
update(id: string, updateData:
|
|
32
|
+
update(id: string, updateData: FileUpdateData): Promise<File>;
|
|
33
33
|
/**
|
|
34
34
|
* DELETE /files/:id - ลบไฟล์
|
|
35
35
|
* Requires authentication
|
|
@@ -42,7 +42,7 @@ export declare class FilesAPI {
|
|
|
42
42
|
* Public access (supports both authenticated and anonymous)
|
|
43
43
|
*/
|
|
44
44
|
search(searchParams?: FileSearchParams): Promise<{
|
|
45
|
-
data:
|
|
45
|
+
data: File[];
|
|
46
46
|
total: number;
|
|
47
47
|
page: number;
|
|
48
48
|
page_size: number;
|
|
@@ -1 +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,
|
|
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,IAAI,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAErE;;;;GAIG;AACH,qBAAa,QAAQ;IACP,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,UAAU;IAEtC;;;OAGG;IACG,MAAM,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAS/C;;;OAGG;IACG,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKxC;;;;OAIG;IACH,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM;IAKjC;;;OAGG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAKnE;;;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,IAAI,EAAE,CAAC;QACb,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"}
|
|
@@ -8,4 +8,9 @@ export { HealthAPI } from './health.api';
|
|
|
8
8
|
export { SystemConfigAPI } from './system-config.api';
|
|
9
9
|
export { FilesAPI } from './files.api';
|
|
10
10
|
export { EventLogApi } from './event-log.api';
|
|
11
|
+
export { OAuthAPI } from './oauth.api';
|
|
12
|
+
export type { OAuthConfig, AuthorizationUrlOptions, TokenResponse, UserInfo, DiscoveryDocument } from './oauth.api';
|
|
13
|
+
export { generatePKCE, generateState } from './oauth.api';
|
|
14
|
+
export { LineAPI } from './line.api';
|
|
15
|
+
export type { SendTextMessageRequest, SendStickerRequest, SendImageRequest, SendMessagesRequest, SendNotificationRequest, LineMessagePayload, LineMessageResponse, LineMessagingAvailabilityResponse, } from './line.api';
|
|
11
16
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +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"}
|
|
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;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,YAAY,EAAE,WAAW,EAAE,uBAAuB,EAAE,aAAa,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACpH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,YAAY,EACV,sBAAsB,EACtB,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,EACnB,iCAAiC,GAClC,MAAM,YAAY,CAAC"}
|
package/dist/client/api/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Central export point for all API namespaces
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.EventLogApi = exports.FilesAPI = exports.SystemConfigAPI = exports.HealthAPI = exports.AuthAPI = void 0;
|
|
8
|
+
exports.LineAPI = exports.generateState = exports.generatePKCE = exports.OAuthAPI = exports.EventLogApi = exports.FilesAPI = exports.SystemConfigAPI = exports.HealthAPI = exports.AuthAPI = void 0;
|
|
9
9
|
var auth_api_1 = require("./auth.api");
|
|
10
10
|
Object.defineProperty(exports, "AuthAPI", { enumerable: true, get: function () { return auth_api_1.AuthAPI; } });
|
|
11
11
|
var health_api_1 = require("./health.api");
|
|
@@ -16,3 +16,10 @@ var files_api_1 = require("./files.api");
|
|
|
16
16
|
Object.defineProperty(exports, "FilesAPI", { enumerable: true, get: function () { return files_api_1.FilesAPI; } });
|
|
17
17
|
var event_log_api_1 = require("./event-log.api");
|
|
18
18
|
Object.defineProperty(exports, "EventLogApi", { enumerable: true, get: function () { return event_log_api_1.EventLogApi; } });
|
|
19
|
+
var oauth_api_1 = require("./oauth.api");
|
|
20
|
+
Object.defineProperty(exports, "OAuthAPI", { enumerable: true, get: function () { return oauth_api_1.OAuthAPI; } });
|
|
21
|
+
var oauth_api_2 = require("./oauth.api");
|
|
22
|
+
Object.defineProperty(exports, "generatePKCE", { enumerable: true, get: function () { return oauth_api_2.generatePKCE; } });
|
|
23
|
+
Object.defineProperty(exports, "generateState", { enumerable: true, get: function () { return oauth_api_2.generateState; } });
|
|
24
|
+
var line_api_1 = require("./line.api");
|
|
25
|
+
Object.defineProperty(exports, "LineAPI", { enumerable: true, get: function () { return line_api_1.LineAPI; } });
|