win-portal-auth-sdk 1.5.0 → 1.5.1

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.
Files changed (35) hide show
  1. package/dist/client/api/auth.api.d.ts +14 -3
  2. package/dist/client/api/auth.api.d.ts.map +1 -1
  3. package/dist/client/api/auth.api.js +12 -4
  4. package/dist/client/auth-client.d.ts +16 -5
  5. package/dist/client/auth-client.d.ts.map +1 -1
  6. package/dist/client/auth-client.js +70 -44
  7. package/dist/middleware/express.middleware.d.ts +1 -1
  8. package/dist/middleware/express.middleware.d.ts.map +1 -1
  9. package/dist/middleware/express.middleware.js +19 -92
  10. package/dist/middleware/nestjs.guard.d.ts.map +1 -1
  11. package/dist/middleware/nestjs.guard.js +24 -114
  12. package/dist/middleware/shared/auth-service.d.ts +36 -0
  13. package/dist/middleware/shared/auth-service.d.ts.map +1 -0
  14. package/dist/middleware/shared/auth-service.js +98 -0
  15. package/dist/middleware/shared/index.d.ts +7 -0
  16. package/dist/middleware/shared/index.d.ts.map +1 -0
  17. package/dist/middleware/shared/index.js +22 -0
  18. package/dist/middleware/shared/token-extractor.d.ts +15 -0
  19. package/dist/middleware/shared/token-extractor.d.ts.map +1 -0
  20. package/dist/middleware/shared/token-extractor.js +47 -0
  21. package/dist/middleware/shared/user-cache.d.ts +51 -0
  22. package/dist/middleware/shared/user-cache.d.ts.map +1 -0
  23. package/dist/middleware/shared/user-cache.js +81 -0
  24. package/dist/types/event-log.types.d.ts +103 -1
  25. package/dist/types/event-log.types.d.ts.map +1 -1
  26. package/dist/types/event-log.types.js +5 -1
  27. package/dist/types/index.d.ts +30 -29
  28. package/dist/types/index.d.ts.map +1 -1
  29. package/dist/types/index.js +7 -3
  30. package/dist/types/system-config.types.d.ts +2 -5
  31. package/dist/types/system-config.types.d.ts.map +1 -1
  32. package/package.json +1 -1
  33. package/dist/types/event-log.interfaces.d.ts +0 -108
  34. package/dist/types/event-log.interfaces.d.ts.map +0 -1
  35. package/dist/types/event-log.interfaces.js +0 -7
@@ -6,8 +6,8 @@
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.clearNestAuthCache = exports.createOptionalAuthGuard = exports.createAuthGuard = void 0;
9
- const client_1 = require("../client");
10
- const userCache = new Map();
9
+ const auth_service_1 = require("./shared/auth-service");
10
+ const user_cache_1 = require("./shared/user-cache");
11
11
  /**
12
12
  * NestJS Auth Guard
13
13
  *
@@ -30,69 +30,23 @@ const userCache = new Map();
30
30
  * ```
31
31
  */
