@seidor-cloud-produtos/orbit-backend-lib 0.0.21 → 0.0.22
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/dist/clean-arch/infra/adapters/express-adapter.js +2 -0
- package/dist/frameworks/express/api-gateway/mapping-model.d.ts +14 -0
- package/dist/frameworks/express/api-gateway/mapping-model.js +38 -0
- package/dist/frameworks/express/api-gateway/middleware-express.d.ts +6 -0
- package/dist/frameworks/express/api-gateway/middleware-express.js +12 -0
- package/dist/frameworks/express/authorizations/authorization-express.d.ts +4 -8
- package/dist/frameworks/express/types.d.ts +6 -0
- package/dist/frameworks/express/types.js +2 -0
- package/dist/infra/http/api-gateway/mapping-model.d.ts +28 -0
- package/dist/infra/http/api-gateway/mapping-model.js +32 -0
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
3
3
|
const tslib_1 = require('tslib');
|
|
4
4
|
const cors_1 = tslib_1.__importDefault(require('cors'));
|
|
5
5
|
const express_1 = tslib_1.__importDefault(require('express'));
|
|
6
|
+
const middleware_express_1 = require('lib/frameworks/express/api-gateway/middleware-express');
|
|
6
7
|
class ExpressAdapter {
|
|
7
8
|
constructor(envs) {
|
|
8
9
|
this.envs = envs;
|
|
@@ -12,6 +13,7 @@ class ExpressAdapter {
|
|
|
12
13
|
this.instance.use(
|
|
13
14
|
express_1.default.urlencoded({ limit: '10mb', extended: false }),
|
|
14
15
|
);
|
|
16
|
+
this.instance.use(middleware_express_1.mapRequestMiddleware);
|
|
15
17
|
}
|
|
16
18
|
on(method, url, callback) {
|
|
17
19
|
this.instance[method](url, async (request, response) => {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MappingModel } from '../../../infra/http/api-gateway/mapping-model';
|
|
2
|
+
import { ExpressMidlewareProperties } from '../types';
|
|
3
|
+
export declare class ExpressMappingModel extends MappingModel {
|
|
4
|
+
controller: ExpressMidlewareProperties;
|
|
5
|
+
protected getBody(): any;
|
|
6
|
+
protected getHeaders(): Record<string, string | string[]>;
|
|
7
|
+
protected getQuery(): Record<string, string | string[]>;
|
|
8
|
+
protected getPathParams(): import('express-serve-static-core').ParamsDictionary;
|
|
9
|
+
protected setHeader(key: string, value: string | string[]): this;
|
|
10
|
+
protected setQuery(key: string, value: string | string[]): this;
|
|
11
|
+
protected setPathParams(key: string, value: string): this;
|
|
12
|
+
protected deleteParams(): this;
|
|
13
|
+
protected next(): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
exports.ExpressMappingModel = void 0;
|
|
4
|
+
const mapping_model_1 = require('../../../infra/http/api-gateway/mapping-model');
|
|
5
|
+
class ExpressMappingModel extends mapping_model_1.MappingModel {
|
|
6
|
+
getBody() {
|
|
7
|
+
return this.controller.request.body;
|
|
8
|
+
}
|
|
9
|
+
getHeaders() {
|
|
10
|
+
return this.controller.request.headers;
|
|
11
|
+
}
|
|
12
|
+
getQuery() {
|
|
13
|
+
return this.controller.request.query;
|
|
14
|
+
}
|
|
15
|
+
getPathParams() {
|
|
16
|
+
return this.controller.request.params;
|
|
17
|
+
}
|
|
18
|
+
setHeader(key, value) {
|
|
19
|
+
this.getHeaders()[key] = value;
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
setQuery(key, value) {
|
|
23
|
+
this.getQuery()[key] = value;
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
setPathParams(key, value) {
|
|
27
|
+
this.getPathParams()[key] = value;
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
deleteParams() {
|
|
31
|
+
delete this.getBody()['api-gateway-params'];
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
next() {
|
|
35
|
+
return this.controller.next();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.ExpressMappingModel = ExpressMappingModel;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
exports.mapRequestMiddleware = void 0;
|
|
4
|
+
const mapping_model_1 = require('./mapping-model');
|
|
5
|
+
const mapRequestMiddleware = (request, response, next) => {
|
|
6
|
+
return new mapping_model_1.ExpressMappingModel({
|
|
7
|
+
request,
|
|
8
|
+
response,
|
|
9
|
+
next,
|
|
10
|
+
}).parse();
|
|
11
|
+
};
|
|
12
|
+
exports.mapRequestMiddleware = mapRequestMiddleware;
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Response } from 'express';
|
|
2
2
|
import { AuthParams } from '../../../infra/authorizations/auth-matcher';
|
|
3
3
|
import { APIAuthValidator } from '../../../infra/authorizations/validator/api/api-validator';
|
|
4
4
|
import AuthValidator from '../../../infra/authorizations/validator/auth-validator';
|
|
5
5
|
import { UnauthorizedResponse } from '../../../infra/http/errors/unauthorized-response';
|
|
6
|
-
|
|
7
|
-
request: Request;
|
|
8
|
-
response: Response;
|
|
9
|
-
next: NextFunction;
|
|
10
|
-
};
|
|
6
|
+
import { ExpressMidlewareProperties } from '../types';
|
|
11
7
|
export default class AuthorizationExpress extends APIAuthValidator {
|
|
12
|
-
controller:
|
|
8
|
+
controller: ExpressMidlewareProperties;
|
|
13
9
|
static create(
|
|
14
10
|
query: AuthParams,
|
|
15
|
-
controllerMetaData:
|
|
11
|
+
controllerMetaData: ExpressMidlewareProperties,
|
|
16
12
|
): Promise<AuthValidator>;
|
|
17
13
|
getAuthorizations(): Promise<string[]>;
|
|
18
14
|
getRequestId(): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface IMappedBody extends Record<string, any> {
|
|
2
|
+
['api-gateway-params']?: {
|
|
3
|
+
path: Record<string, string>;
|
|
4
|
+
querystring: Record<string, string>;
|
|
5
|
+
header: Record<string, string>;
|
|
6
|
+
context: Record<string, string>;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export declare abstract class MappingModel {
|
|
10
|
+
protected controller: any;
|
|
11
|
+
constructor(controller: any);
|
|
12
|
+
protected abstract getBody(): any;
|
|
13
|
+
protected abstract getHeaders(): Record<string, string | string[]>;
|
|
14
|
+
protected abstract getQuery(): Record<string, string | string[]>;
|
|
15
|
+
protected abstract getPathParams(): Record<string, string>;
|
|
16
|
+
protected abstract setHeader(
|
|
17
|
+
key: string,
|
|
18
|
+
value: string | string[],
|
|
19
|
+
): MappingModel;
|
|
20
|
+
protected abstract setQuery(
|
|
21
|
+
key: string,
|
|
22
|
+
value: string | string[],
|
|
23
|
+
): MappingModel;
|
|
24
|
+
protected abstract deleteParams(): MappingModel;
|
|
25
|
+
protected abstract setPathParams(key: string, value: string): MappingModel;
|
|
26
|
+
protected abstract next(): any;
|
|
27
|
+
parse(): any;
|
|
28
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
exports.MappingModel = void 0;
|
|
4
|
+
class MappingModel {
|
|
5
|
+
constructor(controller) {
|
|
6
|
+
this.controller = controller;
|
|
7
|
+
}
|
|
8
|
+
parse() {
|
|
9
|
+
const body = this.getBody();
|
|
10
|
+
const params = body['api-gateway-params'];
|
|
11
|
+
if (!params) return this.next();
|
|
12
|
+
for (const key in params.header) {
|
|
13
|
+
if (this.getHeaders()[key] === undefined || key === 'accept') {
|
|
14
|
+
this.setHeader(key, params.header[key]);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
for (const key in params.querystring) {
|
|
18
|
+
if (this.getQuery()[key] === undefined) {
|
|
19
|
+
this.setQuery(key, params.querystring[key]);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
for (const key in params.path) {
|
|
23
|
+
if (this.getPathParams()[key] === undefined) {
|
|
24
|
+
this.setPathParams(key, params.path[key]);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return this.setHeader('authorizations', params.context.authorizations)
|
|
28
|
+
.deleteParams()
|
|
29
|
+
.next();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.MappingModel = MappingModel;
|