@pawells/nestjs-shared 1.0.0-dev.4c8c698
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/LICENSE +21 -0
- package/README.md +802 -0
- package/build/LICENSE +21 -0
- package/build/README.md +802 -0
- package/build/common/common.module.d.ts +49 -0
- package/build/common/common.module.d.ts.map +1 -0
- package/build/common/common.module.js +178 -0
- package/build/common/common.module.js.map +1 -0
- package/build/common/constants/histogram-buckets.constants.d.ts +12 -0
- package/build/common/constants/histogram-buckets.constants.d.ts.map +1 -0
- package/build/common/constants/histogram-buckets.constants.js +51 -0
- package/build/common/constants/histogram-buckets.constants.js.map +1 -0
- package/build/common/constants/http-status.constants.d.ts +27 -0
- package/build/common/constants/http-status.constants.d.ts.map +1 -0
- package/build/common/constants/http-status.constants.js +27 -0
- package/build/common/constants/http-status.constants.js.map +1 -0
- package/build/common/constants/timeout.constants.d.ts +29 -0
- package/build/common/constants/timeout.constants.d.ts.map +1 -0
- package/build/common/constants/timeout.constants.js +45 -0
- package/build/common/constants/timeout.constants.js.map +1 -0
- package/build/common/controllers/metrics.controller.d.ts +23 -0
- package/build/common/controllers/metrics.controller.d.ts.map +1 -0
- package/build/common/controllers/metrics.controller.js +66 -0
- package/build/common/controllers/metrics.controller.js.map +1 -0
- package/build/common/decorators/common-decorators.d.ts +90 -0
- package/build/common/decorators/common-decorators.d.ts.map +1 -0
- package/build/common/decorators/common-decorators.js +101 -0
- package/build/common/decorators/common-decorators.js.map +1 -0
- package/build/common/decorators/decorator-factory.d.ts +108 -0
- package/build/common/decorators/decorator-factory.d.ts.map +1 -0
- package/build/common/decorators/decorator-factory.js +104 -0
- package/build/common/decorators/decorator-factory.js.map +1 -0
- package/build/common/decorators/guard.decorators.d.ts +48 -0
- package/build/common/decorators/guard.decorators.d.ts.map +1 -0
- package/build/common/decorators/guard.decorators.js +49 -0
- package/build/common/decorators/guard.decorators.js.map +1 -0
- package/build/common/decorators/index.d.ts +10 -0
- package/build/common/decorators/index.d.ts.map +1 -0
- package/build/common/decorators/index.js +11 -0
- package/build/common/decorators/index.js.map +1 -0
- package/build/common/decorators/instrument.decorator.d.ts +128 -0
- package/build/common/decorators/instrument.decorator.d.ts.map +1 -0
- package/build/common/decorators/instrument.decorator.js +165 -0
- package/build/common/decorators/instrument.decorator.js.map +1 -0
- package/build/common/decorators/metric.decorators.d.ts +42 -0
- package/build/common/decorators/metric.decorators.d.ts.map +1 -0
- package/build/common/decorators/metric.decorators.js +85 -0
- package/build/common/decorators/metric.decorators.js.map +1 -0
- package/build/common/decorators/request-property.decorator.d.ts +65 -0
- package/build/common/decorators/request-property.decorator.d.ts.map +1 -0
- package/build/common/decorators/request-property.decorator.js +102 -0
- package/build/common/decorators/request-property.decorator.js.map +1 -0
- package/build/common/errors/base-application-error.d.ts +98 -0
- package/build/common/errors/base-application-error.d.ts.map +1 -0
- package/build/common/errors/base-application-error.js +133 -0
- package/build/common/errors/base-application-error.js.map +1 -0
- package/build/common/errors/error-factory.d.ts +93 -0
- package/build/common/errors/error-factory.d.ts.map +1 -0
- package/build/common/errors/error-factory.js +105 -0
- package/build/common/errors/error-factory.js.map +1 -0
- package/build/common/errors/index.d.ts +13 -0
- package/build/common/errors/index.d.ts.map +1 -0
- package/build/common/errors/index.js +15 -0
- package/build/common/errors/index.js.map +1 -0
- package/build/common/factories/index.d.ts +5 -0
- package/build/common/factories/index.d.ts.map +1 -0
- package/build/common/factories/index.js +3 -0
- package/build/common/factories/index.js.map +1 -0
- package/build/common/factories/module-factory.d.ts +178 -0
- package/build/common/factories/module-factory.d.ts.map +1 -0
- package/build/common/factories/module-factory.js +253 -0
- package/build/common/factories/module-factory.js.map +1 -0
- package/build/common/factories/rate-limit-config.factory.d.ts +79 -0
- package/build/common/factories/rate-limit-config.factory.d.ts.map +1 -0
- package/build/common/factories/rate-limit-config.factory.js +115 -0
- package/build/common/factories/rate-limit-config.factory.js.map +1 -0
- package/build/common/factories/security-bootstrap.factory.d.ts +77 -0
- package/build/common/factories/security-bootstrap.factory.d.ts.map +1 -0
- package/build/common/factories/security-bootstrap.factory.js +222 -0
- package/build/common/factories/security-bootstrap.factory.js.map +1 -0
- package/build/common/filters/global-exception.filter.d.ts +78 -0
- package/build/common/filters/global-exception.filter.d.ts.map +1 -0
- package/build/common/filters/global-exception.filter.js +192 -0
- package/build/common/filters/global-exception.filter.js.map +1 -0
- package/build/common/filters/http-exception.filter.d.ts +37 -0
- package/build/common/filters/http-exception.filter.d.ts.map +1 -0
- package/build/common/filters/http-exception.filter.js +91 -0
- package/build/common/filters/http-exception.filter.js.map +1 -0
- package/build/common/guards/csrf.guard.d.ts +53 -0
- package/build/common/guards/csrf.guard.d.ts.map +1 -0
- package/build/common/guards/csrf.guard.js +109 -0
- package/build/common/guards/csrf.guard.js.map +1 -0
- package/build/common/guards/metrics.guard.d.ts +42 -0
- package/build/common/guards/metrics.guard.d.ts.map +1 -0
- package/build/common/guards/metrics.guard.js +124 -0
- package/build/common/guards/metrics.guard.js.map +1 -0
- package/build/common/index.d.ts +43 -0
- package/build/common/index.d.ts.map +1 -0
- package/build/common/index.js +50 -0
- package/build/common/index.js.map +1 -0
- package/build/common/interceptors/http-client.interceptor.d.ts +11 -0
- package/build/common/interceptors/http-client.interceptor.d.ts.map +1 -0
- package/build/common/interceptors/http-client.interceptor.js +69 -0
- package/build/common/interceptors/http-client.interceptor.js.map +1 -0
- package/build/common/interceptors/http-instrumentation.interceptor.d.ts +64 -0
- package/build/common/interceptors/http-instrumentation.interceptor.d.ts.map +1 -0
- package/build/common/interceptors/http-instrumentation.interceptor.js +148 -0
- package/build/common/interceptors/http-instrumentation.interceptor.js.map +1 -0
- package/build/common/interceptors/http-metrics.interceptor.d.ts +46 -0
- package/build/common/interceptors/http-metrics.interceptor.d.ts.map +1 -0
- package/build/common/interceptors/http-metrics.interceptor.js +120 -0
- package/build/common/interceptors/http-metrics.interceptor.js.map +1 -0
- package/build/common/interceptors/logging.interceptor.d.ts +22 -0
- package/build/common/interceptors/logging.interceptor.d.ts.map +1 -0
- package/build/common/interceptors/logging.interceptor.js +67 -0
- package/build/common/interceptors/logging.interceptor.js.map +1 -0
- package/build/common/interfaces/cache-provider.interface.d.ts +54 -0
- package/build/common/interfaces/cache-provider.interface.d.ts.map +1 -0
- package/build/common/interfaces/cache-provider.interface.js +6 -0
- package/build/common/interfaces/cache-provider.interface.js.map +1 -0
- package/build/common/interfaces/index.d.ts +7 -0
- package/build/common/interfaces/index.d.ts.map +1 -0
- package/build/common/interfaces/index.js +3 -0
- package/build/common/interfaces/index.js.map +1 -0
- package/build/common/interfaces/log-context.interface.d.ts +77 -0
- package/build/common/interfaces/log-context.interface.d.ts.map +1 -0
- package/build/common/interfaces/log-context.interface.js +2 -0
- package/build/common/interfaces/log-context.interface.js.map +1 -0
- package/build/common/interfaces/log-entry.interface.d.ts +26 -0
- package/build/common/interfaces/log-entry.interface.d.ts.map +1 -0
- package/build/common/interfaces/log-entry.interface.js +33 -0
- package/build/common/interfaces/log-entry.interface.js.map +1 -0
- package/build/common/interfaces/logger.interface.d.ts +62 -0
- package/build/common/interfaces/logger.interface.d.ts.map +1 -0
- package/build/common/interfaces/logger.interface.js +2 -0
- package/build/common/interfaces/logger.interface.js.map +1 -0
- package/build/common/interfaces/metrics-exporter.interface.d.ts +275 -0
- package/build/common/interfaces/metrics-exporter.interface.d.ts.map +1 -0
- package/build/common/interfaces/metrics-exporter.interface.js +8 -0
- package/build/common/interfaces/metrics-exporter.interface.js.map +1 -0
- package/build/common/metrics/base-metrics-collector.d.ts +81 -0
- package/build/common/metrics/base-metrics-collector.d.ts.map +1 -0
- package/build/common/metrics/base-metrics-collector.js +88 -0
- package/build/common/metrics/base-metrics-collector.js.map +1 -0
- package/build/common/metrics/index.d.ts +2 -0
- package/build/common/metrics/index.d.ts.map +1 -0
- package/build/common/metrics/index.js +2 -0
- package/build/common/metrics/index.js.map +1 -0
- package/build/common/metrics.module.d.ts +50 -0
- package/build/common/metrics.module.d.ts.map +1 -0
- package/build/common/metrics.module.js +77 -0
- package/build/common/metrics.module.js.map +1 -0
- package/build/common/modules/throttler.module.d.ts +69 -0
- package/build/common/modules/throttler.module.d.ts.map +1 -0
- package/build/common/modules/throttler.module.js +117 -0
- package/build/common/modules/throttler.module.js.map +1 -0
- package/build/common/pipes/base-validation.pipe.d.ts +67 -0
- package/build/common/pipes/base-validation.pipe.d.ts.map +1 -0
- package/build/common/pipes/base-validation.pipe.js +95 -0
- package/build/common/pipes/base-validation.pipe.js.map +1 -0
- package/build/common/pipes/validation.pipe.d.ts +32 -0
- package/build/common/pipes/validation.pipe.d.ts.map +1 -0
- package/build/common/pipes/validation.pipe.js +60 -0
- package/build/common/pipes/validation.pipe.js.map +1 -0
- package/build/common/registry/instrumentation-registry.d.ts +227 -0
- package/build/common/registry/instrumentation-registry.d.ts.map +1 -0
- package/build/common/registry/instrumentation-registry.js +414 -0
- package/build/common/registry/instrumentation-registry.js.map +1 -0
- package/build/common/services/audit-logger.service.d.ts +91 -0
- package/build/common/services/audit-logger.service.d.ts.map +1 -0
- package/build/common/services/audit-logger.service.js +180 -0
- package/build/common/services/audit-logger.service.js.map +1 -0
- package/build/common/services/csrf.service.d.ts +202 -0
- package/build/common/services/csrf.service.d.ts.map +1 -0
- package/build/common/services/csrf.service.js +478 -0
- package/build/common/services/csrf.service.js.map +1 -0
- package/build/common/services/error-categorizer.service.d.ts +82 -0
- package/build/common/services/error-categorizer.service.d.ts.map +1 -0
- package/build/common/services/error-categorizer.service.js +339 -0
- package/build/common/services/error-categorizer.service.js.map +1 -0
- package/build/common/services/error-sanitizer.service.d.ts +146 -0
- package/build/common/services/error-sanitizer.service.d.ts.map +1 -0
- package/build/common/services/error-sanitizer.service.js +287 -0
- package/build/common/services/error-sanitizer.service.js.map +1 -0
- package/build/common/services/health-check.service.d.ts +86 -0
- package/build/common/services/health-check.service.d.ts.map +1 -0
- package/build/common/services/health-check.service.js +132 -0
- package/build/common/services/health-check.service.js.map +1 -0
- package/build/common/services/http-client.service.d.ts +113 -0
- package/build/common/services/http-client.service.d.ts.map +1 -0
- package/build/common/services/http-client.service.js +294 -0
- package/build/common/services/http-client.service.js.map +1 -0
- package/build/common/services/logger.service.d.ts +189 -0
- package/build/common/services/logger.service.d.ts.map +1 -0
- package/build/common/services/logger.service.js +423 -0
- package/build/common/services/logger.service.js.map +1 -0
- package/build/common/services/metrics-registry.service.d.ts +98 -0
- package/build/common/services/metrics-registry.service.d.ts.map +1 -0
- package/build/common/services/metrics-registry.service.js +262 -0
- package/build/common/services/metrics-registry.service.js.map +1 -0
- package/build/common/services/nest-logger-adapter.service.d.ts +62 -0
- package/build/common/services/nest-logger-adapter.service.d.ts.map +1 -0
- package/build/common/services/nest-logger-adapter.service.js +120 -0
- package/build/common/services/nest-logger-adapter.service.js.map +1 -0
- package/build/common/utils/error.utils.d.ts +16 -0
- package/build/common/utils/error.utils.d.ts.map +1 -0
- package/build/common/utils/error.utils.js +26 -0
- package/build/common/utils/error.utils.js.map +1 -0
- package/build/common/utils/lazy-getter.types.d.ts +190 -0
- package/build/common/utils/lazy-getter.types.d.ts.map +1 -0
- package/build/common/utils/lazy-getter.types.js +114 -0
- package/build/common/utils/lazy-getter.types.js.map +1 -0
- package/build/common/utils/module.utils.d.ts +33 -0
- package/build/common/utils/module.utils.d.ts.map +1 -0
- package/build/common/utils/module.utils.js +48 -0
- package/build/common/utils/module.utils.js.map +1 -0
- package/build/common/utils/sanitization.utils.d.ts +69 -0
- package/build/common/utils/sanitization.utils.d.ts.map +1 -0
- package/build/common/utils/sanitization.utils.js +141 -0
- package/build/common/utils/sanitization.utils.js.map +1 -0
- package/build/config/config.module.d.ts +30 -0
- package/build/config/config.module.d.ts.map +1 -0
- package/build/config/config.module.js +49 -0
- package/build/config/config.module.js.map +1 -0
- package/build/config/config.service.d.ts +74 -0
- package/build/config/config.service.d.ts.map +1 -0
- package/build/config/config.service.js +145 -0
- package/build/config/config.service.js.map +1 -0
- package/build/config/config.types.d.ts +143 -0
- package/build/config/config.types.d.ts.map +1 -0
- package/build/config/config.types.js +2 -0
- package/build/config/config.types.js.map +1 -0
- package/build/config/decorators/config.decorators.d.ts +43 -0
- package/build/config/decorators/config.decorators.d.ts.map +1 -0
- package/build/config/decorators/config.decorators.js +68 -0
- package/build/config/decorators/config.decorators.js.map +1 -0
- package/build/config/decorators/index.d.ts +2 -0
- package/build/config/decorators/index.d.ts.map +1 -0
- package/build/config/decorators/index.js +2 -0
- package/build/config/decorators/index.js.map +1 -0
- package/build/config/index.d.ts +7 -0
- package/build/config/index.d.ts.map +1 -0
- package/build/config/index.js +9 -0
- package/build/config/index.js.map +1 -0
- package/build/config/validation.utils.d.ts +136 -0
- package/build/config/validation.utils.d.ts.map +1 -0
- package/build/config/validation.utils.js +263 -0
- package/build/config/validation.utils.js.map +1 -0
- package/build/errors/index.d.ts +9 -0
- package/build/errors/index.d.ts.map +1 -0
- package/build/errors/index.js +12 -0
- package/build/errors/index.js.map +1 -0
- package/build/guards/custom-throttle.guard.d.ts +28 -0
- package/build/guards/custom-throttle.guard.d.ts.map +1 -0
- package/build/guards/custom-throttle.guard.js +52 -0
- package/build/guards/custom-throttle.guard.js.map +1 -0
- package/build/guards/index.d.ts +2 -0
- package/build/guards/index.d.ts.map +1 -0
- package/build/guards/index.js +2 -0
- package/build/guards/index.js.map +1 -0
- package/build/index.d.ts +53 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +61 -0
- package/build/index.js.map +1 -0
- package/build/logging/index.d.ts +7 -0
- package/build/logging/index.d.ts.map +1 -0
- package/build/logging/index.js +7 -0
- package/build/logging/index.js.map +1 -0
- package/build/metrics/index.d.ts +6 -0
- package/build/metrics/index.d.ts.map +1 -0
- package/build/metrics/index.js +11 -0
- package/build/metrics/index.js.map +1 -0
- package/build/package.json +72 -0
- package/build/security/index.d.ts +8 -0
- package/build/security/index.d.ts.map +1 -0
- package/build/security/index.js +11 -0
- package/build/security/index.js.map +1 -0
- package/build/test-setup.d.ts +2 -0
- package/build/test-setup.d.ts.map +1 -0
- package/build/test-setup.js +40 -0
- package/build/test-setup.js.map +1 -0
- package/build/validation/index.d.ts +6 -0
- package/build/validation/index.d.ts.map +1 -0
- package/build/validation/index.js +8 -0
- package/build/validation/index.js.map +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module factory utilities for common NestJS module patterns
|
|
3
|
+
*
|
|
4
|
+
* Provides standardized factory functions for creating modules with consistent
|
|
5
|
+
* structure, providers, exports, and configuration patterns.
|
|
6
|
+
*/
|
|
7
|
+
import { Logger } from '@nestjs/common';
|
|
8
|
+
import { APP_FILTER, APP_INTERCEPTOR, APP_PIPE, APP_GUARD } from '@nestjs/core';
|
|
9
|
+
/**
|
|
10
|
+
* Creates a global module with standardized configuration
|
|
11
|
+
*
|
|
12
|
+
* @param config - Module configuration
|
|
13
|
+
* @returns DynamicModule
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* @Module({})
|
|
18
|
+
* export class ConfigModule extends createGlobalModule({
|
|
19
|
+
* name: 'ConfigModule',
|
|
20
|
+
* providers: [ConfigService],
|
|
21
|
+
* exports: [ConfigService],
|
|
22
|
+
* }) {}
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export function CreateGlobalModule(config) {
|
|
26
|
+
const { name, providers = [], exports = [], imports = [], isGlobal = true } = config;
|
|
27
|
+
const moduleConfig = {
|
|
28
|
+
providers: [
|
|
29
|
+
...providers,
|
|
30
|
+
{
|
|
31
|
+
provide: Logger,
|
|
32
|
+
useValue: new Logger(name),
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
exports: [
|
|
36
|
+
...exports,
|
|
37
|
+
Logger,
|
|
38
|
+
],
|
|
39
|
+
imports,
|
|
40
|
+
};
|
|
41
|
+
if (isGlobal) {
|
|
42
|
+
moduleConfig.providers.push({
|
|
43
|
+
provide: 'MODULE_TYPE',
|
|
44
|
+
useValue: 'global',
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
module: class {
|
|
49
|
+
},
|
|
50
|
+
...moduleConfig,
|
|
51
|
+
global: isGlobal,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Creates a feature module with standardized configuration
|
|
56
|
+
*
|
|
57
|
+
* @param config - Module configuration
|
|
58
|
+
* @returns DynamicModule
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* @Module({})
|
|
63
|
+
* export class UserModule extends createFeatureModule({
|
|
64
|
+
* name: 'UserModule',
|
|
65
|
+
* controllers: [UserController],
|
|
66
|
+
* providers: [UserService],
|
|
67
|
+
* exports: [UserService],
|
|
68
|
+
* }) {}
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export function CreateFeatureModule(config) {
|
|
72
|
+
const { name, providers = [], exports = [], controllers = [], imports = [] } = config;
|
|
73
|
+
return {
|
|
74
|
+
module: class {
|
|
75
|
+
},
|
|
76
|
+
controllers,
|
|
77
|
+
providers: [
|
|
78
|
+
...providers,
|
|
79
|
+
{
|
|
80
|
+
provide: Logger,
|
|
81
|
+
useValue: new Logger(name),
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
exports: [
|
|
85
|
+
...exports,
|
|
86
|
+
Logger,
|
|
87
|
+
],
|
|
88
|
+
imports,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Creates a service module with standardized configuration
|
|
93
|
+
*
|
|
94
|
+
* @param config - Module configuration
|
|
95
|
+
* @returns DynamicModule
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* @Module({})
|
|
100
|
+
* export class DatabaseModule extends createServiceModule({
|
|
101
|
+
* name: 'DatabaseModule',
|
|
102
|
+
* providers: [DatabaseService, DatabaseConnection],
|
|
103
|
+
* exports: [DatabaseService],
|
|
104
|
+
* }) {}
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export function CreateServiceModule(config) {
|
|
108
|
+
const { name, providers = [], exports = [], imports = [] } = config;
|
|
109
|
+
return {
|
|
110
|
+
module: class {
|
|
111
|
+
},
|
|
112
|
+
providers: [
|
|
113
|
+
...providers,
|
|
114
|
+
{
|
|
115
|
+
provide: Logger,
|
|
116
|
+
useValue: new Logger(name),
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
exports: [
|
|
120
|
+
...exports,
|
|
121
|
+
Logger,
|
|
122
|
+
],
|
|
123
|
+
imports,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Creates an application module with global filters, interceptors, pipes, and guards
|
|
128
|
+
*
|
|
129
|
+
* @param config - Module configuration
|
|
130
|
+
* @returns DynamicModule
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* @Module({})
|
|
135
|
+
* export class AppModule extends createApplicationModule({
|
|
136
|
+
* name: 'AppModule',
|
|
137
|
+
* imports: [UserModule, AuthModule],
|
|
138
|
+
* filters: [HttpExceptionFilter],
|
|
139
|
+
* interceptors: [LoggingInterceptor],
|
|
140
|
+
* pipes: [ValidationPipe],
|
|
141
|
+
* guards: [AuthGuard],
|
|
142
|
+
* }) {}
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
export function CreateApplicationModule(config) {
|
|
146
|
+
const { name, filters = [], interceptors = [], pipes = [], guards = [], imports = [] } = config;
|
|
147
|
+
const providers = [
|
|
148
|
+
{
|
|
149
|
+
provide: Logger,
|
|
150
|
+
useValue: new Logger(name),
|
|
151
|
+
},
|
|
152
|
+
];
|
|
153
|
+
// Add global filters
|
|
154
|
+
filters.forEach((filter) => {
|
|
155
|
+
providers.push({
|
|
156
|
+
provide: APP_FILTER,
|
|
157
|
+
useClass: filter,
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
// Add global interceptors
|
|
161
|
+
interceptors.forEach((interceptor) => {
|
|
162
|
+
providers.push({
|
|
163
|
+
provide: APP_INTERCEPTOR,
|
|
164
|
+
useClass: interceptor,
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
// Add global pipes
|
|
168
|
+
pipes.forEach((pipe) => {
|
|
169
|
+
providers.push({
|
|
170
|
+
provide: APP_PIPE,
|
|
171
|
+
useClass: pipe,
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
// Add global guards
|
|
175
|
+
guards.forEach((guard) => {
|
|
176
|
+
providers.push({
|
|
177
|
+
provide: APP_GUARD,
|
|
178
|
+
useClass: guard,
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
return {
|
|
182
|
+
module: class {
|
|
183
|
+
},
|
|
184
|
+
providers,
|
|
185
|
+
exports: [Logger],
|
|
186
|
+
imports,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Creates a module with conditional providers based on configuration
|
|
191
|
+
*
|
|
192
|
+
* @param config - Base module configuration
|
|
193
|
+
* @param conditions - Array of conditional provider configurations
|
|
194
|
+
* @returns DynamicModule
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```typescript
|
|
198
|
+
* @Module({})
|
|
199
|
+
* export class CacheModule extends createConditionalModule(
|
|
200
|
+
* { name: 'CacheModule', imports: [ConfigModule] },
|
|
201
|
+
* [
|
|
202
|
+
* {
|
|
203
|
+
* condition: (config) => config.get('CACHE_ENABLED'),
|
|
204
|
+
* providers: [RedisService],
|
|
205
|
+
* exports: [RedisService],
|
|
206
|
+
* },
|
|
207
|
+
* ]
|
|
208
|
+
* ) {}
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
export function CreateConditionalModule(baseConfig, conditions) {
|
|
212
|
+
const { name = 'ConditionalModule', providers = [], exports = [], imports = [] } = baseConfig;
|
|
213
|
+
const conditionalProviders = [];
|
|
214
|
+
const conditionalExports = [];
|
|
215
|
+
const conditionalImports = [];
|
|
216
|
+
conditions.forEach(({ condition, providers: condProviders = [], exports: condExports = [], imports: condImports = [], config }) => {
|
|
217
|
+
if (condition(config)) {
|
|
218
|
+
conditionalProviders.push(...condProviders);
|
|
219
|
+
conditionalExports.push(...condExports);
|
|
220
|
+
conditionalImports.push(...condImports);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
return {
|
|
224
|
+
module: class {
|
|
225
|
+
},
|
|
226
|
+
providers: [
|
|
227
|
+
...providers,
|
|
228
|
+
...conditionalProviders,
|
|
229
|
+
{
|
|
230
|
+
provide: Logger,
|
|
231
|
+
useValue: new Logger(name),
|
|
232
|
+
},
|
|
233
|
+
],
|
|
234
|
+
exports: [
|
|
235
|
+
...exports,
|
|
236
|
+
...conditionalExports,
|
|
237
|
+
Logger,
|
|
238
|
+
],
|
|
239
|
+
imports: [
|
|
240
|
+
...imports,
|
|
241
|
+
...conditionalImports,
|
|
242
|
+
],
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Backwards compatibility aliases - exported functions use PascalCase per project conventions
|
|
247
|
+
*/
|
|
248
|
+
export const createApplicationModule = CreateApplicationModule;
|
|
249
|
+
export const createConditionalModule = CreateConditionalModule;
|
|
250
|
+
export const createFeatureModule = CreateFeatureModule;
|
|
251
|
+
export const createGlobalModule = CreateGlobalModule;
|
|
252
|
+
export const createServiceModule = CreateServiceModule;
|
|
253
|
+
//# sourceMappingURL=module-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-factory.js","sourceRoot":"","sources":["../../../src/common/factories/module-factory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAiB,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAkEhF;;;;;;;;;;;;;;;GAeG;AACH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BACf,QAAQ,EAAE,IAAI,MAAM,CAAC,IAAI,CAAC;aAC1B;SACD;QACD,OAAO,EAAE;YACR,GAAG,OAAO;YACV,GAAG,kBAAkB;YACrB,MAAM;SACN;QACD,OAAO,EAAE;YACR,GAAG,OAAO;YACV,GAAG,kBAAkB;SACrB;KACD,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,uBAAuB,CAAC;AAC/D,MAAM,CAAC,MAAM,uBAAuB,GAAG,uBAAuB,CAAC;AAC/D,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AACvD,MAAM,CAAC,MAAM,kBAAkB,GAAG,kBAAkB,CAAC;AACrD,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rate Limit Config Factory
|
|
3
|
+
*
|
|
4
|
+
* Provides a generic factory function for creating consistent rate limit configurations
|
|
5
|
+
* across all services. Includes sensible defaults for authentication and API endpoints
|
|
6
|
+
* with support for service-specific customization via deep merging.
|
|
7
|
+
*
|
|
8
|
+
* Default limits:
|
|
9
|
+
* - auth.login: 5 requests per 60 seconds
|
|
10
|
+
* - auth.register: 3 requests per 60 seconds
|
|
11
|
+
* - auth.refreshToken: 10 requests per 60 seconds
|
|
12
|
+
* - api.default: 100 requests per 60 seconds
|
|
13
|
+
* - api.search: 30 requests per 60 seconds
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Describes the rate limit for a single endpoint or operation
|
|
17
|
+
*
|
|
18
|
+
* @property ttl Time-to-live in milliseconds (sliding window for rate limit)
|
|
19
|
+
* @property limit Maximum number of requests allowed within the TTL
|
|
20
|
+
*/
|
|
21
|
+
export interface RateLimitDescriptor {
|
|
22
|
+
/** Time-to-live in milliseconds */
|
|
23
|
+
ttl: number;
|
|
24
|
+
/** Maximum number of requests allowed within TTL */
|
|
25
|
+
limit: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Complete rate limit configuration with auth, API, and custom domain limits
|
|
29
|
+
*
|
|
30
|
+
* @property auth Authentication endpoint rate limits (login, register, refresh token)
|
|
31
|
+
* @property api API endpoint rate limits (default, search)
|
|
32
|
+
* @property custom Index signature for service-specific custom rate limits
|
|
33
|
+
*/
|
|
34
|
+
export interface RateLimitConfig {
|
|
35
|
+
/** Authentication endpoint limits */
|
|
36
|
+
auth: {
|
|
37
|
+
login?: RateLimitDescriptor;
|
|
38
|
+
register?: RateLimitDescriptor;
|
|
39
|
+
refreshToken?: RateLimitDescriptor;
|
|
40
|
+
};
|
|
41
|
+
/** API endpoint limits */
|
|
42
|
+
api: {
|
|
43
|
+
default?: RateLimitDescriptor;
|
|
44
|
+
search?: RateLimitDescriptor;
|
|
45
|
+
};
|
|
46
|
+
/** Custom service-specific limits */
|
|
47
|
+
[key: string]: any;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Creates a rate limit configuration with optional overrides
|
|
51
|
+
*
|
|
52
|
+
* Creates a new rate limit configuration by deep merging the provided overrides
|
|
53
|
+
* with sensible defaults. This ensures that all default limits are preserved
|
|
54
|
+
* unless explicitly overridden.
|
|
55
|
+
*
|
|
56
|
+
* @param overrides Optional partial configuration to override defaults
|
|
57
|
+
* @returns Complete rate limit configuration with overrides applied
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* import { CreateRateLimitConfig } from '@pawells/nestjs-shared';
|
|
62
|
+
*
|
|
63
|
+
* // Use all defaults
|
|
64
|
+
* const config = CreateRateLimitConfig();
|
|
65
|
+
*
|
|
66
|
+
* // Override specific limits
|
|
67
|
+
* const customConfig = CreateRateLimitConfig({
|
|
68
|
+
* auth: {
|
|
69
|
+
* login: { ttl: 30000, limit: 3 },
|
|
70
|
+
* },
|
|
71
|
+
* api: {},
|
|
72
|
+
* custom: {
|
|
73
|
+
* upload: { ttl: 300000, limit: 5 },
|
|
74
|
+
* },
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare function CreateRateLimitConfig(overrides?: Partial<RateLimitConfig>): RateLimitConfig;
|
|
79
|
+
//# sourceMappingURL=rate-limit-config.factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limit-config.factory.d.ts","sourceRoot":"","sources":["../../../src/common/factories/rate-limit-config.factory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IACnC,mCAAmC;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,oDAAoD;IACpD,KAAK,EAAE,MAAM,CAAC;CACd;AAED;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC/B,qCAAqC;IACrC,IAAI,EAAE;QACL,KAAK,CAAC,EAAE,mBAAmB,CAAC;QAC5B,QAAQ,CAAC,EAAE,mBAAmB,CAAC;QAC/B,YAAY,CAAC,EAAE,mBAAmB,CAAC;KACnC,CAAC;IACF,0BAA0B;IAC1B,GAAG,EAAE;QACJ,OAAO,CAAC,EAAE,mBAAmB,CAAC;QAC9B,MAAM,CAAC,EAAE,mBAAmB,CAAC;KAC7B,CAAC;IACF,qCAAqC;IACrC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACnB;AA6ED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,CAE3F"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rate Limit Config Factory
|
|
3
|
+
*
|
|
4
|
+
* Provides a generic factory function for creating consistent rate limit configurations
|
|
5
|
+
* across all services. Includes sensible defaults for authentication and API endpoints
|
|
6
|
+
* with support for service-specific customization via deep merging.
|
|
7
|
+
*
|
|
8
|
+
* Default limits:
|
|
9
|
+
* - auth.login: 5 requests per 60 seconds
|
|
10
|
+
* - auth.register: 3 requests per 60 seconds
|
|
11
|
+
* - auth.refreshToken: 10 requests per 60 seconds
|
|
12
|
+
* - api.default: 100 requests per 60 seconds
|
|
13
|
+
* - api.search: 30 requests per 60 seconds
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Default rate limit configuration
|
|
17
|
+
*
|
|
18
|
+
* Provides sensible defaults for all standard auth and API endpoints.
|
|
19
|
+
* TTL values are in milliseconds, limit values are request counts.
|
|
20
|
+
*/
|
|
21
|
+
const DEFAULT_CONFIG = {
|
|
22
|
+
auth: {
|
|
23
|
+
login: {
|
|
24
|
+
ttl: 60000, // 60 seconds
|
|
25
|
+
limit: 5, // 5 requests per 60 seconds
|
|
26
|
+
},
|
|
27
|
+
register: {
|
|
28
|
+
ttl: 60000, // 60 seconds
|
|
29
|
+
limit: 3, // 3 requests per 60 seconds
|
|
30
|
+
},
|
|
31
|
+
refreshToken: {
|
|
32
|
+
ttl: 60000, // 60 seconds
|
|
33
|
+
limit: 10, // 10 requests per 60 seconds
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
api: {
|
|
37
|
+
default: {
|
|
38
|
+
ttl: 60000, // 60 seconds
|
|
39
|
+
limit: 100, // 100 requests per 60 seconds
|
|
40
|
+
},
|
|
41
|
+
search: {
|
|
42
|
+
ttl: 60000, // 60 seconds
|
|
43
|
+
limit: 30, // 30 requests per 60 seconds
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Deep merges a partial config with defaults, preserving unspecified defaults
|
|
49
|
+
*
|
|
50
|
+
* @param target The default configuration
|
|
51
|
+
* @param source The override configuration (partial)
|
|
52
|
+
* @returns Merged configuration with overrides applied
|
|
53
|
+
*
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
function DeepMerge(target, source) {
|
|
57
|
+
if (!source) {
|
|
58
|
+
return target;
|
|
59
|
+
}
|
|
60
|
+
const result = { ...target };
|
|
61
|
+
for (const key in source) {
|
|
62
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
63
|
+
const sourceValue = source[key];
|
|
64
|
+
const targetValue = target[key];
|
|
65
|
+
// If source is an object (but not array or null), merge recursively
|
|
66
|
+
if (sourceValue &&
|
|
67
|
+
typeof sourceValue === 'object' &&
|
|
68
|
+
!Array.isArray(sourceValue) &&
|
|
69
|
+
sourceValue !== null &&
|
|
70
|
+
targetValue &&
|
|
71
|
+
typeof targetValue === 'object' &&
|
|
72
|
+
!Array.isArray(targetValue)) {
|
|
73
|
+
result[key] = DeepMerge(targetValue, sourceValue);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
// Otherwise, use source value (overwrite)
|
|
77
|
+
result[key] = sourceValue;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Creates a rate limit configuration with optional overrides
|
|
85
|
+
*
|
|
86
|
+
* Creates a new rate limit configuration by deep merging the provided overrides
|
|
87
|
+
* with sensible defaults. This ensures that all default limits are preserved
|
|
88
|
+
* unless explicitly overridden.
|
|
89
|
+
*
|
|
90
|
+
* @param overrides Optional partial configuration to override defaults
|
|
91
|
+
* @returns Complete rate limit configuration with overrides applied
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* import { CreateRateLimitConfig } from '@pawells/nestjs-shared';
|
|
96
|
+
*
|
|
97
|
+
* // Use all defaults
|
|
98
|
+
* const config = CreateRateLimitConfig();
|
|
99
|
+
*
|
|
100
|
+
* // Override specific limits
|
|
101
|
+
* const customConfig = CreateRateLimitConfig({
|
|
102
|
+
* auth: {
|
|
103
|
+
* login: { ttl: 30000, limit: 3 },
|
|
104
|
+
* },
|
|
105
|
+
* api: {},
|
|
106
|
+
* custom: {
|
|
107
|
+
* upload: { ttl: 300000, limit: 5 },
|
|
108
|
+
* },
|
|
109
|
+
* });
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export function CreateRateLimitConfig(overrides) {
|
|
113
|
+
return DeepMerge(DEFAULT_CONFIG, overrides);
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=rate-limit-config.factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limit-config.factory.js","sourceRoot":"","sources":["../../../src/common/factories/rate-limit-config.factory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAsCH;;;;;GAKG;AACH,MAAM,cAAc,GAAoB;IACvC,IAAI,EAAE;QACL,KAAK,EAAE;YACN,GAAG,EAAE,KAAK,EAAE,aAAa;YACzB,KAAK,EAAE,CAAC,EAAE,4BAA4B;SACtC;QACD,QAAQ,EAAE;YACT,GAAG,EAAE,KAAK,EAAE,aAAa;YACzB,KAAK,EAAE,CAAC,EAAE,4BAA4B;SACtC;QACD,YAAY,EAAE;YACb,GAAG,EAAE,KAAK,EAAE,aAAa;YACzB,KAAK,EAAE,EAAE,EAAE,6BAA6B;SACxC;KACD;IACD,GAAG,EAAE;QACJ,OAAO,EAAE;YACR,GAAG,EAAE,KAAK,EAAE,aAAa;YACzB,KAAK,EAAE,GAAG,EAAE,8BAA8B;SAC1C;QACD,MAAM,EAAE;YACP,GAAG,EAAE,KAAK,EAAE,aAAa;YACzB,KAAK,EAAE,EAAE,EAAE,6BAA6B;SACxC;KACD;CACD,CAAC;AAEF;;;;;;;;GAQG;AACH,SAAS,SAAS,CAAC,MAAW,EAAE,MAAW;IAC1C,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,OAAO,MAAM,CAAC;IACf,CAAC;IAED,MAAM,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;IAE7B,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;QAC1B,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;YACvD,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAChC,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAEhC,oEAAoE;YACpE,IACC,WAAW;gBACX,OAAO,WAAW,KAAK,QAAQ;gBAC/B,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC;gBAC3B,WAAW,KAAK,IAAI;gBACpB,WAAW;gBACX,OAAO,WAAW,KAAK,QAAQ;gBAC/B,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,EAC1B,CAAC;gBACF,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;YACnD,CAAC;iBAAM,CAAC;gBACP,0CAA0C;gBAC1C,MAAM,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC;YAC3B,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,qBAAqB,CAAC,SAAoC;IACzE,OAAO,SAAS,CAAC,cAAc,EAAE,SAAS,CAAoB,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security Bootstrap Factory
|
|
3
|
+
*
|
|
4
|
+
* Provides a comprehensive factory function for applying security middleware and
|
|
5
|
+
* configurations to a NestJS application. This includes compression, MongoDB injection
|
|
6
|
+
* prevention, XSS protection, Helmet.js security headers, CORS, and global validation pipes.
|
|
7
|
+
*
|
|
8
|
+
* All security features are enabled by default and can be selectively disabled via options.
|
|
9
|
+
*/
|
|
10
|
+
import { INestApplication, Logger } from '@nestjs/common';
|
|
11
|
+
export interface SecurityBootstrapOptions {
|
|
12
|
+
/** List of allowed CORS origins. In development, localhost and Apollo Studio are always included. */
|
|
13
|
+
corsOrigins?: string[];
|
|
14
|
+
/** Environment mode (development or production). Defaults to NODE_ENV or 'development'. */
|
|
15
|
+
environment?: string;
|
|
16
|
+
/** Enable/disable compression middleware (default: true) */
|
|
17
|
+
compressionEnabled?: boolean;
|
|
18
|
+
/** Enable/disable XSS protection (default: true) */
|
|
19
|
+
xssEnabled?: boolean;
|
|
20
|
+
/** Enable/disable Helmet.js security headers (default: true) */
|
|
21
|
+
helmetEnabled?: boolean;
|
|
22
|
+
/** Enable/disable MongoDB injection prevention (default: true) */
|
|
23
|
+
mongoDbInjectionPreventionEnabled?: boolean;
|
|
24
|
+
/** Enable/disable CORS (default: true) */
|
|
25
|
+
corsEnabled?: boolean;
|
|
26
|
+
/** Custom CORS allowed headers (default: Content-Type, Authorization, etc.) */
|
|
27
|
+
corsAllowedHeaders?: string[];
|
|
28
|
+
/** CSP Connect-Src directives for allowed API origins. Merged with default 'self' (default: empty array). Use for configuring allowed API endpoints in production. */
|
|
29
|
+
cspConnectSrc?: string[];
|
|
30
|
+
/** CSP Image-Src directives for allowed image origins. Merged with default 'self' and 'data:' (default: empty array). Use for configuring allowed image CDNs in production. */
|
|
31
|
+
cspImgSrc?: string[];
|
|
32
|
+
/** CSP Style-Src directives for allowed style origins. Merged with default 'self' (default: empty array). Use for configuring allowed style CDNs like Google Fonts in production. */
|
|
33
|
+
cspStyleSrc?: string[];
|
|
34
|
+
/** CSP Font-Src directives for allowed font origins. Merged with default 'self' (default: empty array). Use for configuring allowed font CDNs like Google Fonts in production. */
|
|
35
|
+
cspFontSrc?: string[];
|
|
36
|
+
/** Maximum request body size limit (default: '10mb'). Express format: '10mb', '100kb', etc. */
|
|
37
|
+
maxBodySize?: string;
|
|
38
|
+
/** Logger instance for middleware application logging (optional) */
|
|
39
|
+
logger?: Logger;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Applies comprehensive security middleware and configurations to a NestJS application
|
|
43
|
+
*
|
|
44
|
+
* Configured middleware stack (in order):
|
|
45
|
+
* 0. Body Size Limits - Enforces maximum request body size
|
|
46
|
+
* 1. Compression - Reduces response size for APIs larger than 1KB
|
|
47
|
+
* 2. MongoDB Injection Prevention - Sanitizes request body and params
|
|
48
|
+
* 3. XSS Protection - Sanitizes user input to prevent XSS attacks
|
|
49
|
+
* 4. Helmet.js - Sets security-related HTTP headers (CSP, HSTS, X-Frame-Options, etc)
|
|
50
|
+
* 5. Global Validation Pipe - Validates and transforms incoming data
|
|
51
|
+
* 6. CORS - Enables cross-origin resource sharing with configurable origins
|
|
52
|
+
*
|
|
53
|
+
* @param app The NestJS application instance
|
|
54
|
+
* @param options Configuration options for security bootstrap
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* import { NestFactory } from '@nestjs/core';
|
|
59
|
+
* import { ApplySecurityMiddleware } from '@pawells/nestjs-shared';
|
|
60
|
+
* import { AppModule } from './app.module';
|
|
61
|
+
*
|
|
62
|
+
* async function bootstrap() {
|
|
63
|
+
* const app = await NestFactory.create(AppModule);
|
|
64
|
+
*
|
|
65
|
+
* ApplySecurityMiddleware(app, {
|
|
66
|
+
* corsOrigins: ['https://example.com'],
|
|
67
|
+
* environment: 'production',
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* await app.listen(3000);
|
|
71
|
+
* }
|
|
72
|
+
*
|
|
73
|
+
* bootstrap();
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare function ApplySecurityMiddleware(app: INestApplication, options?: SecurityBootstrapOptions): void;
|
|
77
|
+
//# sourceMappingURL=security-bootstrap.factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security-bootstrap.factory.d.ts","sourceRoot":"","sources":["../../../src/common/factories/security-bootstrap.factory.ts"],"names":[],"mappings":"AACA;;;;;;;;GAQG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAkB,MAAM,gBAAgB,CAAC;AAM1E,MAAM,WAAW,wBAAwB;IACxC,qGAAqG;IACrG,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,2FAA2F;IAC3F,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,oDAAoD;IACpD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,gEAAgE;IAChE,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,kEAAkE;IAClE,iCAAiC,CAAC,EAAE,OAAO,CAAC;IAC5C,0CAA0C;IAC1C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,+EAA+E;IAC/E,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,sKAAsK;IACtK,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,+KAA+K;IAC/K,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,qLAAqL;IACrL,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,kLAAkL;IAClL,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,+FAA+F;IAC/F,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,uBAAuB,CACtC,GAAG,EAAE,gBAAgB,EACrB,OAAO,GAAE,wBAA6B,GACpC,IAAI,CA+MN"}
|