@digitaldefiance/node-express-suite 3.11.32 → 3.12.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 (146) hide show
  1. package/README.md +858 -0
  2. package/package.json +1 -1
  3. package/src/controllers/openapi.d.ts +67 -0
  4. package/src/controllers/openapi.d.ts.map +1 -0
  5. package/src/controllers/openapi.js +89 -0
  6. package/src/controllers/openapi.js.map +1 -0
  7. package/src/decorators/auth.d.ts +128 -0
  8. package/src/decorators/auth.d.ts.map +1 -0
  9. package/src/decorators/auth.js +230 -0
  10. package/src/decorators/auth.js.map +1 -0
  11. package/src/decorators/base-controller.d.ts +144 -6
  12. package/src/decorators/base-controller.d.ts.map +1 -1
  13. package/src/decorators/base-controller.js +487 -31
  14. package/src/decorators/base-controller.js.map +1 -1
  15. package/src/decorators/controller.d.ts +63 -7
  16. package/src/decorators/controller.d.ts.map +1 -1
  17. package/src/decorators/controller.js +70 -39
  18. package/src/decorators/controller.js.map +1 -1
  19. package/src/decorators/handler-args.d.ts +68 -0
  20. package/src/decorators/handler-args.d.ts.map +1 -0
  21. package/src/decorators/handler-args.js +83 -0
  22. package/src/decorators/handler-args.js.map +1 -0
  23. package/src/decorators/http-methods.d.ts +143 -0
  24. package/src/decorators/http-methods.d.ts.map +1 -0
  25. package/src/decorators/http-methods.js +265 -0
  26. package/src/decorators/http-methods.js.map +1 -0
  27. package/src/decorators/index.d.ts +22 -0
  28. package/src/decorators/index.d.ts.map +1 -1
  29. package/src/decorators/index.js +56 -0
  30. package/src/decorators/index.js.map +1 -1
  31. package/src/decorators/lifecycle.d.ts +248 -0
  32. package/src/decorators/lifecycle.d.ts.map +1 -0
  33. package/src/decorators/lifecycle.js +301 -0
  34. package/src/decorators/lifecycle.js.map +1 -0
  35. package/src/decorators/metadata-collector.d.ts +175 -0
  36. package/src/decorators/metadata-collector.d.ts.map +1 -0
  37. package/src/decorators/metadata-collector.js +272 -0
  38. package/src/decorators/metadata-collector.js.map +1 -0
  39. package/src/decorators/metadata-keys.d.ts +121 -0
  40. package/src/decorators/metadata-keys.d.ts.map +1 -0
  41. package/src/decorators/metadata-keys.js +116 -0
  42. package/src/decorators/metadata-keys.js.map +1 -0
  43. package/src/decorators/middleware.d.ts +181 -0
  44. package/src/decorators/middleware.d.ts.map +1 -0
  45. package/src/decorators/middleware.js +400 -0
  46. package/src/decorators/middleware.js.map +1 -0
  47. package/src/decorators/openapi-params.d.ts +192 -0
  48. package/src/decorators/openapi-params.d.ts.map +1 -0
  49. package/src/decorators/openapi-params.js +332 -0
  50. package/src/decorators/openapi-params.js.map +1 -0
  51. package/src/decorators/openapi.d.ts +201 -0
  52. package/src/decorators/openapi.d.ts.map +1 -0
  53. package/src/decorators/openapi.js +334 -0
  54. package/src/decorators/openapi.js.map +1 -0
  55. package/src/decorators/params.d.ts +217 -0
  56. package/src/decorators/params.d.ts.map +1 -0
  57. package/src/decorators/params.js +323 -0
  58. package/src/decorators/params.js.map +1 -0
  59. package/src/decorators/response.d.ts +200 -0
  60. package/src/decorators/response.d.ts.map +1 -0
  61. package/src/decorators/response.js +315 -0
  62. package/src/decorators/response.js.map +1 -0
  63. package/src/decorators/schema.d.ts +99 -0
  64. package/src/decorators/schema.d.ts.map +1 -0
  65. package/src/decorators/schema.js +329 -0
  66. package/src/decorators/schema.js.map +1 -0
  67. package/src/decorators/transaction.d.ts +69 -0
  68. package/src/decorators/transaction.d.ts.map +1 -0
  69. package/src/decorators/transaction.js +80 -0
  70. package/src/decorators/transaction.js.map +1 -0
  71. package/src/decorators/validation.d.ts +188 -0
  72. package/src/decorators/validation.d.ts.map +1 -0
  73. package/src/decorators/validation.js +269 -0
  74. package/src/decorators/validation.js.map +1 -0
  75. package/src/decorators/zod-validation.d.ts +164 -4
  76. package/src/decorators/zod-validation.d.ts.map +1 -1
  77. package/src/decorators/zod-validation.js +692 -13
  78. package/src/decorators/zod-validation.js.map +1 -1
  79. package/src/index.d.ts +1 -0
  80. package/src/index.d.ts.map +1 -1
  81. package/src/index.js +1 -0
  82. package/src/index.js.map +1 -1
  83. package/src/interfaces/openApi/decoratorOptions.d.ts +760 -0
  84. package/src/interfaces/openApi/decoratorOptions.d.ts.map +1 -0
  85. package/src/interfaces/openApi/decoratorOptions.js +734 -0
  86. package/src/interfaces/openApi/decoratorOptions.js.map +1 -0
  87. package/src/interfaces/openApi/index.d.ts +1 -0
  88. package/src/interfaces/openApi/index.d.ts.map +1 -1
  89. package/src/interfaces/openApi/index.js +23 -0
  90. package/src/interfaces/openApi/index.js.map +1 -1
  91. package/src/interfaces/openApi/parameter.d.ts +2 -0
  92. package/src/interfaces/openApi/parameter.d.ts.map +1 -1
  93. package/src/interfaces/openApi/parameter.js +3 -1
  94. package/src/interfaces/openApi/parameter.js.map +1 -1
  95. package/src/interfaces/openApi/parameterSchema.d.ts +2 -0
  96. package/src/interfaces/openApi/parameterSchema.d.ts.map +1 -1
  97. package/src/interfaces/openApi/parameterSchema.js +3 -0
  98. package/src/interfaces/openApi/parameterSchema.js.map +1 -1
  99. package/src/openapi/builder.d.ts +249 -0
  100. package/src/openapi/builder.d.ts.map +1 -0
  101. package/src/openapi/builder.js +352 -0
  102. package/src/openapi/builder.js.map +1 -0
  103. package/src/openapi/controller.d.ts +153 -0
  104. package/src/openapi/controller.d.ts.map +1 -0
  105. package/src/openapi/controller.js +331 -0
  106. package/src/openapi/controller.js.map +1 -0
  107. package/src/openapi/index.d.ts +12 -0
  108. package/src/openapi/index.d.ts.map +1 -0
  109. package/src/openapi/index.js +20 -0
  110. package/src/openapi/index.js.map +1 -0
  111. package/src/openapi/markdown-generator.d.ts +52 -0
  112. package/src/openapi/markdown-generator.d.ts.map +1 -0
  113. package/src/openapi/markdown-generator.js +569 -0
  114. package/src/openapi/markdown-generator.js.map +1 -0
  115. package/src/openapi/middleware/index.d.ts +9 -0
  116. package/src/openapi/middleware/index.d.ts.map +1 -0
  117. package/src/openapi/middleware/index.js +15 -0
  118. package/src/openapi/middleware/index.js.map +1 -0
  119. package/src/openapi/middleware/redoc.d.ts +314 -0
  120. package/src/openapi/middleware/redoc.d.ts.map +1 -0
  121. package/src/openapi/middleware/redoc.js +181 -0
  122. package/src/openapi/middleware/redoc.js.map +1 -0
  123. package/src/openapi/middleware/swagger-ui.d.ts +123 -0
  124. package/src/openapi/middleware/swagger-ui.d.ts.map +1 -0
  125. package/src/openapi/middleware/swagger-ui.js +227 -0
  126. package/src/openapi/middleware/swagger-ui.js.map +1 -0
  127. package/src/openapi/schemas.d.ts +170 -0
  128. package/src/openapi/schemas.d.ts.map +1 -0
  129. package/src/openapi/schemas.js +340 -0
  130. package/src/openapi/schemas.js.map +1 -0
  131. package/src/registry/controller-registry.d.ts +78 -0
  132. package/src/registry/controller-registry.d.ts.map +1 -0
  133. package/src/registry/controller-registry.js +86 -0
  134. package/src/registry/controller-registry.js.map +1 -0
  135. package/src/registry/index.d.ts +2 -0
  136. package/src/registry/index.d.ts.map +1 -1
  137. package/src/registry/index.js +3 -1
  138. package/src/registry/index.js.map +1 -1
  139. package/src/routers/api.d.ts +2 -1
  140. package/src/routers/api.d.ts.map +1 -1
  141. package/src/routers/api.js +7 -1
  142. package/src/routers/api.js.map +1 -1
  143. package/src/types.d.ts +1 -0
  144. package/src/types.d.ts.map +1 -1
  145. package/src/types.js +1 -0
  146. package/src/types.js.map +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitaldefiance/node-express-suite",