32
32
  function createAuthGuard(config) {
33
- const client = new client_1.AuthClient({
34
- baseURL: config.baseURL,
35
- apiKey: config.apiKey,
36
- apiKeyHeader: config.apiKeyHeader,
33
+ const authService = new auth_service_1.AuthService({
34
+ ...config,
35
+ optional: false,
37
36
  });
38
- const cacheTimeout = (config.cacheTimeout || 300) * 1000;
39
- const tokenStrategy = config.tokenStrategy || 'bearer';
40
- const cookieName = config.cookieName || 'access_token';
41
37
  class AuthGuard {
42
38
  async canActivate(context) {
43
39
  const request = context.switchToHttp().getRequest();
44
- // Extract token
45
- let token = null;
46
- if (config.tokenExtractor) {
47
- token = config.tokenExtractor(request);
48
- }
49
- else if (tokenStrategy === 'bearer') {
50
- const authHeader = request.headers.authorization;
51
- if (authHeader && authHeader.startsWith('Bearer ')) {
52
- token = authHeader.substring(7);
53
- }
54
- }
55
- else if (tokenStrategy === 'cookie') {
56
- token = request.cookies?.[cookieName] || null;
57
- }
58
- if (!token) {
59
- return false;
60
- }
61
- try {
62
- // Check cache first
63
- const cached = userCache.get(token);
64
- if (cached && Date.now() - cached.timestamp < cacheTimeout) {
65
- request.user = cached.user;
66
- request.token = token;
67
- return true;
68
- }
69
- // Fetch user profile
70
- client.setToken(token);
71
- const user = await client.auth.profile();
72
- // Update cache
73
- userCache.set(token, {
74
- user,
75
- timestamp: Date.now(),
76
- });
77
- // Clean up old cache entries
78
- if (userCache.size > 1000) {
79
- const now = Date.now();
80
- const entries = Array.from(userCache.entries());
81
- for (const [key, entry] of entries) {
82
- if (now - entry.timestamp > cacheTimeout) {
83
- userCache.delete(key);
84
- }
85
- }
86
- }
87
- // Attach user to request
88
- request.user = user;
89
- request.token = token;
90
- return true;
91
- }
92
- catch (error) {
93
- userCache.delete(token);
40
+ // Authenticate request
41
+ const result = await authService.authenticate(request);
42
+ // Return false if authentication failed
43
+ if (result.error || !result.user || !result.token) {
94
44
  return false;
95
45
  }
46
+ // Attach user and token to request
47
+ request.user = result.user;
48
+ request.token = result.token;
49
+ return true;
96
50
  }
97
51
  }
98
52
  return AuthGuard;
@@ -112,63 +66,19 @@ exports.createAuthGuard = createAuthGuard;
112
66
  * ```
113
67
  */
114
68
  function createOptionalAuthGuard(config) {
115
- const client = new client_1.AuthClient({
116
- baseURL: config.baseURL,
117
- apiKey: config.apiKey,
118
- apiKeyHeader: config.apiKeyHeader,
69
+ const authService = new auth_service_1.AuthService({
70
+ ...config,
71
+ optional: true,
119
72
  });
120
- const cacheTimeout = (config.cacheTimeout || 300) * 1000;
121
- const tokenStrategy = config.tokenStrategy || 'bearer';
122
- const cookieName = config.cookieName || 'access_token';
123
73
  class OptionalAuthGuard {
124
74
  async canActivate(context) {
125
75
  const request = context.switchToHttp().getRequest();
126
- // Extract token
127
- let token = null;
128
- if (config.tokenExtractor) {
129
- token = config.tokenExtractor(request);
130
- }
131
- else if (tokenStrategy === 'bearer') {
132
- const authHeader = request.headers.authorization;
133
- if (authHeader && authHeader.startsWith('Bearer ')) {
134
- token = authHeader.substring(7);
135
- }
136
- }
137
- else if (tokenStrategy === 'cookie') {
138
- token = request.cookies?.[cookieName] || null;
139
- }
140
- if (!token) {
141
- request.user = null;
142
- request.token = null;
143
- return true; // Allow access even without token
144
- }
145
- try {
146
- // Check cache first
147
- const cached = userCache.get(token);
148
- if (cached && Date.now() - cached.timestamp < cacheTimeout) {
149
- request.user = cached.user;
150
- request.token = token;
151
- return true;
152
- }
153
- // Fetch user profile
154
- client.setToken(token);
155
- const user = await client.auth.profile();
156
- // Update cache
157
- userCache.set(token, {
158
- user,
159
- timestamp: Date.now(),
160
- });
161
- // Attach user to request
162
- request.user = user;
163
- request.token = token;
164
- return true;
165
- }
166
- catch (error) {
167
- userCache.delete(token);
168
- request.user = null;
169
- request.token = null;
170
- return true; // Allow access even on error
171
- }
76
+ // Authenticate request (optional mode - always allows access)
77
+ const result = await authService.authenticate(request);
78
+ // Attach user and token to request (may be null)
79
+ request.user = result.user;
80
+ request.token = result.token;
81
+ return true; // Always allow access
172
82
  }
173
83
  }
174
84
  return OptionalAuthGuard;
@@ -179,10 +89,10 @@ exports.createOptionalAuthGuard = createOptionalAuthGuard;
179
89
  */
180
90
  function clearNestAuthCache(token) {
181
91
  if (token) {
182
- userCache.delete(token);
92
+ user_cache_1.userCache.delete(token);
183
93
  }
184
94
  else {
185
- userCache.clear();
95
+ user_cache_1.userCache.clear();
186
96
  }
187
97
  }
188
98
  exports.clearNestAuthCache = clearNestAuthCache;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Auth Service - Shared authentication logic for Express and NestJS
3
+ *
4
+ * Centralized authentication service to avoid code duplication
5
+ */
6
+ import { AuthClient } from '../../client';
7
+ import { User } from '../../types';
8
+ import { MiddlewareConfig } from '../types';
9
+ /**
10
+ * Authentication result
11
+ */
12
+ export interface AuthResult {
13
+ user: User | null;
14
+ token: string | null;
15
+ error?: {
16
+ status: number;
17
+ message: string;
18
+ };
19
+ }
20
+ /**
21
+ * Authentication service
22
+ */
23
+ export declare class AuthService {
24
+ private client;
25
+ private config;
26
+ constructor(config: MiddlewareConfig);
27
+ /**
28
+ * Authenticate request
29
+ */
30
+ authenticate(req: any): Promise<AuthResult>;
31
+ /**
32
+ * Get client instance (for advanced usage)
33
+ */
34
+ getClient(): AuthClient;
35
+ }
36
+ //# sourceMappingURL=auth-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-service.d.ts","sourceRoot":"","sources":["../../../src/middleware/shared/auth-service.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAI5C;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,KAAK,CAAC,EAAE;QACN,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH;AAED;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,MAAM,CAAmB;gBAErB,MAAM,EAAE,gBAAgB;IASpC;;OAEG;IACG,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC;IAyEjD;;OAEG;IACH,SAAS,IAAI,UAAU;CAGxB"}
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ /**
3
+ * Auth Service - Shared authentication logic for Express and NestJS
4
+ *
5
+ * Centralized authentication service to avoid code duplication
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.AuthService = void 0;
9
+ const client_1 = require("../../client");
10
+ const user_cache_1 = require("./user-cache");
11
+ const token_extractor_1 = require("./token-extractor");
12
+ /**
13
+ * Authentication service
14
+ */
15
+ class AuthService {
16
+ constructor(config) {
17
+ this.config = config;
18
+ this.client = new client_1.AuthClient({
19
+ baseURL: config.baseURL,
20
+ apiKey: config.apiKey,
21
+ apiKeyHeader: config.apiKeyHeader,
22
+ });
23
+ }
24
+ /**
25
+ * Authenticate request
26
+ */
27
+ async authenticate(req) {
28
+ // Extract token
29
+ const token = (0, token_extractor_1.extractToken)(req, this.config);
30
+ // No token found
31
+ if (!token) {
32
+ if (this.config.optional) {
33
+ return {
34
+ user: null,
35
+ token: null,
36
+ };
37
+ }
38
+ return {
39
+ user: null,
40
+ token: null,
41
+ error: {
42
+ status: 401,
43
+ message: 'Authentication required',
44
+ },
45
+ };
46
+ }
47
+ try {
48
+ const cacheTimeout = (this.config.cacheTimeout || 300) * 1000;
49
+ // Check cache first
50
+ const cachedUser = user_cache_1.userCache.get(token, cacheTimeout);
51
+ if (cachedUser) {
52
+ // Cleanup cache if needed
53
+ user_cache_1.userCache.cleanupIfNeeded(1000, cacheTimeout);
54
+ return {
55
+ user: cachedUser,
56
+ token,
57
+ };
58
+ }
59
+ // Fetch user profile from API
60
+ this.client.setToken(token);
61
+ const user = await this.client.auth.profile();
62
+ // Update cache
63
+ user_cache_1.userCache.set(token, user);
64
+ user_cache_1.userCache.cleanupIfNeeded(1000, cacheTimeout);
65
+ return {
66
+ user,
67
+ token,
68
+ };
69
+ }
70
+ catch (error) {
71
+ // Clear cache on error
72
+ user_cache_1.userCache.delete(token);
73
+ if (this.config.optional) {
74
+ return {
75
+ user: null,
76
+ token: null,
77
+ };
78
+ }
79
+ const status = error.response?.status || 401;
80
+ const message = error.response?.data?.message || 'Authentication failed';
81
+ return {
82
+ user: null,
83
+ token: null,
84
+ error: {
85
+ status,
86
+ message,
87
+ },
88
+ };
89
+ }
90
+ }
91
+ /**
92
+ * Get client instance (for advanced usage)
93
+ */
94
+ getClient() {
95
+ return this.client;
96
+ }
97
+ }
98
+ exports.AuthService = AuthService;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Shared utilities exports
3
+ */
4
+ export * from './user-cache';
5
+ export * from './token-extractor';
6
+ export * from './auth-service';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/middleware/shared/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /**
3
+ * Shared utilities exports
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ __exportStar(require("./user-cache"), exports);
21
+ __exportStar(require("./token-extractor"), exports);
22
+ __exportStar(require("./auth-service"), exports);
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Token Extractor - Shared token extraction logic for Express and NestJS
3
+ *
4
+ * Centralized token extraction to avoid code duplication
5
+ */
6
+ import { MiddlewareConfig } from '../types';
7
+ /**
8
+ * Extract token from request
9
+ */
10
+ export declare function extractToken(req: any, config: MiddlewareConfig): string | null;
11
+ /**
12
+ * Check if path should be excluded
13
+ */
14
+ export declare function shouldExcludePath(path: string, excludePaths?: (string | RegExp)[]): boolean;
15
+ //# sourceMappingURL=token-extractor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-extractor.d.ts","sourceRoot":"","sources":["../../../src/middleware/shared/token-extractor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,gBAAgB,GAAG,MAAM,GAAG,IAAI,CAqB9E;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,GAAG,OAAO,CAW3F"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ /**
3
+ * Token Extractor - Shared token extraction logic for Express and NestJS
4
+ *
5
+ * Centralized token extraction to avoid code duplication
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.shouldExcludePath = exports.extractToken = void 0;
9
+ /**
10
+ * Extract token from request
11
+ */
12
+ function extractToken(req, config) {
13
+ // Custom extractor takes priority
14
+ if (config.tokenExtractor) {
15
+ return config.tokenExtractor(req);
16
+ }
17
+ const tokenStrategy = config.tokenStrategy || 'bearer';
18
+ const cookieName = config.cookieName || 'access_token';
19
+ if (tokenStrategy === 'bearer') {
20
+ const authHeader = req.headers?.authorization || req.headers?.Authorization;
21
+ if (authHeader && typeof authHeader === 'string' && authHeader.startsWith('Bearer ')) {
22
+ return authHeader.substring(7);
23
+ }
24
+ }
25
+ else if (tokenStrategy === 'cookie') {
26
+ // Support both Express (req.cookies) and NestJS (req.cookies)
27
+ const cookies = req.cookies || {};
28
+ return cookies[cookieName] || null;
29
+ }
30
+ return null;
31
+ }
32
+ exports.extractToken = extractToken;
33
+ /**
34
+ * Check if path should be excluded
35
+ */
36
+ function shouldExcludePath(path, excludePaths) {
37
+ if (!excludePaths || excludePaths.length === 0) {
38
+ return false;
39
+ }
40
+ return excludePaths.some((pattern) => {
41
+ if (typeof pattern === 'string') {
42
+ return path === pattern;
43
+ }
44
+ return pattern.test(path);
45
+ });
46
+ }
47
+ exports.shouldExcludePath = shouldExcludePath;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * User Cache - Shared cache management for Express and NestJS
3
+ *
4
+ * Centralized cache implementation to avoid code duplication
5
+ */
6
+ import { User } from '../../types';
7
+ /**
8
+ * Cache entry structure
9
+ */
10
+ export interface CacheEntry {
11
+ user: User;
12
+ timestamp: number;
13
+ }
14
+ /**
15
+ * User cache manager
16
+ */
17
+ declare class UserCacheManager {
18
+ private cache;
19
+ private defaultTimeout;
20
+ /**
21
+ * Get cached user
22
+ */
23
+ get(token: string, timeout?: number): User | null;
24
+ /**
25
+ * Set cached user
26
+ */
27
+ set(token: string, user: User): void;
28
+ /**
29
+ * Delete cached user
30
+ */
31
+ delete(token: string): void;
32
+ /**
33
+ * Clear all cache
34
+ */
35
+ clear(): void;
36
+ /**
37
+ * Clean up old entries
38
+ */
39
+ cleanup(timeout?: number): void;
40
+ /**
41
+ * Cleanup when cache size exceeds limit
42
+ */
43
+ cleanupIfNeeded(maxSize?: number, timeout?: number): void;
44
+ /**
45
+ * Get cache size
46
+ */
47
+ size(): number;
48
+ }
49
+ export declare const userCache: UserCacheManager;
50
+ export {};
51
+ //# sourceMappingURL=user-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-cache.d.ts","sourceRoot":"","sources":["../../../src/middleware/shared/user-cache.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnC;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,cAAM,gBAAgB;IACpB,OAAO,CAAC,KAAK,CAAiC;IAC9C,OAAO,CAAC,cAAc,CAAsB;IAE5C;;OAEG;IACH,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,MAA4B,GAAG,IAAI,GAAG,IAAI;IAetE;;OAEG;IACH,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI;IAOpC;;OAEG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI3B;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,OAAO,CAAC,OAAO,GAAE,MAA4B,GAAG,IAAI;IAWpD;;OAEG;IACH,eAAe,CAAC,OAAO,GAAE,MAAa,EAAE,OAAO,GAAE,MAA4B,GAAG,IAAI;IAMpF;;OAEG;IACH,IAAI,IAAI,MAAM;CAGf;AAGD,eAAO,MAAM,SAAS,kBAAyB,CAAC"}
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ /**
3
+ * User Cache - Shared cache management for Express and NestJS
4
+ *
5
+ * Centralized cache implementation to avoid code duplication
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.userCache = void 0;
9
+ /**
10
+ * User cache manager
11
+ */
12
+ class UserCacheManager {
13
+ constructor() {
14
+ this.cache = new Map();
15
+ this.defaultTimeout = 300 * 1000; // 5 minutes in ms
16
+ }
17
+ /**
18
+ * Get cached user
19
+ */
20
+ get(token, timeout = this.defaultTimeout) {
21
+ const entry = this.cache.get(token);
22
+ if (!entry) {
23
+ return null;
24
+ }
25
+ const age = Date.now() - entry.timestamp;
26
+ if (age >= timeout) {
27
+ this.cache.delete(token);
28
+ return null;
29
+ }
30
+ return entry.user;
31
+ }
32
+ /**
33
+ * Set cached user
34
+ */
35
+ set(token, user) {
36
+ this.cache.set(token, {
37
+ user,
38
+ timestamp: Date.now(),
39
+ });
40
+ }
41
+ /**
42
+ * Delete cached user
43
+ */
44
+ delete(token) {
45
+ this.cache.delete(token);
46
+ }
47
+ /**
48
+ * Clear all cache
49
+ */
50
+ clear() {
51
+ this.cache.clear();
52
+ }
53
+ /**
54
+ * Clean up old entries
55
+ */
56
+ cleanup(timeout = this.defaultTimeout) {
57
+ const now = Date.now();
58
+ const entries = Array.from(this.cache.entries());
59
+ for (const [key, entry] of entries) {
60
+ if (now - entry.timestamp >= timeout) {
61
+ this.cache.delete(key);
62
+ }
63
+ }
64
+ }
65
+ /**
66
+ * Cleanup when cache size exceeds limit
67
+ */
68
+ cleanupIfNeeded(maxSize = 1000, timeout = this.defaultTimeout) {
69
+ if (this.cache.size > maxSize) {
70
+ this.cleanup(timeout);
71
+ }
72
+ }
73
+ /**
74
+ * Get cache size
75
+ */
76
+ size() {
77
+ return this.cache.size;
78
+ }
79
+ }
80
+ // Singleton instance
81
+ exports.userCache = new UserCacheManager();
@@ -1,6 +1,7 @@
1
1
  /**
2
- * Event Log Enums
2
+ * Event Log Types
3
3
  *
4
+ * Complete type definitions for event logging
4
5
  * Copied from @win-portal/shared for SDK independence
5
6
  */
6
7
  /**
@@ -61,4 +62,105 @@ export type EventOutcomeType = `${EventOutcome}`;
61
62
  export type EventCategoryType = `${EventCategory}`;
62
63
  export type EventRiskLevelType = `${EventRiskLevel}`;
63
64
  export type ActorTypeType = `${ActorType}`;
65
+ /**
66
+ * Event Log Actor Information
67
+ */
68
+ export interface IEventLogActor {
69
+ type: ActorType;
70
+ id?: string;
71
+ name?: string;
72
+ session_id?: string;
73
+ ip_address?: string;
74
+ user_agent?: string;
75
+ }
76
+ /**
77
+ * Event Log Target Information
78
+ */
79
+ export interface IEventLogTarget {
80
+ type: string;
81
+ id?: string;
82
+ name?: string;
83
+ }
84
+ /**
85
+ * Event Log Error Information
86
+ */
87
+ export interface IEventLogError {
88
+ code?: string;
89
+ message?: string;
90
+ details?: any;
91
+ }
92
+ /**
93
+ * Create Event Log Request DTO
94
+ *
95
+ * Complete interface for creating event logs
96
+ */
97
+ export interface CreateEventLogRequestDto {
98
+ source: string;
99
+ event_type: string;
100
+ subject?: string;
101
+ event_time?: Date | string;
102
+ application_id?: string | null;
103
+ application_code?: string;
104
+ severity?: EventSeverity;
105
+ outcome?: EventOutcome;
106
+ category?: EventCategory;
107
+ risk_level?: EventRiskLevel;
108
+ actor?: IEventLogActor;
109
+ target?: IEventLogTarget;
110
+ action?: string;
111
+ message?: string;
112
+ before_state?: Record<string, any>;
113
+ after_state?: Record<string, any>;
114
+ changed_fields?: Record<string, any>;
115
+ metadata?: Record<string, any>;
116
+ tags?: string[];
117
+ error?: IEventLogError;
118
+ trace_id?: string;
119
+ span_id?: string;
120
+ parent_span_id?: string;
121
+ trace_flags?: string;
122
+ correlation_id?: string;
123
+ request_id?: string;
124
+ business_reason?: string;
125
+ application_version?: string;
126
+ service_version?: string;
127
+ performance?: {
128
+ duration_ms?: number;
129
+ resource_usage?: Record<string, any>;
130
+ };
131
+ requires_approval?: boolean;
132
+ approval?: {
133
+ required: boolean;
134
+ approved_by?: string;
135
+ approved_at?: Date;
136
+ rejected_by?: string;
137
+ rejected_at?: Date;
138
+ reason?: string;
139
+ };
140
+ review?: {
141
+ required: boolean;
142
+ reviewed_by?: string;
143
+ reviewed_at?: Date;
144
+ status?: 'pending' | 'approved' | 'rejected';
145
+ notes?: string;
146
+ };
147
+ retention_period?: string;
148
+ expires_at?: Date;
149
+ }
150
+ /**
151
+ * Event Log Response DTO
152
+ */
153
+ export interface EventLogResponseDto {
154
+ id: string;
155
+ source: string;
156
+ event_type: string;
157
+ subject?: string;
158
+ event_time: string;
159
+ severity: string;
160
+ outcome: string;
161
+ category?: string;
162
+ risk_level?: string;
163
+ created_at: string;
164
+ updated_at: string;
165
+ }
64
166
  //# sourceMappingURL=event-log.types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"event-log.types.d.ts","sourceRoot":"","sources":["../../src/types/event-log.types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,oBAAY,aAAa;IACvB,KAAK,UAAU;IACf,IAAI,SAAS;IACb,OAAO,YAAY;IACnB,KAAK,UAAU;IACf,QAAQ,aAAa;CACtB;AAED;;GAEG;AACH,oBAAY,YAAY;IACtB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,OAAO,YAAY;CACpB;AAED;;GAEG;AACH,oBAAY,aAAa;IACvB,cAAc,mBAAmB;IACjC,aAAa,kBAAkB;IAC/B,WAAW,gBAAgB;IAC3B,QAAQ,aAAa;IACrB,QAAQ,aAAa;IACrB,SAAS,cAAc;IACvB,UAAU,eAAe;IACzB,cAAc,mBAAmB;CAClC;AAED;;GAEG;AACH,oBAAY,cAAc;IACxB,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,QAAQ,aAAa;CACtB;AAED;;GAEG;AACH,oBAAY,SAAS;IACnB,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,SAAS,cAAc;IACvB,OAAO,YAAY;CACpB;AAGD,MAAM,MAAM,iBAAiB,GAAG,GAAG,aAAa,EAAE,CAAC;AACnD,MAAM,MAAM,gBAAgB,GAAG,GAAG,YAAY,EAAE,CAAC;AACjD,MAAM,MAAM,iBAAiB,GAAG,GAAG,aAAa,EAAE,CAAC;AACnD,MAAM,MAAM,kBAAkB,GAAG,GAAG,cAAc,EAAE,CAAC;AACrD,MAAM,MAAM,aAAa,GAAG,GAAG,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"event-log.types.d.ts","sourceRoot":"","sources":["../../src/types/event-log.types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH;;GAEG;AACH,oBAAY,aAAa;IACvB,KAAK,UAAU;IACf,IAAI,SAAS;IACb,OAAO,YAAY;IACnB,KAAK,UAAU;IACf,QAAQ,aAAa;CACtB;AAED;;GAEG;AACH,oBAAY,YAAY;IACtB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,OAAO,YAAY;CACpB;AAED;;GAEG;AACH,oBAAY,aAAa;IACvB,cAAc,mBAAmB;IACjC,aAAa,kBAAkB;IAC/B,WAAW,gBAAgB;IAC3B,QAAQ,aAAa;IACrB,QAAQ,aAAa;IACrB,SAAS,cAAc;IACvB,UAAU,eAAe;IACzB,cAAc,mBAAmB;CAClC;AAED;;GAEG;AACH,oBAAY,cAAc;IACxB,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,QAAQ,aAAa;CACtB;AAED;;GAEG;AACH,oBAAY,SAAS;IACnB,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,UAAU,eAAe;I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