@noony-serverless/core 0.1.1 → 0.2.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.
Files changed (62) hide show
  1. package/build/core/core.d.ts +16 -48
  2. package/build/core/core.js +2 -61
  3. package/build/core/handler.d.ts +37 -16
  4. package/build/core/handler.js +131 -42
  5. package/build/core/index.d.ts +0 -1
  6. package/build/core/index.js +0 -1
  7. package/build/middlewares/ConsolidatedValidationMiddleware.d.ts +126 -0
  8. package/build/middlewares/ConsolidatedValidationMiddleware.js +330 -0
  9. package/build/middlewares/ProcessingMiddleware.d.ts +138 -0
  10. package/build/middlewares/ProcessingMiddleware.js +425 -0
  11. package/build/middlewares/SecurityMiddleware.d.ts +157 -0
  12. package/build/middlewares/SecurityMiddleware.js +307 -0
  13. package/build/middlewares/authenticationMiddleware.d.ts +379 -0
  14. package/build/middlewares/authenticationMiddleware.js +216 -0
  15. package/build/middlewares/bodyParserMiddleware.d.ts +99 -0
  16. package/build/middlewares/bodyParserMiddleware.js +99 -0
  17. package/build/middlewares/bodyValidationMiddleware.d.ts +69 -3
  18. package/build/middlewares/bodyValidationMiddleware.js +68 -2
  19. package/build/middlewares/dependencyInjectionMiddleware.d.ts +238 -0
  20. package/build/middlewares/dependencyInjectionMiddleware.js +238 -0
  21. package/build/middlewares/errorHandlerMiddleware.d.ts +94 -0
  22. package/build/middlewares/errorHandlerMiddleware.js +105 -0
  23. package/build/middlewares/guards/RouteGuards.d.ts +476 -21
  24. package/build/middlewares/guards/RouteGuards.js +418 -21
  25. package/build/middlewares/guards/adapters/CustomTokenVerificationPortAdapter.d.ts +271 -0
  26. package/build/middlewares/guards/adapters/CustomTokenVerificationPortAdapter.js +301 -0
  27. package/build/middlewares/guards/cache/CacheAdapter.d.ts +369 -28
  28. package/build/middlewares/guards/cache/CacheAdapter.js +124 -5
  29. package/build/middlewares/guards/cache/MemoryCacheAdapter.d.ts +113 -4
  30. package/build/middlewares/guards/cache/MemoryCacheAdapter.js +113 -4
  31. package/build/middlewares/guards/config/GuardConfiguration.d.ts +568 -18
  32. package/build/middlewares/guards/config/GuardConfiguration.js +266 -10
  33. package/build/middlewares/guards/guards/FastAuthGuard.d.ts +5 -5
  34. package/build/middlewares/guards/guards/PermissionGuardFactory.d.ts +5 -13
  35. package/build/middlewares/guards/guards/PermissionGuardFactory.js +4 -4
  36. package/build/middlewares/guards/index.d.ts +43 -1
  37. package/build/middlewares/guards/index.js +46 -1
  38. package/build/middlewares/guards/resolvers/ExpressionPermissionResolver.d.ts +1 -1
  39. package/build/middlewares/guards/resolvers/ExpressionPermissionResolver.js +1 -1
  40. package/build/middlewares/guards/resolvers/PermissionResolver.d.ts +1 -1
  41. package/build/middlewares/guards/resolvers/PlainPermissionResolver.d.ts +1 -1
  42. package/build/middlewares/guards/resolvers/WildcardPermissionResolver.d.ts +1 -1
  43. package/build/middlewares/guards/services/FastUserContextService.d.ts +20 -33
  44. package/build/middlewares/guards/services/FastUserContextService.js +19 -5
  45. package/build/middlewares/headerVariablesMiddleware.d.ts +118 -0
  46. package/build/middlewares/headerVariablesMiddleware.js +118 -0
  47. package/build/middlewares/httpAttributesMiddleware.d.ts +235 -0
  48. package/build/middlewares/httpAttributesMiddleware.js +236 -1
  49. package/build/middlewares/index.d.ts +3 -1
  50. package/build/middlewares/index.js +6 -1
  51. package/build/middlewares/queryParametersMiddleware.d.ts +105 -0
  52. package/build/middlewares/queryParametersMiddleware.js +105 -0
  53. package/build/middlewares/rateLimitingMiddleware.d.ts +601 -9
  54. package/build/middlewares/rateLimitingMiddleware.js +623 -11
  55. package/build/middlewares/responseWrapperMiddleware.d.ts +170 -1
  56. package/build/middlewares/responseWrapperMiddleware.js +170 -1
  57. package/build/middlewares/securityAuditMiddleware.js +5 -5
  58. package/package.json +11 -9
  59. package/build/core/containerPool.d.ts +0 -44
  60. package/build/core/containerPool.js +0 -103
  61. package/build/middlewares/validationMiddleware.d.ts +0 -9
  62. package/build/middlewares/validationMiddleware.js +0 -40
