win-portal-auth-sdk 1.3.0 → 1.4.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 +80 -7
- package/dist/client/auth-client.d.ts +97 -2
- package/dist/client/auth-client.d.ts.map +1 -1
- package/dist/client/auth-client.js +276 -30
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -2
- package/dist/nestjs/decorators/current-token.decorator.d.ts +29 -0
- package/dist/nestjs/decorators/current-token.decorator.d.ts.map +1 -0
- package/dist/nestjs/decorators/current-token.decorator.js +36 -0
- package/dist/nestjs/decorators/current-user.decorator.d.ts +26 -0
- package/dist/nestjs/decorators/current-user.decorator.d.ts.map +1 -0
- package/dist/nestjs/decorators/current-user.decorator.js +33 -0
- package/dist/nestjs/decorators/index.d.ts +9 -0
- package/dist/nestjs/decorators/index.d.ts.map +1 -0
- package/dist/nestjs/decorators/index.js +15 -0
- package/dist/nestjs/decorators/public.decorator.d.ts +31 -0
- package/dist/nestjs/decorators/public.decorator.d.ts.map +1 -0
- package/dist/nestjs/decorators/public.decorator.js +36 -0
- package/dist/nestjs/guards/index.d.ts +7 -0
- package/dist/nestjs/guards/index.d.ts.map +1 -0
- package/dist/nestjs/guards/index.js +11 -0
- package/dist/nestjs/guards/oauth-auth.guard.d.ts +139 -0
- package/dist/nestjs/guards/oauth-auth.guard.d.ts.map +1 -0
- package/dist/nestjs/guards/oauth-auth.guard.js +257 -0
- package/dist/nestjs/index.d.ts +28 -0
- package/dist/nestjs/index.d.ts.map +1 -0
- package/dist/nestjs/index.js +47 -0
- package/dist/nestjs/middleware/index.d.ts +7 -0
- package/dist/nestjs/middleware/index.d.ts.map +1 -0
- package/dist/nestjs/middleware/index.js +11 -0
- package/dist/nestjs/middleware/request-context.middleware.d.ts +62 -0
- package/dist/nestjs/middleware/request-context.middleware.d.ts.map +1 -0
- package/dist/nestjs/middleware/request-context.middleware.js +122 -0
- package/dist/nestjs/types/request-context.types.d.ts +69 -0
- package/dist/nestjs/types/request-context.types.d.ts.map +1 -0
- package/dist/nestjs/types/request-context.types.js +33 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/logger.d.ts +23 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +49 -0
- package/package.json +41 -3
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request Context Middleware
|
|
3
|
+
*
|
|
4
|
+
* Optional middleware for managing request context with RequestContextService.
|
|
5
|
+
* This middleware creates a request context with requestId, ipAddress, userAgent,
|
|
6
|
+
* and runs the request within AsyncLocalStorage context.
|
|
7
|
+
*
|
|
8
|
+
* Note: This middleware requires RequestContextService to be available in the application.
|
|
9
|
+
* If RequestContextService is not available, the middleware will still work but
|
|
10
|
+
* won't set up the context.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // In your AppModule
|
|
15
|
+
* import { RequestContextMiddleware } from 'win-portal-auth-sdk/nestjs';
|
|
16
|
+
*
|
|
17
|
+
* @Module({})
|
|
18
|
+
* export class AppModule implements NestModule {
|
|
19
|
+
* configure(consumer: MiddlewareConsumer) {
|
|
20
|
+
* consumer.apply(RequestContextMiddleware).forRoutes('*');
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Request Context Middleware Class
|
|
27
|
+
*
|
|
28
|
+
* Creates request context and runs request within AsyncLocalStorage context.
|
|
29
|
+
*/
|
|
30
|
+
export declare class RequestContextMiddleware {
|
|
31
|
+
/**
|
|
32
|
+
* Generate request ID
|
|
33
|
+
* Uses uuid v4 if available, otherwise generates a simple ID
|
|
34
|
+
*/
|
|
35
|
+
private generateRequestId;
|
|
36
|
+
/**
|
|
37
|
+
* Get client IP address from request
|
|
38
|
+
*/
|
|
39
|
+
private getClientIP;
|
|
40
|
+
/**
|
|
41
|
+
* Middleware handler
|
|
42
|
+
*/
|
|
43
|
+
use(req: any, res: any, next: () => void): void;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Factory function to create RequestContextMiddleware
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* // In your AppModule
|
|
51
|
+
* import { createRequestContextMiddleware } from 'win-portal-auth-sdk/nestjs';
|
|
52
|
+
*
|
|
53
|
+
* @Module({})
|
|
54
|
+
* export class AppModule implements NestModule {
|
|
55
|
+
* configure(consumer: MiddlewareConsumer) {
|
|
56
|
+
* consumer.apply(createRequestContextMiddleware()).forRoutes('*');
|
|
57
|
+
* }
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function createRequestContextMiddleware(): RequestContextMiddleware;
|
|
62
|
+
//# sourceMappingURL=request-context.middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-context.middleware.d.ts","sourceRoot":"","sources":["../../../src/nestjs/middleware/request-context.middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH;;;;GAIG;AACH,qBAAa,wBAAwB;IACnC;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAUzB;;OAEG;IACH,OAAO,CAAC,WAAW;IAUnB;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,IAAI,GAAG,IAAI;CA2ChD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,8BAA8B,6BAE7C"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Request Context Middleware
|
|
4
|
+
*
|
|
5
|
+
* Optional middleware for managing request context with RequestContextService.
|
|
6
|
+
* This middleware creates a request context with requestId, ipAddress, userAgent,
|
|
7
|
+
* and runs the request within AsyncLocalStorage context.
|
|
8
|
+
*
|
|
9
|
+
* Note: This middleware requires RequestContextService to be available in the application.
|
|
10
|
+
* If RequestContextService is not available, the middleware will still work but
|
|
11
|
+
* won't set up the context.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // In your AppModule
|
|
16
|
+
* import { RequestContextMiddleware } from 'win-portal-auth-sdk/nestjs';
|
|
17
|
+
*
|
|
18
|
+
* @Module({})
|
|
19
|
+
* export class AppModule implements NestModule {
|
|
20
|
+
* configure(consumer: MiddlewareConsumer) {
|
|
21
|
+
* consumer.apply(RequestContextMiddleware).forRoutes('*');
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.createRequestContextMiddleware = exports.RequestContextMiddleware = void 0;
|
|
28
|
+
const request_context_types_1 = require("../types/request-context.types");
|
|
29
|
+
/**
|
|
30
|
+
* Request Context Middleware Class
|
|
31
|
+
*
|
|
32
|
+
* Creates request context and runs request within AsyncLocalStorage context.
|
|
33
|
+
*/
|
|
34
|
+
class RequestContextMiddleware {
|
|
35
|
+
/**
|
|
36
|
+
* Generate request ID
|
|
37
|
+
* Uses uuid v4 if available, otherwise generates a simple ID
|
|
38
|
+
*/
|
|
39
|
+
generateRequestId() {
|
|
40
|
+
try {
|
|
41
|
+
const { v4: uuidv4 } = require('uuid');
|
|
42
|
+
return uuidv4();
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// Fallback if uuid is not available
|
|
46
|
+
return `req-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get client IP address from request
|
|
51
|
+
*/
|
|
52
|
+
getClientIP(req) {
|
|
53
|
+
return (req.headers['x-forwarded-for']?.split(',')[0]?.trim() ||
|
|
54
|
+
req.headers['x-real-ip'] ||
|
|
55
|
+
req.connection?.remoteAddress ||
|
|
56
|
+
req.socket?.remoteAddress ||
|
|
57
|
+
'127.0.0.1');
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Middleware handler
|
|
61
|
+
*/
|
|
62
|
+
use(req, res, next) {
|
|
63
|
+
const requestId = this.generateRequestId();
|
|
64
|
+
const ipAddress = this.getClientIP(req);
|
|
65
|
+
const userAgent = req.get('user-agent') || req.headers['user-agent'] || 'Unknown';
|
|
66
|
+
const origin = req.get('origin') || req.get('referer');
|
|
67
|
+
// Set request ID in response headers for debugging
|
|
68
|
+
if (res && typeof res.setHeader === 'function') {
|
|
69
|
+
res.setHeader('X-Request-ID', requestId);
|
|
70
|
+
}
|
|
71
|
+
// Store context in request object
|
|
72
|
+
const requestContext = {
|
|
73
|
+
requestId,
|
|
74
|
+
ipAddress,
|
|
75
|
+
userAgent,
|
|
76
|
+
origin,
|
|
77
|
+
method: req.method,
|
|
78
|
+
url: req.url,
|
|
79
|
+
timestamp: new Date(),
|
|
80
|
+
};
|
|
81
|
+
// Attach to request object
|
|
82
|
+
req.requestContext = requestContext;
|
|
83
|
+
// Try to use RequestContextService if available
|
|
84
|
+
const requestContextService = (0, request_context_types_1.getRequestContextService)();
|
|
85
|
+
if (requestContextService) {
|
|
86
|
+
try {
|
|
87
|
+
// Run the entire request pipeline within AsyncLocalStorage context
|
|
88
|
+
requestContextService.runWithContext(req, () => {
|
|
89
|
+
next();
|
|
90
|
+
});
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
// RequestContextService not available or error
|
|
95
|
+
// Continue without it
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// If RequestContextService is not available, just continue
|
|
99
|
+
next();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.RequestContextMiddleware = RequestContextMiddleware;
|
|
103
|
+
/**
|
|
104
|
+
* Factory function to create RequestContextMiddleware
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* // In your AppModule
|
|
109
|
+
* import { createRequestContextMiddleware } from 'win-portal-auth-sdk/nestjs';
|
|
110
|
+
*
|
|
111
|
+
* @Module({})
|
|
112
|
+
* export class AppModule implements NestModule {
|
|
113
|
+
* configure(consumer: MiddlewareConsumer) {
|
|
114
|
+
* consumer.apply(createRequestContextMiddleware()).forRoutes('*');
|
|
115
|
+
* }
|
|
116
|
+
* }
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
function createRequestContextMiddleware() {
|
|
120
|
+
return new RequestContextMiddleware();
|
|
121
|
+
}
|
|
122
|
+
exports.createRequestContextMiddleware = createRequestContextMiddleware;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request Context Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for optional RequestContextService integration
|
|
5
|
+
* These types allow SDK components to work with RequestContextService
|
|
6
|
+
* if it's available in the application, without requiring it as a dependency.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Request Context Data Interface
|
|
10
|
+
*
|
|
11
|
+
* Matches the structure used by RequestContextService in applications
|
|
12
|
+
*/
|
|
13
|
+
export interface RequestContextData {
|
|
14
|
+
requestId: string;
|
|
15
|
+
ipAddress: string;
|
|
16
|
+
userAgent: string;
|
|
17
|
+
origin?: string;
|
|
18
|
+
userId?: string;
|
|
19
|
+
userEmail?: string;
|
|
20
|
+
sessionId?: string;
|
|
21
|
+
method: string;
|
|
22
|
+
url: string;
|
|
23
|
+
timestamp: Date;
|
|
24
|
+
authToken?: string;
|
|
25
|
+
permissions?: string[];
|
|
26
|
+
roles?: Array<{
|
|
27
|
+
id: string;
|
|
28
|
+
name: string;
|
|
29
|
+
}>;
|
|
30
|
+
roleCodes?: string[];
|
|
31
|
+
applicationId?: string;
|
|
32
|
+
applicationName?: string;
|
|
33
|
+
apiKeyId?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Optional RequestContextService Interface
|
|
37
|
+
*
|
|
38
|
+
* This interface represents the static methods available on RequestContextService
|
|
39
|
+
* that SDK components can use if the service is available.
|
|
40
|
+
*/
|
|
41
|
+
export interface RequestContextServiceInterface {
|
|
42
|
+
/**
|
|
43
|
+
* Get current request context
|
|
44
|
+
*/
|
|
45
|
+
getContext(): RequestContextData | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Run function with request context
|
|
48
|
+
*/
|
|
49
|
+
runWithContext<T>(req: any, fn: () => T): T;
|
|
50
|
+
/**
|
|
51
|
+
* Set user info in current context
|
|
52
|
+
*/
|
|
53
|
+
setUserInfo(userId: string, userEmail: string, sessionId?: string, authToken?: string): void;
|
|
54
|
+
/**
|
|
55
|
+
* Set user permissions and roles in context
|
|
56
|
+
*/
|
|
57
|
+
setUserPermissions(permissions: string[], roles: string[] | Array<{
|
|
58
|
+
id: string;
|
|
59
|
+
name: string;
|
|
60
|
+
}>): void;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Helper function to safely access RequestContextService
|
|
64
|
+
*
|
|
65
|
+
* This function checks if RequestContextService is available and returns
|
|
66
|
+
* a typed interface if it exists, or undefined if not.
|
|
67
|
+
*/
|
|
68
|
+
export declare function getRequestContextService(): RequestContextServiceInterface | undefined;
|
|
69
|
+
//# sourceMappingURL=request-context.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-context.types.d.ts","sourceRoot":"","sources":["../../../src/nestjs/types/request-context.types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,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
|
|
3
|
+
* Request Context Types
|
|
4
|
+
*
|
|
5
|
+
* Type definitions for optional RequestContextService integration
|
|
6
|
+
* These types allow SDK components to work with RequestContextService
|
|
7
|
+
* if it's available in the application, without requiring it as a dependency.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.getRequestContextService = void 0;
|
|
11
|
+
/**
|
|
12
|
+
* Helper function to safely access RequestContextService
|
|
13
|
+
*
|
|
14
|
+
* This function checks if RequestContextService is available and returns
|
|
15
|
+
* a typed interface if it exists, or undefined if not.
|
|
16
|
+
*/
|
|
17
|
+
function getRequestContextService() {
|
|
18
|
+
// Try to access RequestContextService from global scope or module
|
|
19
|
+
// This is a safe way to check if the service exists without requiring it
|
|
20
|
+
try {
|
|
21
|
+
// Check if RequestContextService exists in the runtime
|
|
22
|
+
// Applications that use RequestContextService will have it available
|
|
23
|
+
const RequestContextService = global.RequestContextService;
|
|
24
|
+
if (RequestContextService && typeof RequestContextService.setUserInfo === 'function') {
|
|
25
|
+
return RequestContextService;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// RequestContextService not available
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
exports.getRequestContextService = getRequestContextService;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -67,6 +67,24 @@ export interface AuthSdkConfig {
|
|
|
67
67
|
baseURL?: string;
|
|
68
68
|
apiKeyHeader?: string;
|
|
69
69
|
timeout?: number;
|
|
70
|
+
/**
|
|
71
|
+
* Advanced configuration options
|
|
72
|
+
* สำหรับปรับแต่ง internal behavior ของ SDK
|
|
73
|
+
*/
|
|
74
|
+
advanced?: {
|
|
75
|
+
/**
|
|
76
|
+
* Activity throttle time (milliseconds)
|
|
77
|
+
* ระยะเวลาที่ throttle activity handler เพื่อลด CPU usage
|
|
78
|
+
* Default: 1000ms (1 second)
|
|
79
|
+
*/
|
|
80
|
+
activityThrottleMs?: number;
|
|
81
|
+
/**
|
|
82
|
+
* Refresh token timeout (milliseconds)
|
|
83
|
+
* ระยะเวลาที่รอ refresh token request ก่อน timeout
|
|
84
|
+
* Default: 5000ms (5 seconds)
|
|
85
|
+
*/
|
|
86
|
+
refreshTimeoutMs?: number;
|
|
87
|
+
};
|
|
70
88
|
}
|
|
71
89
|
/**
|
|
72
90
|
* NestJS Module Configuration
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE;QACL,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,kBAAkB,CAAC;IAChC,YAAY,EAAE,mBAAmB,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IAGf,iBAAiB,EAAE,OAAO,CAAC;IAG3B,qBAAqB,EAAE,MAAM,CAAC;IAG9B,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IAGxB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC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ACrC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAGD,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AAGvC,cAAc,cAAc,CAAC;AAG7B,cAAc,cAAc,CAAC;AAG7B,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger Utility
|
|
3
|
+
*
|
|
4
|
+
* @description Centralized logging utility for Auth SDK
|
|
5
|
+
* Supports different log levels and environment-based filtering
|
|
6
|
+
*/
|
|
7
|
+
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
8
|
+
interface LoggerConfig {
|
|
9
|
+
enabled: boolean;
|
|
10
|
+
logLevel: LogLevel;
|
|
11
|
+
}
|
|
12
|
+
declare class Logger {
|
|
13
|
+
private config;
|
|
14
|
+
private shouldLog;
|
|
15
|
+
debug(...args: any[]): void;
|
|
16
|
+
info(...args: any[]): void;
|
|
17
|
+
warn(...args: any[]): void;
|
|
18
|
+
error(...args: any[]): void;
|
|
19
|
+
setConfig(config: Partial<LoggerConfig>): void;
|
|
20
|
+
}
|
|
21
|
+
export declare const logger: Logger;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,KAAK,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAEpD,UAAU,YAAY;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED,cAAM,MAAM;IACV,OAAO,CAAC,MAAM,CAGZ;IAEF,OAAO,CAAC,SAAS;IAUjB,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAM3B,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAM1B,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAM1B,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAM3B,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI;CAG/C;AAED,eAAO,MAAM,MAAM,QAAe,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Logger Utility
|
|
4
|
+
*
|
|
5
|
+
* @description Centralized logging utility for Auth SDK
|
|
6
|
+
* Supports different log levels and environment-based filtering
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.logger = void 0;
|
|
10
|
+
class Logger {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.config = {
|
|
13
|
+
enabled: true,
|
|
14
|
+
logLevel: process.env.NODE_ENV === 'production' ? 'warn' : 'debug',
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
shouldLog(level) {
|
|
18
|
+
if (!this.config.enabled)
|
|
19
|
+
return false;
|
|
20
|
+
const levels = ['debug', 'info', 'warn', 'error'];
|
|
21
|
+
const currentLevelIndex = levels.indexOf(this.config.logLevel);
|
|
22
|
+
const messageLevelIndex = levels.indexOf(level);
|
|
23
|
+
return messageLevelIndex >= currentLevelIndex;
|
|
24
|
+
}
|
|
25
|
+
debug(...args) {
|
|
26
|
+
if (this.shouldLog('debug')) {
|
|
27
|
+
console.log('[AuthClient]', ...args);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
info(...args) {
|
|
31
|
+
if (this.shouldLog('info')) {
|
|
32
|
+
console.log('[AuthClient]', ...args);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
warn(...args) {
|
|
36
|
+
if (this.shouldLog('warn')) {
|
|
37
|
+
console.warn('[AuthClient]', ...args);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
error(...args) {
|
|
41
|
+
if (this.shouldLog('error')) {
|
|
42
|
+
console.error('[AuthClient]', ...args);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
setConfig(config) {
|
|
46
|
+
this.config = { ...this.config, ...config };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.logger = new Logger();
|
package/package.json
CHANGED
|
@@ -1,9 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "win-portal-auth-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Shared authentication SDK for Win Portal applications with JWT and OAuth support",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./middleware": {
|
|
13
|
+
"types": "./dist/middleware/index.d.ts",
|
|
14
|
+
"default": "./dist/middleware/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./nestjs": {
|
|
17
|
+
"types": "./dist/nestjs/index.d.ts",
|
|
18
|
+
"default": "./dist/nestjs/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./client": {
|
|
21
|
+
"types": "./dist/client/index.d.ts",
|
|
22
|
+
"default": "./dist/client/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./types": {
|
|
25
|
+
"types": "./dist/types/index.d.ts",
|
|
26
|
+
"default": "./dist/types/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
7
29
|
"files": [
|
|
8
30
|
"dist",
|
|
9
31
|
"README.md",
|
|
@@ -47,6 +69,22 @@
|
|
|
47
69
|
"dependencies": {
|
|
48
70
|
"axios": "^1.6.0"
|
|
49
71
|
},
|
|
72
|
+
"peerDependencies": {
|
|
73
|
+
"@nestjs/common": "^10.0.0 || ^11.0.0",
|
|
74
|
+
"@nestjs/core": "^10.0.0 || ^11.0.0",
|
|
75
|
+
"uuid": "^9.0.0 || ^10.0.0"
|
|
76
|
+
},
|
|
77
|
+
"peerDependenciesMeta": {
|
|
78
|
+
"@nestjs/common": {
|
|
79
|
+
"optional": true
|
|
80
|
+
},
|
|
81
|
+
"@nestjs/core": {
|
|
82
|
+
"optional": true
|
|
83
|
+
},
|
|
84
|
+
"uuid": {
|
|
85
|
+
"optional": true
|
|
86
|
+
}
|
|
87
|
+
},
|
|
50
88
|
"devDependencies": {
|
|
51
89
|
"@types/node": "^20.0.0",
|
|
52
90
|
"typescript": "^5.3.0"
|