win-portal-auth-sdk 1.6.0 → 1.6.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/dist/client/api/system-config.api.d.ts +4 -13
- package/dist/client/api/system-config.api.d.ts.map +1 -1
- package/dist/client/api/system-config.api.js +7 -21
- package/dist/client/api/webhook.api.d.ts +17 -10
- package/dist/client/api/webhook.api.d.ts.map +1 -1
- package/dist/client/api/webhook.api.js +17 -10
- package/dist/client/auth-client.js +1 -1
- package/dist/types/webhook.types.d.ts +14 -1
- package/dist/types/webhook.types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { SessionManagementConfig, SystemConfig, SystemConfigByCategory } from '../../types';
|
|
1
2
|
import { AuthClient } from '../auth-client';
|
|
2
|
-
import { SystemConfig, SystemConfigByCategory, SecurityJwtConfig, SessionManagementConfig } from '../../types';
|
|
3
3
|
/**
|
|
4
4
|
* System Config API
|
|
5
5
|
* Methods for retrieving system configurations
|
|
@@ -12,22 +12,13 @@ export declare class SystemConfigAPI {
|
|
|
12
12
|
* GET /system-configs/categories/:category
|
|
13
13
|
* ดึง configs ตาม category - ส่ง object ที่รวมทุก key เป็น { key1: value1, key2: value2 }
|
|
14
14
|
*/
|
|
15
|
-
getByCategory
|
|
15
|
+
private getByCategory;
|
|
16
16
|
/**
|
|
17
17
|
* GET /system-configs/categories/:category/:key
|
|
18
18
|
* ดึง config ตาม category และ key - ส่ง full metadata row
|
|
19
19
|
*/
|
|
20
|
-
getByCategoryAndKey
|
|
21
|
-
|
|
22
|
-
* GET /system-configs/categories/security
|
|
23
|
-
* ดึง security configs ทั้งหมด (convenience method)
|
|
24
|
-
*/
|
|
25
|
-
security(): Promise<SystemConfigByCategory>;
|
|
26
|
-
/**
|
|
27
|
-
* GET /system-configs/categories/security/jwt
|
|
28
|
-
* ดึง JWT configuration (convenience method)
|
|
29
|
-
*/
|
|
30
|
-
getSecurityJwtConfig(): Promise<SecurityJwtConfig>;
|
|
20
|
+
private getByCategoryAndKey;
|
|
21
|
+
get(category: string, key?: string): Promise<SystemConfig | SystemConfigByCategory>;
|
|
31
22
|
/**
|
|
32
23
|
* GET /system-configs/categories/security/session-management
|
|
33
24
|
* ดึง Session Management configuration (convenience method)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system-config.api.d.ts","sourceRoot":"","sources":["../../../src/client/api/system-config.api.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"system-config.api.d.ts","sourceRoot":"","sources":["../../../src/client/api/system-config.api.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,uBAAuB,EACvB,YAAY,EACZ,sBAAsB,EACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;;;GAIG;AACH,qBAAa,eAAe;IACd,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,UAAU;IAEtC;;;OAGG;YACW,aAAa;IAO3B;;;OAGG;YACW,mBAAmB;IAK3B,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,sBAAsB,CAAC;IAOzF;;;OAGG;IACG,oBAAoB,IAAI,OAAO,CAAC,uBAAuB,CAAC;CAI/D"}
|
|
@@ -26,33 +26,19 @@ class SystemConfigAPI {
|
|
|
26
26
|
const response = await this.client.get(`/system-configs/categories/${category}/${key}`);
|
|
27
27
|
return response.data.data;
|
|
28
28
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return this.getByCategory('security');
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* GET /system-configs/categories/security/jwt
|
|
38
|
-
* ดึง JWT configuration (convenience method)
|
|
39
|
-
*/
|
|
40
|
-
async getSecurityJwtConfig() {
|
|
41
|
-
const config = await this.getByCategoryAndKey('security', 'jwt');
|
|
42
|
-
return config.value;
|
|
29
|
+
async get(category, key) {
|
|
30
|
+
if (key) {
|
|
31
|
+
return await this.getByCategoryAndKey(category, key);
|
|
32
|
+
}
|
|
33
|
+
return await this.getByCategory(category);
|
|
43
34
|
}
|
|
44
35
|
/**
|
|
45
36
|
* GET /system-configs/categories/security/session-management
|
|
46
37
|
* ดึง Session Management configuration (convenience method)
|
|
47
38
|
*/
|
|
48
39
|
async getSessionManagement() {
|
|
49
|
-
const securityConfigs = await this.security
|
|
50
|
-
|
|
51
|
-
const sessionManagement = securityConfigs['session_management'] || securityConfigs['session-management'];
|
|
52
|
-
if (!sessionManagement) {
|
|
53
|
-
throw new Error('Session management configuration not found');
|
|
54
|
-
}
|
|
55
|
-
return sessionManagement;
|
|
40
|
+
const securityConfigs = await this.get('security', 'session_management');
|
|
41
|
+
return securityConfigs.value;
|
|
56
42
|
}
|
|
57
43
|
}
|
|
58
44
|
exports.SystemConfigAPI = SystemConfigAPI;
|
|
@@ -19,10 +19,11 @@ export declare class WebhookAPI {
|
|
|
19
19
|
* - ส่ง webhook request ไปยัง external URL ผ่านระบบ proxy
|
|
20
20
|
* - ระบบจะสร้าง webhook_log และยิง webhook ออกไปให้
|
|
21
21
|
* - รองรับ retry mechanism อัตโนมัติ
|
|
22
|
+
* - ส่ง async: true เพื่อยิงทันทีและรับ result (http_status, response_body) ใน response
|
|
22
23
|
*
|
|
23
24
|
* @example
|
|
24
25
|
* ```typescript
|
|
25
|
-
* // ส่ง webhook request
|
|
26
|
+
* // ส่ง webhook request (โหมดปกติ - ได้ webhook_log_id กลับมา แล้วค่อย getStatus ตรวจสอบ)
|
|
26
27
|
* const result = await authClient.webhook.proxy({
|
|
27
28
|
* webhook_url: 'https://api.example.com/webhooks/users',
|
|
28
29
|
* event_type: 'user.created',
|
|
@@ -31,21 +32,27 @@ export declare class WebhookAPI {
|
|
|
31
32
|
* object: 'event',
|
|
32
33
|
* type: 'user.created'
|
|
33
34
|
* },
|
|
34
|
-
* headers: {
|
|
35
|
-
* 'Authorization': 'Bearer token'
|
|
36
|
-
* },
|
|
35
|
+
* headers: { 'Authorization': 'Bearer token' },
|
|
37
36
|
* secret: 'webhook-secret',
|
|
38
37
|
* timeout_ms: 30000,
|
|
39
38
|
* max_retries: 3
|
|
40
39
|
* });
|
|
41
|
-
*
|
|
42
40
|
* console.log('Webhook Log ID:', result.webhook_log_id);
|
|
43
|
-
* console.log('Status:', result.status);
|
|
44
41
|
*
|
|
45
|
-
* //
|
|
46
|
-
* const
|
|
47
|
-
*
|
|
48
|
-
*
|
|
42
|
+
* // โหมด async: true - ยิงทันทีและได้ result กลับใน response (ไม่ต้อง getStatus)
|
|
43
|
+
* const resultAsync = await authClient.webhook.proxy({
|
|
44
|
+
* webhook_url: 'https://api.example.com/webhooks/users',
|
|
45
|
+
* event_type: 'user.created',
|
|
46
|
+
* payload: { data: { id: 'user-123' }, object: 'event', type: 'user.created' },
|
|
47
|
+
* async: true
|
|
48
|
+
* });
|
|
49
|
+
* if (resultAsync.status === 'success') {
|
|
50
|
+
* console.log('HTTP Status:', resultAsync.http_status);
|
|
51
|
+
* console.log('Response Body:', resultAsync.response_body);
|
|
52
|
+
* console.log('Execution Time:', resultAsync.execution_time_ms, 'ms');
|
|
53
|
+
* } else {
|
|
54
|
+
* console.error('Failed:', resultAsync.error_message);
|
|
55
|
+
* }
|
|
49
56
|
* ```
|
|
50
57
|
*/
|
|
51
58
|
proxy(request: WebhookProxyRequest): Promise<WebhookProxyResponse>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhook.api.d.ts","sourceRoot":"","sources":["../../../src/client/api/webhook.api.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7G,qBAAa,UAAU;IACT,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,UAAU;IAEtC
|
|
1
|
+
{"version":3,"file":"webhook.api.d.ts","sourceRoot":"","sources":["../../../src/client/api/webhook.api.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7G,qBAAa,UAAU;IACT,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,UAAU;IAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA0CG;IACG,KAAK,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAKxE;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACG,SAAS,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAIjE"}
|
|
@@ -21,10 +21,11 @@ class WebhookAPI {
|
|
|
21
21
|
* - ส่ง webhook request ไปยัง external URL ผ่านระบบ proxy
|
|
22
22
|
* - ระบบจะสร้าง webhook_log และยิง webhook ออกไปให้
|
|
23
23
|
* - รองรับ retry mechanism อัตโนมัติ
|
|
24
|
+
* - ส่ง async: true เพื่อยิงทันทีและรับ result (http_status, response_body) ใน response
|
|
24
25
|
*
|
|
25
26
|
* @example
|
|
26
27
|
* ```typescript
|
|
27
|
-
* // ส่ง webhook request
|
|
28
|
+
* // ส่ง webhook request (โหมดปกติ - ได้ webhook_log_id กลับมา แล้วค่อย getStatus ตรวจสอบ)
|
|
28
29
|
* const result = await authClient.webhook.proxy({
|
|
29
30
|
* webhook_url: 'https://api.example.com/webhooks/users',
|
|
30
31
|
* event_type: 'user.created',
|
|
@@ -33,21 +34,27 @@ class WebhookAPI {
|
|
|
33
34
|
* object: 'event',
|
|
34
35
|
* type: 'user.created'
|
|
35
36
|
* },
|
|
36
|
-
* headers: {
|
|
37
|
-
* 'Authorization': 'Bearer token'
|
|
38
|
-
* },
|
|
37
|
+
* headers: { 'Authorization': 'Bearer token' },
|
|
39
38
|
* secret: 'webhook-secret',
|
|
40
39
|
* timeout_ms: 30000,
|
|
41
40
|
* max_retries: 3
|
|
42
41
|
* });
|
|
43
|
-
*
|
|
44
42
|
* console.log('Webhook Log ID:', result.webhook_log_id);
|
|
45
|
-
* console.log('Status:', result.status);
|
|
46
43
|
*
|
|
47
|
-
* //
|
|
48
|
-
* const
|
|
49
|
-
*
|
|
50
|
-
*
|
|
44
|
+
* // โหมด async: true - ยิงทันทีและได้ result กลับใน response (ไม่ต้อง getStatus)
|
|
45
|
+
* const resultAsync = await authClient.webhook.proxy({
|
|
46
|
+
* webhook_url: 'https://api.example.com/webhooks/users',
|
|
47
|
+
* event_type: 'user.created',
|
|
48
|
+
* payload: { data: { id: 'user-123' }, object: 'event', type: 'user.created' },
|
|
49
|
+
* async: true
|
|
50
|
+
* });
|
|
51
|
+
* if (resultAsync.status === 'success') {
|
|
52
|
+
* console.log('HTTP Status:', resultAsync.http_status);
|
|
53
|
+
* console.log('Response Body:', resultAsync.response_body);
|
|
54
|
+
* console.log('Execution Time:', resultAsync.execution_time_ms, 'ms');
|
|
55
|
+
* } else {
|
|
56
|
+
* console.error('Failed:', resultAsync.error_message);
|
|
57
|
+
* }
|
|
51
58
|
* ```
|
|
52
59
|
*/
|
|
53
60
|
async proxy(request) {
|
|
@@ -432,7 +432,7 @@ class AuthClient {
|
|
|
432
432
|
*/
|
|
433
433
|
async performJwtConfigLoad() {
|
|
434
434
|
try {
|
|
435
|
-
const config = await this.systemConfig.
|
|
435
|
+
const config = (await this.systemConfig.get('security', 'jwt')).value;
|
|
436
436
|
this.refreshThresholdMinutes = config.refresh_threshold_minutes;
|
|
437
437
|
this.automaticRefreshEnabled = config.automatic_refresh ?? true;
|
|
438
438
|
logger_1.logger.debug(`JWT config loaded: refresh_threshold_minutes=${this.refreshThresholdMinutes} minutes, automatic_refresh=${this.automaticRefreshEnabled}`);
|
|
@@ -22,10 +22,13 @@ export interface WebhookProxyRequest {
|
|
|
22
22
|
timeout_ms?: number;
|
|
23
23
|
/** จำนวนครั้งสูงสุดที่จะ retry */
|
|
24
24
|
max_retries?: number;
|
|
25
|
+
/** ถ้า true = ยิงทันทีและส่ง result (http_status, response_body) กลับใน response */
|
|
26
|
+
async?: boolean;
|
|
25
27
|
}
|
|
26
28
|
/**
|
|
27
29
|
* Webhook Proxy Response
|
|
28
30
|
* Response หลังจากส่ง webhook request
|
|
31
|
+
* เมื่อส่ง async: true จะมี http_status, response_body, execution_time_ms (และ error_message ถ้าล้มเหลว)
|
|
29
32
|
*/
|
|
30
33
|
export interface WebhookProxyResponse {
|
|
31
34
|
/** รหัส webhook log ที่สร้างขึ้น */
|
|
@@ -34,6 +37,14 @@ export interface WebhookProxyResponse {
|
|
|
34
37
|
status: 'pending' | 'success' | 'failed' | 'retrying';
|
|
35
38
|
/** ข้อความอธิบาย */
|
|
36
39
|
message: string;
|
|
40
|
+
/** HTTP status จากปลายทาง (เมื่อ async=true) */
|
|
41
|
+
http_status?: number;
|
|
42
|
+
/** Response body จากปลายทาง (เมื่อ async=true) */
|
|
43
|
+
response_body?: unknown;
|
|
44
|
+
/** เวลาที่ใช้ส่ง request มิลลิวินาที (เมื่อ async=true) */
|
|
45
|
+
execution_time_ms?: number;
|
|
46
|
+
/** ข้อความ error (เมื่อ async=true และล้มเหลว) */
|
|
47
|
+
error_message?: string;
|
|
37
48
|
}
|
|
38
49
|
/**
|
|
39
50
|
* Webhook Log Detail
|
|
@@ -58,8 +69,10 @@ export interface WebhookLogDetail {
|
|
|
58
69
|
status: 'pending' | 'success' | 'failed' | 'retrying';
|
|
59
70
|
/** HTTP status code ที่ได้รับกลับมา */
|
|
60
71
|
http_status?: number;
|
|
61
|
-
/**
|
|
72
|
+
/** HTTP request headers จาก external ที่เรียกเข้ามา */
|
|
62
73
|
request_headers?: Record<string, string>;
|
|
74
|
+
/** Headers ที่จะใช้ส่งไปกับ axios (จาก DTO หรือ webhook config) */
|
|
75
|
+
headers?: Record<string, string>;
|
|
63
76
|
/** Headers ที่ได้รับกลับมาจาก response */
|
|
64
77
|
response_headers?: Record<string, string>;
|
|
65
78
|
/** Response body ที่ได้รับกลับมา */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhook.types.d.ts","sourceRoot":"","sources":["../../src/types/webhook.types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,qCAAqC;IACrC,WAAW,EAAE,MAAM,CAAC;IAEpB,sBAAsB;IACtB,UAAU,EAAE,MAAM,CAAC;IAEnB,yBAAyB;IACzB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE7B,yCAAyC;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjC,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,8CAA8C;IAC9C,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,kCAAkC;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"webhook.types.d.ts","sourceRoot":"","sources":["../../src/types/webhook.types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,qCAAqC;IACrC,WAAW,EAAE,MAAM,CAAC;IAEpB,sBAAsB;IACtB,UAAU,EAAE,MAAM,CAAC;IAEnB,yBAAyB;IACzB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE7B,yCAAyC;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjC,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,8CAA8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