@@ -19,7 +19,28 @@
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.GuardConfiguration = exports.MonitoringLevel = exports.CacheInvalidationStrategy = exports.PermissionResolutionStrategy = void 0;
21
21
  /**
22
- * Permission resolution strategies for wildcard permissions
22
+ * Permission resolution strategies for wildcard permissions.
23
+ * Determines how wildcard patterns are processed for optimal performance.
24
+ *
25
+ * @example
26
+ * Pre-expansion strategy (production recommended):
27
+ * ```typescript
28
+ * const productionConfig = {
29
+ * permissionResolutionStrategy: PermissionResolutionStrategy.PRE_EXPANSION,
30
+ * // Expands "admin.*" to ["admin.users", "admin.reports", "admin.settings"]
31
+ * // at user context load time for O(1) runtime checks
32
+ * };
33
+ * ```
34
+ *
35
+ * @example
36
+ * On-demand strategy (memory efficient):
37
+ * ```typescript
38
+ * const memoryEfficientConfig = {
39
+ * permissionResolutionStrategy: PermissionResolutionStrategy.ON_DEMAND,
40
+ * // Matches "admin.*" pattern against user permissions at runtime
41
+ * // Lower memory usage but requires pattern matching overhead
42
+ * };
43
+ * ```
23
44
  *
24
45
  * PRE_EXPANSION: Expand wildcards at user context load time
25
46
  * - Pros: Faster runtime permission checks (O(1) set lookups)
@@ -53,25 +74,155 @@ var MonitoringLevel;
53
74
  MonitoringLevel["VERBOSE"] = "verbose";
54
75
  })(MonitoringLevel || (exports.MonitoringLevel = MonitoringLevel = {}));
55
76
  /**
56
- * GuardConfiguration class implementation
77
+ * GuardConfiguration class implementation.
78
+ * Immutable configuration object for the Noony guard system with factory methods
79
+ * for creating configurations from environment profiles or predefined templates.
80
+ *
81
+ * @example
82
+ * Create from environment profile:
83
+ * ```typescript
84
+ * import { GuardConfiguration } from '@noony/core';
85
+ *
86
+ * const config = GuardConfiguration.fromEnvironmentProfile({
87
+ * environment: 'production',
88
+ * cacheType: 'redis',
89
+ * security: { ... },
90
+ * cache: { ... },
91
+ * monitoring: { ... }
92
+ * });
93
+ * ```
94
+ *
95
+ * @example
96
+ * Use predefined configurations:
97
+ * ```typescript
98
+ * // Development configuration
99
+ * const devConfig = GuardConfiguration.development();
100
+ *
101
+ * // Production configuration
102
+ * const prodConfig = GuardConfiguration.production();
103
+ *
104
+ * // Testing configuration
105
+ * const testConfig = GuardConfiguration.testing();
106
+ * ```
107
+ *
108
+ * @example
109
+ * Manual configuration:
110
+ * ```typescript
111
+ * const customConfig = new GuardConfiguration(
112
+ * { permissionResolutionStrategy: PermissionResolutionStrategy.PRE_EXPANSION },
113
+ * { maxEntries: 10000, defaultTtlMs: 300000 },
114
+ * { enablePerformanceTracking: true, logLevel: 'info' }
115
+ * );
116
+ * ```
57
117
  */