3
- "version": "3.11.32",
3
+ "version": "3.12.0",
4
4
  "homepage": "https://github.com/Digital-Defiance/node-express-suite",
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1,67 @@
1
+ import { CoreLanguageCode } from '@digitaldefiance/i18n-lib';
2
+ import { PlatformID } from '@digitaldefiance/node-ecies-lib';
3
+ import '../openapi/schemas';
4
+ import { IApiMessageResponse } from '@digitaldefiance/suite-core-lib';
5
+ import { ApiErrorResponse, ApiRequestHandler, TypedHandlers } from '../types';
6
+ import { BaseController } from './base';
7
+ import { IApplication } from '../interfaces';
8
+ /**
9
+ * OpenAPI specification response
10
+ */
11
+ export interface IOpenAPIResponse extends IApiMessageResponse {
12
+ openapi: string;
13
+ info: {
14
+ title: string;
15
+ version: string;
16
+ description: string;
17
+ };
18
+ servers: Array<{
19
+ url: string;
20
+ description: string;
21
+ }>;
22
+ paths: Record<string, any>;
23
+ components: {
24
+ schemas: Record<string, any>;
25
+ securitySchemes: Record<string, any>;
26
+ };
27
+ [key: string]: unknown;
28
+ }
29
+ type DocsApiResponse = IOpenAPIResponse | ApiErrorResponse;
30
+ interface DocsHandlers extends TypedHandlers {
31
+ getDocs: ApiRequestHandler<IOpenAPIResponse | ApiErrorResponse>;
32
+ }
33
+ /**
34
+ * Controller for API documentation endpoint.
35
+ *
36
+ * Provides the OpenAPI specification.
37
+ * The specification is built dynamically from registered controllers
38
+ * using their route definitions and OpenAPI metadata.
39
+ *
40
+ * ## Endpoints
41
+ *
42
+ * ### GET /api/openapi
43
+ * Returns the OpenAPI specification in JSON format.
44
+ *
45
+ * **Response:**
46
+ * - OpenAPI 3.0.3 specification with all endpoints
47
+ * - Request/response schemas for each endpoint
48
+ * - Authentication requirements per endpoint
49
+ * - Example requests and responses
50
+ *
51
+ * @requirements 10.1, 10.2, 10.3, 10.4
52
+ */
53
+ export declare class OpenApiController<TID extends PlatformID = Buffer> extends BaseController<DocsApiResponse, DocsHandlers, CoreLanguageCode, TID> {
54
+ private static readonly API_VERSION;
55
+ private readonly builder;
56
+ constructor(application: IApplication<TID>);
57
+ protected initRouteDefinitions(): void;
58
+ /**
59
+ * GET /api/openapi
60
+ * Returns the OpenAPI specification in JSON format.
61
+ *
62
+ * @requirements 10.1, 10.2, 10.3, 10.4
63
+ */
64
+ private handleGetOpenApi;
65
+ }
66
+ export {};
67
+ //# sourceMappingURL=openapi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-express-suite/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Ac,CAAC,eAAe,EAAE,YAAY,EAAE,gBAAgB,EAAE,GAAG,CAAC;IAC5E,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAY;IAC/C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;gBAE7B,WAAW,EAAE,YAAY,CAAC,GAAG,CAAC;IAW1C,SAAS,CAAC,oBAAoB,IAAI,IAAI;IAgCtC;;;;;OAKG;YACW,gBAAgB;CAiB/B"}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OpenApiController = void 0;
4
+ // Import to trigger schema registration
5
+ require("../openapi/schemas");
6
+ const types_1 = require("../types");
7
+ const base_1 = require("./base");
8
+ const openapi_1 = require("../openapi");
9
+ const registry_1 = require("../registry");
10
+ /**
11
+ * Controller for API documentation endpoint.
12
+ *
13
+ * Provides the OpenAPI specification.
14
+ * The specification is built dynamically from registered controllers
15
+ * using their route definitions and OpenAPI metadata.
16
+ *
17
+ * ## Endpoints
18
+ *
19
+ * ### GET /api/openapi
20
+ * Returns the OpenAPI specification in JSON format.
21
+ *
22
+ * **Response:**
23
+ * - OpenAPI 3.0.3 specification with all endpoints
24
+ * - Request/response schemas for each endpoint
25
+ * - Authentication requirements per endpoint
26
+ * - Example requests and responses
27
+ *
28
+ * @requirements 10.1, 10.2, 10.3, 10.4
29
+ */
30
+ class OpenApiController extends base_1.BaseController {
31
+ static API_VERSION = '0.12.0';
32
+ builder;
33
+ constructor(application) {
34
+ super(application);
35
+ this.builder = new openapi_1.OpenAPIBuilder({
36
+ title: 'Express Suite API',
37
+ version: OpenApiController.API_VERSION,
38
+ description: 'REST API for an Express Suite Servier',
39
+ servers: [{ url: '/api', description: 'API server' }],
40
+ });
41
+ }
42
+ initRouteDefinitions() {
43
+ this.routeDefinitions = [
44
+ (0, types_1.routeConfig)('get', '/', {
45
+ handlerKey: 'getDocs',
46
+ useAuthentication: false,
47
+ useCryptoAuthentication: false,
48
+ openapi: {
49
+ summary: 'Get OpenAPI specification',
50
+ description: 'Returns the OpenAPI specification in JSON format.',
51
+ tags: ['Documentation'],
52
+ responses: {
53
+ 200: {
54
+ schema: 'OpenAPISpec',
55
+ description: 'OpenAPI specification',
56
+ },
57
+ },
58
+ },
59
+ }),
60
+ ];
61
+ // Register this controller
62
+ registry_1.ControllerRegistry.register('/openapi', 'OpenApiController', this.routeDefinitions);
63
+ this.handlers = {
64
+ getDocs: this.handleGetOpenApi.bind(this),
65
+ };
66
+ }
67
+ /**
68
+ * GET /api/openapi
69
+ * Returns the OpenAPI specification in JSON format.
70
+ *
71
+ * @requirements 10.1, 10.2, 10.3, 10.4
72
+ */
73
+ async handleGetOpenApi() {
74
+ const spec = this.builder.build();
75
+ return {
76
+ statusCode: 200,
77
+ response: {
78
+ message: 'OpenAPI specification',
79
+ openapi: spec.openapi,
80
+ info: spec.info,
81
+ servers: spec.servers,
82
+ paths: spec.paths,
83
+ components: spec.components,
84
+ },
85
+ };
86
+ }
87
+ }
88
+ exports.OpenApiController = OpenApiController;
89
+ //# sourceMappingURL=openapi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openapi.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-express-suite/src/controllers/openapi.ts"],"names":[],"mappings":";;;AAGA,wCAAwC;AACxC,8BAA4B;AAE5B,oCAKkB;AAClB,iCAAwC;AACxC,wCAA4C;AAE5C,0CAAiD;AA8BjD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAa,iBAEX,SAAQ,qBAAoE;IACpE,MAAM,CAAU,WAAW,GAAG,QAAQ,CAAC;IAC9B,OAAO,CAAiB;IAEzC,YAAY,WAA8B;QACxC,KAAK,CAAC,WAAW,CAAC,CAAC;QAEnB,IAAI,CAAC,OAAO,GAAG,IAAI,wBAAc,CAAC;YAChC,KAAK,EAAE,mBAAmB;YAC1B,OAAO,EAAE,iBAAiB,CAAC,WAAW;YACtC,WAAW,EAAE,uCAAuC;YACpD,OAA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.
3
+ * Provides @RequireAuth, @RequireCryptoAuth, @Public, and @AuthFailureStatus decorators.
4
+ * Supports both class-level and method-level application.
5
+ * @module decorators/auth
6
+ */
7
+ import 'reflect-metadata';
8
+ import { AuthMetadata } from '../interfaces/openApi/decoratorOptions';
9
+ /**
10
+ * Decorator that requires JWT authentication for a route or all routes in a controller.
11
+ * Can be applied at class level (affects all methods) or method level.
12
+ * Automatically adds 401 response to OpenAPI spec.
13
+ *
14
+ * @returns Class or method decorator
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * // Class-level - all routes require auth
19
+ * @RequireAuth()
20
+ * @ApiController('/api/users')
21
+ * class UserController {
22
+ * @Get('/')
23
+ * listUsers() {}
24
+ * }
25
+ *
26
+ * // Method-level
27
+ * @ApiController('/api/items')
28
+ * class ItemController {
29
+ * @Get('/')
30
+ * listItems() {} // Public
31
+ *
32
+ * @RequireAuth()
33
+ * @Post('/')
34
+ * createItem() {} // Requires auth
35
+ * }
36
+ * ```
37
+ */
38
+ export declare function RequireAuth(): ClassDecorator & MethodDecorator;
39
+ /**
40
+ * Decorator that requires ECIES crypto authentication for a route or all routes in a controller.
41
+ * Can be applied at class level (affects all methods) or method level.
42
+ * Automatically adds 401 response to OpenAPI spec.
43
+ *
44
+ * @returns Class or method decorator
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * // Class-level - all routes require crypto auth
49
+ * @RequireCryptoAuth()
50
+ * @ApiController('/api/secure')
51
+ * class SecureController {
52
+ * @Get('/data')
53
+ * getData() {}
54
+ * }
55
+ *
56
+ * // Method-level
57
+ * @ApiController('/api/items')
58
+ * class ItemController {
59
+ * @RequireCryptoAuth()
60
+ * @Post('/encrypted')
61
+ * createEncrypted() {} // Requires crypto auth
62
+ * }
63
+ * ```
64
+ */
65
+ export declare function RequireCryptoAuth(): ClassDecorator & MethodDecorator;
66
+ /**
67
+ * Decorator that explicitly marks a route as public (no authentication required).
68
+ * Useful for overriding class-level authentication requirements.
69
+ * Can be applied at class level or method level.
70
+ *
71
+ * @returns Class or method decorator
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * @RequireAuth() // All routes require auth by default
76
+ * @ApiController('/api/users')
77
+ * class UserController {
78
+ * @Get('/:id')
79
+ * getUser() {} // Requires auth (inherited)
80
+ *
81
+ * @Public()
82
+ * @Get('/public-profile/:id')
83
+ * getPublicProfile() {} // No auth required (overridden)
84
+ * }
85
+ * ```
86
+ */
87
+ export declare function Public(): ClassDecorator & MethodDecorator;
88
+ /**
89
+ * Decorator that sets a custom status code for authentication failures.
90
+ * Can be applied at class level (affects all methods) or method level.
91
+ *
92
+ * @param statusCode - HTTP status code to return on auth failure (default is 401)
93
+ * @returns Class or method decorator
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * @RequireAuth()
98
+ * @AuthFailureStatus(403) // Return 403 instead of 401 for all routes
99
+ * @ApiController('/api/admin')
100
+ * class AdminController {
101
+ * @Get('/dashboard')
102
+ * getDashboard() {}
103
+ *
104
+ * @AuthFailureStatus(404) // Return 404 for this specific route
105
+ * @Get('/secret')
106
+ * getSecret() {}
107
+ * }
108
+ * ```
109
+ */
110
+ export declare function AuthFailureStatus(statusCode: number): ClassDecorator & MethodDecorator;
111
+ /**
112
+ * Gets the effective auth metadata for a method, merging class-level and method-level settings.
113
+ * Method-level settings override class-level settings.
114
+ *
115
+ * @param target - The class constructor
116
+ * @param propertyKey - The method name
117
+ * @returns The merged auth metadata
118
+ */
119
+ export declare function getEffectiveAuthMetadata(target: object, propertyKey: string | symbol): AuthMetadata;
120
+ /**
121
+ * Checks if a route requires authentication based on merged metadata.
122
+ *
123
+ * @param target - The class constructor
124
+ * @param propertyKey - The method name
125
+ * @returns True if the route requires any form of authentication
126
+ */
127
+ export declare function requiresAuthentication(target: object, propertyKey: string | symbol): boolean;
128
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-express-suite/src/decorators/auth.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AA0EtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,WAAW,IAAI,cAAc,GAAG,eAAe,CAQ9D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,GAAG,eAAe,CAQpE;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,MAAM,IAAI,cAAc,GAAG,eAAe,CAOzD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,GACjB,cAAc,GAAG,eAAe,CAOlC;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,MAAM,GAC3B,YAAY,CAoBd;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,MAAM,GAC3B,OAAO,CAMT"}
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Authentication decorators for Express Suite.
4
+ * Provides @RequireAuth, @RequireCryptoAuth, @Public, and @AuthFailureStatus decorators.
5
+ * Supports both class-level and method-level application.
6
+ * @module decorators/auth
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.RequireAuth = RequireAuth;
10
+ exports.RequireCryptoAuth = RequireCryptoAuth;
11
+ exports.Public = Public;
12
+ exports.AuthFailureStatus = AuthFailureStatus;
13
+ exports.getEffectiveAuthMetadata = getEffectiveAuthMetadata;
14
+ exports.requiresAuthentication = requiresAuthentication;
15
+ require("reflect-metadata");
16
+ const metadata_keys_1 = require("./metadata-keys");
17
+ const metadata_collector_1 = require("./metadata-collector");
18
+ /**
19
+ * Response metadata for 401 Unauthorized response.
20
+ */
21
+ const UNAUTHORIZED_RESPONSE = {
22
+ statusCode: 401,
23
+ description: 'Unauthorized - Authentication required',
24
+ schema: 'ErrorResponse',
25
+ };
26
+ /**
27
+ * Adds 401 response to OpenAPI metadata for authenticated routes.
28
+ * @param target - The target object (class constructor or prototype)
29
+ * @param propertyKey - Optional property key for method-level metadata
30
+ */
31
+ function addUnauthorizedResponse(target, propertyKey) {
32
+ const existingResponses = (0, metadata_collector_1.getMetadataOrDefault)(metadata_keys_1.RESPONSE_METADATA, target, propertyKey, []);
33
+ // Check if 401 response already exists
34
+ const has401 = existingResponses.some((r) => r.statusCode === 401);
35
+ if (!has401) {
36
+ existingResponses.push(UNAUTHORIZED_RESPONSE);
37
+ (0, metadata_collector_1.setMetadata)(metadata_keys_1.RESPONSE_METADATA, existingResponses, target, propertyKey);
38
+ }
39
+ }
40
+ /**
41
+ * Creates a decorator that can be applied to both classes and methods.
42
+ * @param applyMetadata - Function to apply the metadata
43
+ * @returns A decorator function
44
+ */
45
+ function createAuthDecorator(applyMetadata) {
46
+ function decorator(target, propertyKey, descriptor) {
47
+ if (propertyKey !== undefined && descriptor !== undefined) {
48
+ // Method decorator
49
+ applyMetadata(target.constructor, propertyKey);
50
+ return descriptor;
51
+ }
52
+ else {
53
+ // Class decorator
54
+ applyMetadata(target);
55
+ return target;
56
+ }
57
+ }
58
+ return decorator;
59
+ }
60
+ /**
61
+ * Decorator that requires JWT authentication for a route or all routes in a controller.
62
+ * Can be applied at class level (affects all methods) or method level.
63
+ * Automatically adds 401 response to OpenAPI spec.
64
+ *
65
+ * @returns Class or method decorator
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * // Class-level - all routes require auth
70
+ * @RequireAuth()
71
+ * @ApiController('/api/users')
72
+ * class UserController {
73
+ * @Get('/')
74
+ * listUsers() {}
75
+ * }
76
+ *
77
+ * // Method-level
78
+ * @ApiController('/api/items')
79
+ * class ItemController {
80
+ * @Get('/')
81
+ * listItems() {} // Public
82
+ *
83
+ * @RequireAuth()
84
+ * @Post('/')
85
+ * createItem() {} // Requires auth
86
+ * }
87
+ * ```
88
+ */
89
+ function RequireAuth() {
90
+ return createAuthDecorator((target, propertyKey) => {
91
+ const authMetadata = {
92
+ requireAuth: true,
93
+ };
94
+ (0, metadata_collector_1.mergeMetadata)(metadata_keys_1.AUTH_METADATA, authMetadata, target, propertyKey);
95
+ addUnauthorizedResponse(target, propertyKey);
96
+ });
97
+ }
98
+ /**
99
+ * Decorator that requires ECIES crypto authentication for a route or all routes in a controller.
100
+ * Can be applied at class level (affects all methods) or method level.
101
+ * Automatically adds 401 response to OpenAPI spec.
102
+ *
103
+ * @returns Class or method decorator
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * // Class-level - all routes require crypto auth
108
+ * @RequireCryptoAuth()
109
+ * @ApiController('/api/secure')
110
+ * class SecureController {
111
+ * @Get('/data')
112
+ * getData() {}
113
+ * }
114
+ *
115
+ * // Method-level
116
+ * @ApiController('/api/items')
117
+ * class ItemController {
118
+ * @RequireCryptoAuth()
119
+ * @Post('/encrypted')
120
+ * createEncrypted() {} // Requires crypto auth
121
+ * }
122
+ * ```
123
+ */
124
+ function RequireCryptoAuth() {
125
+ return createAuthDecorator((target, propertyKey) => {
126
+ const authMetadata = {
127
+ requireCryptoAuth: true,
128
+ };
129
+ (0, metadata_collector_1.mergeMetadata)(metadata_keys_1.AUTH_METADATA, authMetadata, target, propertyKey);
130
+ addUnauthorizedResponse(target, propertyKey);
131
+ });
132
+ }
133
+ /**
134
+ * Decorator that explicitly marks a route as public (no authentication required).
135
+ * Useful for overriding class-level authentication requirements.
136
+ * Can be applied at class level or method level.
137
+ *
138
+ * @returns Class or method decorator
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * @RequireAuth() // All routes require auth by default
143
+ * @ApiController('/api/users')
144
+ * class UserController {
145
+ * @Get('/:id')
146
+ * getUser() {} // Requires auth (inherited)
147
+ *
148
+ * @Public()
149
+ * @Get('/public-profile/:id')
150
+ * getPublicProfile() {} // No auth required (overridden)
151
+ * }
152
+ * ```
153
+ */
154
+ function Public() {
155
+ return createAuthDecorator((target, propertyKey) => {
156
+ const authMetadata = {
157
+ isPublic: true,
158
+ };
159
+ (0, metadata_collector_1.mergeMetadata)(metadata_keys_1.AUTH_METADATA, authMetadata, target, propertyKey);
160
+ });
161
+ }
162
+ /**
163
+ * Decorator that sets a custom status code for authentication failures.
164
+ * Can be applied at class level (affects all methods) or method level.
165
+ *
166
+ * @param statusCode - HTTP status code to return on auth failure (default is 401)
167
+ * @returns Class or method decorator
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * @RequireAuth()
172
+ * @AuthFailureStatus(403) // Return 403 instead of 401 for all routes
173
+ * @ApiController('/api/admin')
174
+ * class AdminController {
175
+ * @Get('/dashboard')
176
+ * getDashboard() {}
177
+ *
178
+ * @AuthFailureStatus(404) // Return 404 for this specific route
179
+ * @Get('/secret')
180
+ * getSecret() {}
181
+ * }
182
+ * ```
183
+ */
184
+ function AuthFailureStatus(statusCode) {
185
+ return createAuthDecorator((target, propertyKey) => {
186
+ const authMetadata = {
187
+ failureStatusCode: statusCode,
188
+ };
189
+ (0, metadata_collector_1.mergeMetadata)(metadata_keys_1.AUTH_METADATA, authMetadata, target, propertyKey);
190
+ });
191
+ }
192
+ /**
193
+ * Gets the effective auth metadata for a method, merging class-level and method-level settings.
194
+ * Method-level settings override class-level settings.
195
+ *
196
+ * @param target - The class constructor
197
+ * @param propertyKey - The method name
198
+ * @returns The merged auth metadata
199
+ */
200
+ function getEffectiveAuthMetadata(target, propertyKey) {
201
+ // Get class-level auth metadata
202
+ const classAuth = (0, metadata_collector_1.getMetadata)(metadata_keys_1.AUTH_METADATA, target) ?? {};
203
+ // Get method-level auth metadata
204
+ const methodAuth = (0, metadata_collector_1.getMetadata)(metadata_keys_1.AUTH_METADATA, target, propertyKey) ?? {};
205
+ // Method-level overrides class-level
206
+ const merged = { ...classAuth, ...methodAuth };
207
+ // If method is explicitly public, clear auth requirements
208
+ if (merged.isPublic) {
209
+ return {
210
+ isPublic: true,
211
+ failureStatusCode: merged.failureStatusCode,
212
+ };
213
+ }
214
+ return merged;
215
+ }
216
+ /**
217
+ * Checks if a route requires authentication based on merged metadata.
218
+ *
219
+ * @param target - The class constructor
220
+ * @param propertyKey - The method name
221
+ * @returns True if the route requires any form of authentication
222
+ */
223
+ function requiresAuthentication(target, propertyKey) {
224
+ const auth = getEffectiveAuthMetadata(target, propertyKey);
225
+ if (auth.isPublic) {
226
+ return false;
227
+ }
228
+ return auth.requireAuth === true || auth.requireCryptoAuth === true;
229
+ }
230
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-express-suite/src/decorators/auth.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AA0GH,kCAQC;AA4BD,8CAQC;AAuBD,wBAOC;AAwBD,8CASC;AAUD,4DAuBC;AASD,wDASC;AAtQD,4BAA0B;AAE1B,mDAAmE;AACnE,6DAK8B;AAE9B;;GAEG;AACH,MAAM,qBAAqB,GAAG;IAC5B,UAAU,EAAE,GAAG;IACf,WAAW,EAAE,wCAAwC;IACrD,MAAM,EAAE,eAAe;CACxB,CAAC;AAEF;;;;GAIG;AACH,SAAS,uBAAuB,CAC9B,MAAc,EACd,WAA6B;IAE7B,MAAM,iBAAiB,GAAG,IAAA,yCAAoB,EAE5C,iCAAiB,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,CAAC,CAAC;IAE9C,uCAAuC;IACvC,MAAM,MAAM,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,GAAG,CAAC,CAAC;IACnE,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,iBAAiB,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;QAC9C,IAAA,gCAAW,EAAC,iCAAiB,EAAE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