@node-c/api-http 1.0.0-alpha4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/common/definitions/common.constants.d.ts +9 -0
- package/dist/common/definitions/common.constants.js +14 -0
- package/dist/common/definitions/common.constants.js.map +1 -0
- package/dist/common/definitions/common.definitions.d.ts +9 -0
- package/dist/common/definitions/common.definitions.js +3 -0
- package/dist/common/definitions/common.definitions.js.map +1 -0
- package/dist/common/definitions/common.errors.d.ts +9 -0
- package/dist/common/definitions/common.errors.js +12 -0
- package/dist/common/definitions/common.errors.js.map +1 -0
- package/dist/common/definitions/index.d.ts +2 -0
- package/dist/common/definitions/index.js +19 -0
- package/dist/common/definitions/index.js.map +1 -0
- package/dist/exceptionFilters/http.exceptionFilters.httpException.d.ts +4 -0
- package/dist/exceptionFilters/http.exceptionFilters.httpException.js +26 -0
- package/dist/exceptionFilters/http.exceptionFilters.httpException.js.map +1 -0
- package/dist/exceptionFilters/index.d.ts +1 -0
- package/dist/exceptionFilters/index.js +18 -0
- package/dist/exceptionFilters/index.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/interceptors/http.interceptors.authorization.d.ts +11 -0
- package/dist/interceptors/http.interceptors.authorization.js +87 -0
- package/dist/interceptors/http.interceptors.authorization.js.map +1 -0
- package/dist/interceptors/http.interceptors.error.d.ts +5 -0
- package/dist/interceptors/http.interceptors.error.js +61 -0
- package/dist/interceptors/http.interceptors.error.js.map +1 -0
- package/dist/interceptors/index.d.ts +2 -0
- package/dist/interceptors/index.js +19 -0
- package/dist/interceptors/index.js.map +1 -0
- package/dist/middlewares/http.middlewares.authentication.d.ts +13 -0
- package/dist/middlewares/http.middlewares.authentication.js +128 -0
- package/dist/middlewares/http.middlewares.authentication.js.map +1 -0
- package/dist/middlewares/http.middlewares.cors.d.ts +10 -0
- package/dist/middlewares/http.middlewares.cors.js +47 -0
- package/dist/middlewares/http.middlewares.cors.js.map +1 -0
- package/dist/middlewares/index.d.ts +2 -0
- package/dist/middlewares/index.js +19 -0
- package/dist/middlewares/index.js.map +1 -0
- package/dist/module/http.api.module.d.ts +13 -0
- package/dist/module/http.api.module.definitions.d.ts +14 -0
- package/dist/module/http.api.module.definitions.js +3 -0
- package/dist/module/http.api.module.definitions.js.map +1 -0
- package/dist/module/http.api.module.js +82 -0
- package/dist/module/http.api.module.js.map +1 -0
- package/dist/module/index.d.ts +2 -0
- package/dist/module/index.js +19 -0
- package/dist/module/index.js.map +1 -0
- package/package.json +29 -0
- package/src/common/definitions/common.constants.ts +16 -0
- package/src/common/definitions/common.definitions.ts +10 -0
- package/src/common/definitions/common.errors.ts +13 -0
- package/src/common/definitions/index.ts +2 -0
- package/src/exceptionFilters/http.exceptionFilters.httpException.ts +21 -0
- package/src/exceptionFilters/index.ts +1 -0
- package/src/index.ts +5 -0
- package/src/interceptors/http.interceptors.authorization.ts +82 -0
- package/src/interceptors/http.interceptors.error.ts +50 -0
- package/src/interceptors/index.ts +2 -0
- package/src/middlewares/http.middlewares.authentication.ts +111 -0
- package/src/middlewares/http.middlewares.cors.ts +37 -0
- package/src/middlewares/index.ts +2 -0
- package/src/module/http.api.module.definitions.ts +16 -0
- package/src/module/http.api.module.ts +69 -0
- package/src/module/index.ts +2 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ModuleMetadata } from '@nestjs/common';
|
|
2
|
+
|
|
3
|
+
import { GenericObject } from '@node-c/core';
|
|
4
|
+
|
|
5
|
+
export interface HTTPAPIModuleOptions {
|
|
6
|
+
controllers?: ModuleMetadata['controllers'];
|
|
7
|
+
exports?: ModuleMetadata['exports'];
|
|
8
|
+
folderData: GenericObject<unknown>;
|
|
9
|
+
imports?: {
|
|
10
|
+
atEnd?: ModuleMetadata['imports'];
|
|
11
|
+
atStart?: ModuleMetadata['imports'];
|
|
12
|
+
};
|
|
13
|
+
moduleClass: unknown;
|
|
14
|
+
moduleName: string;
|
|
15
|
+
providers?: ModuleMetadata['providers'];
|
|
16
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { DynamicModule, Inject, MiddlewareConsumer, ModuleMetadata } from '@nestjs/common';
|
|
2
|
+
|
|
3
|
+
import { ConfigProviderService, loadDynamicModules } from '@node-c/core';
|
|
4
|
+
|
|
5
|
+
import cookieParser from 'cookie-parser';
|
|
6
|
+
import express, { Response } from 'express';
|
|
7
|
+
|
|
8
|
+
import { HTTPAPIModuleOptions } from './http.api.module.definitions';
|
|
9
|
+
|
|
10
|
+
import { Constants, RequestWithLocals } from '../common/definitions';
|
|
11
|
+
import { HttpExceptionFilter } from '../exceptionFilters';
|
|
12
|
+
import { HTTPAuthorizationInterceptor, HTTPErrorInterceptor } from '../interceptors';
|
|
13
|
+
import { HTTPAuthenticationMiddleware, HTTPCORSMiddleware } from '../middlewares';
|
|
14
|
+
|
|
15
|
+
export class HTTPAPIModule {
|
|
16
|
+
constructor(
|
|
17
|
+
// eslint-disable-next-line no-unused-vars
|
|
18
|
+
protected configProvider: ConfigProviderService,
|
|
19
|
+
@Inject(Constants.API_MODULE_NAME)
|
|
20
|
+
// eslint-disable-next-line no-unused-vars
|
|
21
|
+
protected moduleName: string
|
|
22
|
+
) {}
|
|
23
|
+
|
|
24
|
+
configure(consumer: MiddlewareConsumer): void {
|
|
25
|
+
consumer.apply(express.urlencoded({ verify: HTTPAPIModule.rawBodyBuffer, extended: true })).forRoutes('*');
|
|
26
|
+
consumer.apply(express.json({ verify: HTTPAPIModule.rawBodyBuffer })).forRoutes('*');
|
|
27
|
+
consumer.apply(cookieParser()).forRoutes('*');
|
|
28
|
+
consumer.apply(HTTPCORSMiddleware).forRoutes('*');
|
|
29
|
+
consumer.apply(HTTPAuthenticationMiddleware).forRoutes('*');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static rawBodyBuffer(req: RequestWithLocals<unknown>, _res: Response, buffer: Buffer): void {
|
|
33
|
+
if (buffer && buffer.length) {
|
|
34
|
+
req.rawBody = buffer.toString();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static register(options: HTTPAPIModuleOptions): DynamicModule {
|
|
39
|
+
const { folderData, imports: additionalImports, moduleClass } = options;
|
|
40
|
+
const { atEnd: importsAtEnd, atStart: importsAtStart } = additionalImports || {};
|
|
41
|
+
const { controllers, services } = loadDynamicModules(folderData);
|
|
42
|
+
return {
|
|
43
|
+
module: moduleClass as DynamicModule['module'],
|
|
44
|
+
imports: [...(importsAtStart || []), ...(importsAtEnd || [])],
|
|
45
|
+
providers: [
|
|
46
|
+
{
|
|
47
|
+
provide: Constants.API_MODULE_NAME,
|
|
48
|
+
useValue: options.moduleName
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
provide: Constants.AUTHORIZATION_INTERCEPTOR,
|
|
52
|
+
useClass: HTTPAuthorizationInterceptor
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
provide: Constants.ERROR_INTERCEPTOR,
|
|
56
|
+
useClass: HTTPErrorInterceptor
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
provide: Constants.HTTP_EXCEPTION_FILTER,
|
|
60
|
+
useClass: HttpExceptionFilter
|
|
61
|
+
},
|
|
62
|
+
...(options.providers || []),
|
|
63
|
+
...(services || [])
|
|
64
|
+
],
|
|
65
|
+
controllers: [...(controllers || []), ...(options.controllers || [])] as unknown as ModuleMetadata['controllers'],
|
|
66
|
+
exports: [...(services || []), ...(options.exports || [])]
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|