58
118
  class GuardConfiguration {
119
+ /**
120
+ * Security configuration settings.
121
+ * Contains permission resolution strategies and security limits.
122
+ */
59
123
  security;
124
+ /**
125
+ * Cache configuration settings.
126
+ * Contains cache size limits and TTL values.
127
+ */
60
128
  cache;
129
+ /**
130
+ * Monitoring configuration settings.
131
+ * Contains logging and metrics collection settings.
132
+ */
61
133
  monitoring;
134
+ /**
135
+ * Creates a new GuardConfiguration instance.
136
+ *
137
+ * @param security - Security configuration settings
138
+ * @param cache - Cache configuration settings
139
+ * @param monitoring - Monitoring configuration settings
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * const config = new GuardConfiguration(
144
+ * {
145
+ * permissionResolutionStrategy: PermissionResolutionStrategy.PRE_EXPANSION,
146
+ * conservativeCacheInvalidation: true,
147
+ * maxExpressionComplexity: 100
148
+ * },
149
+ * {
150
+ * maxEntries: 10000,
151
+ * defaultTtlMs: 300000,
152
+ * userContextTtlMs: 600000,
153
+ * authTokenTtlMs: 900000
154
+ * },
155
+ * {
156
+ * enablePerformanceTracking: true,
157
+ * enableDetailedLogging: false,
158
+ * logLevel: 'info',
159
+ * metricsCollectionInterval: 60000
160
+ * }
161
+ * );
162
+ * ```
163
+ */
62
164
  constructor(security, cache, monitoring) {
63
165
  this.security = security;
64
166
  this.cache = cache;
65
167
  this.monitoring = monitoring;
66
168
  }
67
169
  /**
68
- * Create GuardConfiguration from environment profile
170
+ * Create GuardConfiguration from environment profile.
171
+ * Factory method that constructs a configuration from a complete environment profile.
172
+ *
173
+ * @param profile - Complete environment profile with all configuration sections
174
+ * @returns New GuardConfiguration instance
175
+ *
176
+ * @example
177
+ * Create from production profile:
178
+ * ```typescript
179
+ * const productionProfile: GuardEnvironmentProfile = {
180
+ * environment: 'production',
181
+ * cacheType: 'redis',
182
+ * security: {
183
+ * permissionResolutionStrategy: PermissionResolutionStrategy.PRE_EXPANSION,
184
+ * conservativeCacheInvalidation: true,
185
+ * maxExpressionComplexity: 100
186
+ * },
187
+ * cache: {
188
+ * maxEntries: 50000,
189
+ * defaultTtlMs: 600000,
190
+ * userContextTtlMs: 1800000,
191
+ * authTokenTtlMs: 3600000
192
+ * },
193
+ * monitoring: {
194
+ * enablePerformanceTracking: true,
195
+ * enableDetailedLogging: false,
196
+ * logLevel: 'error',
197
+ * metricsCollectionInterval: 60000
198
+ * }
199
+ * };
200
+ *
201
+ * const config = GuardConfiguration.fromEnvironmentProfile(productionProfile);
202
+ * ```
69
203
  */
70
204
  static fromEnvironmentProfile(profile) {
71
205
  return new GuardConfiguration(profile.security, profile.cache, profile.monitoring);
72
206
  }
73
207
  /**
74
- * Create default development configuration
208
+ * Create default development configuration.
209
+ * Pre-configured settings optimized for development environments with fast refresh
210
+ * and detailed logging for debugging.
211
+ *
212
+ * @returns GuardConfiguration optimized for development
213
+ *
214
+ * @example
215
+ * ```typescript
216
+ * const devConfig = GuardConfiguration.development();
217
+ *
218
+ * // Configuration includes:
219
+ * // - On-demand permission resolution (lower memory, dynamic)
220
+ * // - Conservative cache invalidation disabled (faster refresh)
221
+ * // - Lower complexity limits for faster feedback
222
+ * // - Shorter TTL values for rapid development cycles
223
+ * // - Detailed logging and debug level
224
+ * // - Frequent metrics collection (30 seconds)
225
+ * ```
75
226
  */
76
227
  static development() {
77
228
  return new GuardConfiguration({
@@ -93,7 +244,24 @@ class GuardConfiguration {
93
244
  });
94
245
  }
95
246
  /**
96
- * Create default production configuration
247
+ * Create default production configuration.
248
+ * Pre-configured settings optimized for production environments with high performance,
249
+ * security, and stability.
250
+ *
251
+ * @returns GuardConfiguration optimized for production
252
+ *
253
+ * @example
254
+ * ```typescript
255
+ * const prodConfig = GuardConfiguration.production();
256
+ *
257
+ * // Configuration includes:
258
+ * // - Pre-expansion permission resolution (high performance)
259
+ * // - Conservative cache invalidation enabled (high security)
260
+ * // - Higher complexity limits for production workloads
261
+ * // - Longer TTL values for better performance
262
+ * // - Performance tracking enabled, detailed logging disabled
263
+ * // - Standard metrics collection (1 minute intervals)
264
+ * ```
97
265
  */
98
266
  static production() {
99
267
  return new GuardConfiguration({
@@ -115,17 +283,105 @@ class GuardConfiguration {
115
283
  });
116
284
  }
117
285
  /**
118
- * Validate configuration
286
+ * Validate configuration settings.
287
+ * Ensures all configuration values are within acceptable bounds and constraints
288
+ * to prevent security vulnerabilities and performance issues.
289
+ *
290
+ * @throws Error if any configuration value is invalid
291
+ *
292
+ * @example
293
+ * ```typescript
294
+ * const config = new GuardConfiguration(securityConfig, cacheConfig, monitoringConfig);
295
+ *
296
+ * try {
297
+ * config.validate();
298
+ * console.log('Configuration is valid');
299
+ * } catch (error) {
300
+ * console.error('Invalid configuration:', error.message);
301
+ * // Handle configuration error
302
+ * }
303
+ * ```
304
+ *
305
+ * @example
306
+ * Validation constraints:
307
+ * ```typescript
308
+ * // These will throw validation errors:
309
+ * // maxPatternDepth must be 2 or 3 (prevents deep recursion)
310
+ * // maxNestingDepth must be 2 (prevents complex expressions)
311
+ * // maxExpressionComplexity must be positive
312
+ * // defaultTtlMs must be at least 1000ms (1 second)
313
+ * ```
314
+ */
315
+ /**
316
+ * Check if caching is enabled via environment variable.
317
+ *
318
+ * Caching is disabled by default for security-first approach.
319
+ * Only enabled when NOONY_GUARD_CACHE_ENABLE is explicitly set to 'true'.
320
+ *
321
+ * @returns true if caching should be enabled, false otherwise
322
+ *
323
+ * @example
324
+ * ```typescript
325
+ * // Caching disabled (default)
326
+ * process.env.NOONY_GUARD_CACHE_ENABLE = undefined;
327
+ * console.log(GuardConfiguration.isCachingEnabled()); // false
328
+ *
329
+ * // Caching enabled
330
+ * process.env.NOONY_GUARD_CACHE_ENABLE = 'true';
331
+ * console.log(GuardConfiguration.isCachingEnabled()); // true
332
+ *
333
+ * // Caching disabled (any other value)
334
+ * process.env.NOONY_GUARD_CACHE_ENABLE = 'false';
335
+ * console.log(GuardConfiguration.isCachingEnabled()); // false
336
+ * ```
119
337
  */
338
+ static isCachingEnabled() {
339
+ return process.env.NOONY_GUARD_CACHE_ENABLE === 'true';
340
+ }
341
+ /**
342
+ * Get effective cache type considering environment variable override.
343
+ *
344
+ * Environment variable takes precedence for security:
345
+ * - If NOONY_GUARD_CACHE_ENABLE is not 'true', returns 'none'
346
+ * - Otherwise returns the specified cacheType
347
+ *
348
+ * @param cacheType - Configured cache type
349
+ * @returns Effective cache type after environment variable consideration
350
+ *
351
+ * @example
352
+ * ```typescript
353
+ * // Environment variable not set - caching disabled
354
+ * process.env.NOONY_GUARD_CACHE_ENABLE = undefined;
355
+ * console.log(GuardConfiguration.getEffectiveCacheType('memory')); // 'none'
356
+ * console.log(GuardConfiguration.getEffectiveCacheType('redis')); // 'none'
357
+ * console.log(GuardConfiguration.getEffectiveCacheType('none')); // 'none'
358
+ *
359
+ * // Environment variable enabled - respect cacheType
360
+ * process.env.NOONY_GUARD_CACHE_ENABLE = 'true';
361
+ * console.log(GuardConfiguration.getEffectiveCacheType('memory')); // 'memory'
362
+ * console.log(GuardConfiguration.getEffectiveCacheType('redis')); // 'redis'
363
+ * console.log(GuardConfiguration.getEffectiveCacheType('none')); // 'none'
364
+ * ```
365
+ */
366
+ static getEffectiveCacheType(cacheType) {
367
+ // If caching is disabled by environment variable, always return 'none'
368
+ if (!GuardConfiguration.isCachingEnabled()) {
369
+ return 'none';
370
+ }
371
+ // Otherwise return the specified cache type
372
+ return cacheType;
373
+ }
120
374
  validate() {
121
- if (this.security.maxPatternDepth < 2 ||
122
- this.security.maxPatternDepth > 3) {
375
+ if (this.security.maxPatternDepth !== undefined &&
376
+ (this.security.maxPatternDepth < 2 || this.security.maxPatternDepth > 3)) {
123
377
  throw new Error('maxPatternDepth must be 2 or 3');
124
378
  }
125
- if (this.security.maxNestingDepth !== 2) {
379
+ if (this.security.maxNestingDepth !== undefined &&
380
+ this.security.maxNestingDepth !== 2) {
126
381
  throw new Error('maxNestingDepth must be 2');
127
382
  }
128
- if (this.security.maxExpressionComplexity < 1) {
383
+ if (this.security.maxExpressionComplexity !== undefined &&
384
+ this.security.maxExpressionComplexity < 1) {
129
385
  throw new Error('maxExpressionComplexity must be positive');
130
386
  }
131
387
  if (this.cache.defaultTtlMs < 1000) {
@@ -43,7 +43,7 @@ export interface AuthenticationResult {
43
43
  success: boolean;
44
44
  user?: UserContext;
45
45
  token?: {
46
- decoded: any;
46
+ decoded: unknown;
47
47
  raw: string;
48
48
  expiresAt: string;
49
49
  issuer?: string;
@@ -63,7 +63,7 @@ export interface AuthGuardConfig {
63
63
  allowedIssuers?: string[];
64
64
  requireEmailVerification: boolean;
65
65
  allowInactiveUsers: boolean;
66
- customValidation?: (token: any, user: UserContext) => Promise<boolean>;
66
+ customValidation?: (token: unknown, user: UserContext) => Promise<boolean>;
67
67
  }
68
68
  /**
69
69
  * Token validation service interface
@@ -74,17 +74,17 @@ export interface TokenValidator {
74
74
  */
75
75
  validateToken(token: string): Promise<{
76
76
  valid: boolean;
77
- decoded?: any;
77
+ decoded?: unknown;
78
78
  error?: string;
79
79
  }>;
80
80
  /**
81
81
  * Extract user ID from decoded token
82
82
  */
83
- extractUserId(decoded: any): string;
83
+ extractUserId(decoded: unknown): string;
84
84
  /**
85
85
  * Check if token is expired
86
86
  */
87
- isTokenExpired(decoded: any): boolean;
87
+ isTokenExpired(decoded: unknown): boolean;
88
88
  }
89
89
  /**
90
90
  * Fast Authentication Guard Implementation
@@ -39,7 +39,7 @@ import { PermissionResolverType, PermissionCheckResult, PermissionExpression } f
39
39
  */
40
40
  export interface GuardConfig {
41
41
  requireAuth: boolean;
42
- permissions: any;
42
+ permissions: string | string[] | PermissionExpression | Record<string, unknown>;
43
43
  resolverType?: PermissionResolverType;
44
44
  cacheResults: boolean;
45
45
  auditTrail: boolean;
@@ -141,7 +141,7 @@ export declare class PermissionGuardFactory {
141
141
  * @returns Composite permission guard instance
142
142
  */
143
143
  createCompositeGuard(requirements: Array<{
144
- permissions: any;
144
+ permissions: string | string[] | PermissionExpression | Record<string, unknown>;
145
145
  resolverType: PermissionResolverType;
146
146
  required: boolean;
147
147
  }>, config?: Partial<GuardConfig>): BasePermissionGuard;
@@ -155,23 +155,15 @@ export declare class PermissionGuardFactory {
155
155
  * @param config - Optional guard configuration
156
156
  * @returns Optimally configured permission guard
157
157
  */
158
- createAutoGuard(permissions: any, config?: Partial<GuardConfig>): BasePermissionGuard;
158
+ createAutoGuard(permissions: string | string[] | PermissionExpression | Record<string, unknown>, config?: Partial<GuardConfig>): BasePermissionGuard;
159
159
  /**
160
160
  * Get factory statistics
161
161
  */
162
162
  getStats(): {
163
163
  totalGuards: number;
164
164
  guardsByType: Record<string, number>;
165
- individualGuardStats: {
166
- guardType: string;
167
- checkCount: number;
168
- successCount: number;
169
- failureCount: number;
170
- successRate: number;
171
- averageProcessingTimeUs: number;
172
- totalProcessingTimeUs: number;
173
- }[];
174
- aggregatedStats: any;
165
+ individualGuardStats: Record<string, unknown>[];
166
+ aggregatedStats: Record<string, unknown>;
175
167
  };
176
168
  /**
177
169
  * Clear guard cache
@@ -531,10 +531,10 @@ let PermissionGuardFactory = class PermissionGuardFactory {
531
531
  };
532
532
  }
533
533
  const totals = guardStats.reduce((acc, stats) => ({
534
- checkCount: acc.checkCount + stats.checkCount,
535
- successCount: acc.successCount + stats.successCount,
536
- failureCount: acc.failureCount + stats.failureCount,
537
- totalProcessingTimeUs: acc.totalProcessingTimeUs + stats.totalProcessingTimeUs,
534
+ checkCount: acc.checkCount + (stats.checkCount || 0),
535
+ successCount: acc.successCount + (stats.successCount || 0),
536
+ failureCount: acc.failureCount + (stats.failureCount || 0),
537
+ totalProcessingTimeUs: acc.totalProcessingTimeUs + (stats.totalProcessingTimeUs || 0),
538
538
  }), {
539
539
  checkCount: 0,
540
540
  successCount: 0,
@@ -15,7 +15,7 @@
15
15
  * @author Noony Framework Team
16
16
  * @version 1.0.0
17
17
  */
18
- export { RouteGuards, RouteGuardOptions, GuardSystemStats, } from './RouteGuards';
18
+ export { RouteGuards, RouteGuardOptions, GuardSystemStats, AnyTokenValidator, } from './RouteGuards';
19
19
  export { GuardConfiguration, GuardEnvironmentProfile, PermissionResolutionStrategy, GuardSecurityConfig, GuardCacheConfig, GuardMonitoringConfig, } from './config/GuardConfiguration';
20
20
  export { CacheAdapter, CacheStats, CacheKeyBuilder, } from './cache/CacheAdapter';
21
21
  export { MemoryCacheAdapter } from './cache/MemoryCacheAdapter';
@@ -29,6 +29,7 @@ export { PermissionRegistry } from './registry/PermissionRegistry';
29
29
  export { FastUserContextService, UserContext, UserPermissionSource, PermissionCheckOptions, } from './services/FastUserContextService';
30
30
  export { FastAuthGuard, AuthenticationResult, AuthGuardConfig, TokenValidator, } from './guards/FastAuthGuard';
31
31
  export { PermissionGuardFactory, GuardConfig, } from './guards/PermissionGuardFactory';
32
+ export { CustomTokenVerificationPortAdapter, TokenVerificationAdapterFactory, AdapterConfig, } from './adapters/CustomTokenVerificationPortAdapter';
32
33
  export declare const GUARD_DEFAULTS: {
33
34
  readonly CACHE_TTL_MS: number;
34
35
  readonly AUTH_TOKEN_TTL_MS: number;
@@ -49,18 +50,59 @@ import { GuardEnvironmentProfile } from './config/GuardConfiguration';
49
50
  export declare class GuardSetup {
50
51
  /**
51
52
  * Development environment setup
53
+ *
54
+ * Note: Caching is disabled by default unless NOONY_GUARD_CACHE_ENABLE=true is set.
55
+ * Even with cacheType: 'memory', the environment variable takes precedence.
56
+ *
57
+ * @example
58
+ * ```bash
59
+ * # Caching disabled (default)
60
+ * npm run dev
61
+ *
62
+ * # Caching enabled
63
+ * NOONY_GUARD_CACHE_ENABLE=true npm run dev
64
+ * ```
52
65
  */
53
66
  static development(): GuardEnvironmentProfile;
54
67
  /**
55
68
  * Production environment setup
69
+ *
70
+ * Note: Caching is disabled by default unless NOONY_GUARD_CACHE_ENABLE=true is set.
71
+ * This provides a security-first approach where caching must be explicitly enabled.
72
+ *
73
+ * @example
74
+ * ```bash
75
+ * # Production with caching enabled (recommended)
76
+ * NOONY_GUARD_CACHE_ENABLE=true node dist/index.js
77
+ *
78
+ * # Production with caching disabled (debugging/troubleshooting)
79
+ * node dist/index.js
80
+ * ```
56
81
  */
57
82
  static production(): GuardEnvironmentProfile;
58
83
  /**
59
84
  * Serverless environment setup (optimized for cold starts)
85
+ *
86
+ * Note: Caching is disabled by default unless NOONY_GUARD_CACHE_ENABLE=true is set.
87
+ * For serverless environments, consider enabling caching to improve performance
88
+ * across warm invocations.
89
+ *
90
+ * @example
91
+ * ```bash
92
+ * # Serverless with caching enabled (recommended for warm starts)
93
+ * NOONY_GUARD_CACHE_ENABLE=true serverless deploy
94
+ *
95
+ * # Serverless with caching disabled (cold start optimization)
96
+ * serverless deploy
97
+ * ```
60
98
  */
61
99
  static serverless(): GuardEnvironmentProfile;
62
100
  /**
63
101
  * Testing environment setup
102
+ *
103
+ * Note: Uses cacheType: 'none' explicitly, so caching is always disabled
104
+ * regardless of NOONY_GUARD_CACHE_ENABLE environment variable.
105
+ * This ensures predictable test behavior.
64
106
  */
65
107
  static testing(): GuardEnvironmentProfile;
66
108
  }
@@ -17,7 +17,7 @@
17
17
  * @version 1.0.0
18
18
  */
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.GuardSetup = exports.PERMISSION_PATTERNS = exports.GUARD_DEFAULTS = exports.PermissionGuardFactory = exports.FastAuthGuard = exports.FastUserContextService = exports.ExpressionPermissionResolver = exports.WildcardPermissionResolver = exports.PlainPermissionResolver = exports.PermissionUtils = exports.PermissionResolverType = exports.PermissionResolver = exports.InvalidationScope = exports.InvalidationType = exports.ConservativeCacheInvalidation = exports.NoopCacheAdapter = exports.MemoryCacheAdapter = exports.CacheKeyBuilder = exports.PermissionResolutionStrategy = exports.GuardConfiguration = exports.RouteGuards = void 0;
20
+ exports.GuardSetup = exports.PERMISSION_PATTERNS = exports.GUARD_DEFAULTS = exports.TokenVerificationAdapterFactory = exports.CustomTokenVerificationPortAdapter = exports.PermissionGuardFactory = exports.FastAuthGuard = exports.FastUserContextService = exports.ExpressionPermissionResolver = exports.WildcardPermissionResolver = exports.PlainPermissionResolver = exports.PermissionUtils = exports.PermissionResolverType = exports.PermissionResolver = exports.InvalidationScope = exports.InvalidationType = exports.ConservativeCacheInvalidation = exports.NoopCacheAdapter = exports.MemoryCacheAdapter = exports.CacheKeyBuilder = exports.PermissionResolutionStrategy = exports.GuardConfiguration = exports.RouteGuards = void 0;
21
21
  // Main facade - primary entry point
22
22
  var RouteGuards_1 = require("./RouteGuards");
23
23
  Object.defineProperty(exports, "RouteGuards", { enumerable: true, get: function () { return RouteGuards_1.RouteGuards; } });
@@ -55,6 +55,10 @@ var FastAuthGuard_1 = require("./guards/FastAuthGuard");
55
55
  Object.defineProperty(exports, "FastAuthGuard", { enumerable: true, get: function () { return FastAuthGuard_1.FastAuthGuard; } });
56
56
  var PermissionGuardFactory_1 = require("./guards/PermissionGuardFactory");
57
57
  Object.defineProperty(exports, "PermissionGuardFactory", { enumerable: true, get: function () { return PermissionGuardFactory_1.PermissionGuardFactory; } });
58
+ // Token verification adapters for integration with AuthenticationMiddleware
59
+ var CustomTokenVerificationPortAdapter_1 = require("./adapters/CustomTokenVerificationPortAdapter");
60
+ Object.defineProperty(exports, "CustomTokenVerificationPortAdapter", { enumerable: true, get: function () { return CustomTokenVerificationPortAdapter_1.CustomTokenVerificationPortAdapter; } });
61
+ Object.defineProperty(exports, "TokenVerificationAdapterFactory", { enumerable: true, get: function () { return CustomTokenVerificationPortAdapter_1.TokenVerificationAdapterFactory; } });
58
62
  // Utility types and constants
59
63
  exports.GUARD_DEFAULTS = {
60
64
  CACHE_TTL_MS: 15 * 60 * 1000, // 15 minutes
@@ -77,6 +81,18 @@ const GuardConfiguration_2 = require("./config/GuardConfiguration");
77
81
  class GuardSetup {
78
82
  /**
79
83
  * Development environment setup
84
+ *
85
+ * Note: Caching is disabled by default unless NOONY_GUARD_CACHE_ENABLE=true is set.
86
+ * Even with cacheType: 'memory', the environment variable takes precedence.
87
+ *
88
+ * @example
89
+ * ```bash
90
+ * # Caching disabled (default)
91
+ * npm run dev
92
+ *
93
+ * # Caching enabled
94
+ * NOONY_GUARD_CACHE_ENABLE=true npm run dev
95
+ * ```
80
96
  */
81
97
  static development() {
82
98
  return {
@@ -105,6 +121,18 @@ class GuardSetup {
105
121
  }
106
122
  /**
107
123
  * Production environment setup
124
+ *
125
+ * Note: Caching is disabled by default unless NOONY_GUARD_CACHE_ENABLE=true is set.
126
+ * This provides a security-first approach where caching must be explicitly enabled.
127
+ *
128
+ * @example
129
+ * ```bash
130
+ * # Production with caching enabled (recommended)
131
+ * NOONY_GUARD_CACHE_ENABLE=true node dist/index.js
132
+ *
133
+ * # Production with caching disabled (debugging/troubleshooting)
134
+ * node dist/index.js
135
+ * ```
108
136
  */
109
137
  static production() {
110
138
  return {
@@ -133,6 +161,19 @@ class GuardSetup {
133
161
  }
134
162
  /**
135
163
  * Serverless environment setup (optimized for cold starts)
164
+ *
165
+ * Note: Caching is disabled by default unless NOONY_GUARD_CACHE_ENABLE=true is set.
166
+ * For serverless environments, consider enabling caching to improve performance
167
+ * across warm invocations.
168
+ *
169
+ * @example
170
+ * ```bash
171
+ * # Serverless with caching enabled (recommended for warm starts)
172
+ * NOONY_GUARD_CACHE_ENABLE=true serverless deploy
173
+ *
174
+ * # Serverless with caching disabled (cold start optimization)
175
+ * serverless deploy
176
+ * ```
136
177
  */
137
178
  static serverless() {
138
179
  return {
@@ -161,6 +202,10 @@ class GuardSetup {
161
202
  }
162
203
  /**
163
204
  * Testing environment setup
205
+ *
206
+ * Note: Uses cacheType: 'none' explicitly, so caching is always disabled
207
+ * regardless of NOONY_GUARD_CACHE_ENABLE environment variable.
208
+ * This ensures predictable test behavior.
164
209
  */
165
210
  static testing() {
166
211
  return {
@@ -118,7 +118,7 @@ export declare class ExpressionPermissionResolver extends PermissionResolver<Per
118
118
  /**
119
119
  * Check if this resolver can handle the given requirement type
120
120
  */
121
- canHandle(requirement: any): requirement is PermissionExpression;
121
+ canHandle(requirement: unknown): requirement is PermissionExpression;
122
122
  /**
123
123
  * Normalize expression for consistent cache keys
124
124
  *
@@ -412,7 +412,7 @@ class ExpressionPermissionResolver extends PermissionResolver_1.PermissionResolv
412
412
  * Check if this resolver can handle the given requirement type
413
413
  */
414
414
  canHandle(requirement) {
415
- return (requirement &&
415
+ return Boolean(requirement &&
416
416
  typeof requirement === 'object' &&
417
417
  PermissionResolver_1.PermissionUtils.isValidExpression(requirement));
418
418
  }
@@ -19,7 +19,7 @@
19
19
  * different types of permission requirements. The generic type T represents
20
20
  * the specific requirement format for each resolver.
21
21
  */
22
- export declare abstract class PermissionResolver<T = any> {
22
+ export declare abstract class PermissionResolver<T = unknown> {
23
23
  /**
24
24
  * Check if user permissions satisfy the requirement
25
25
  *
@@ -96,6 +96,6 @@ export declare class PlainPermissionResolver extends PermissionResolver<string[]
96
96
  * @param requirement - The requirement to check
97
97
  * @returns true if this resolver can handle the requirement
98
98
  */
99
- canHandle(requirement: any): requirement is string[];
99
+ canHandle(requirement: unknown): requirement is string[];
100
100
  }
101
101
  //# sourceMappingURL=PlainPermissionResolver.d.ts.map
@@ -141,6 +141,6 @@ export declare class WildcardPermissionResolver extends PermissionResolver<strin
141
141
  /**
142
142
  * Check if this resolver can handle the given requirement type
143
143
  */
144
- canHandle(requirement: any): requirement is string[];
144
+ canHandle(requirement: unknown): requirement is string[];
145
145
  }
146
146
  //# sourceMappingURL=WildcardPermissionResolver.d.ts.map