pangea-server 1.0.81 → 2.0.1
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.
|
@@ -4,7 +4,7 @@ import type { AuthMap, AuthUsers } from '../authentication/authentication.types'
|
|
|
4
4
|
import type { RouteValidator as Validator, RouteValidate as Validate } from '../validator/validator.types';
|
|
5
5
|
import type { SetRouteArgs, AuthConfig } from './router.types';
|
|
6
6
|
type ApiMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
7
|
-
export declare function getAppRouter<AM extends AuthMap, AU extends AuthUsers<AM>, BA extends BaseAuth<AM>>(authConfig: AuthConfig<AM, AU, BA>): {
|
|
7
|
+
export declare function getAppRouter<AM extends AuthMap, AU extends AuthUsers<AM>, BA extends BaseAuth<AM>>(appVersion: string, authConfig: AuthConfig<AM, AU, BA>): {
|
|
8
8
|
new (app: App, basePath: string): {
|
|
9
9
|
router: Router;
|
|
10
10
|
setRoute<V extends Validator>(method: ApiMethod, path: string, validate: Validate<V>, ...args: SetRouteArgs<V, AM, BA>): void;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getAppRouter = void 0;
|
|
4
4
|
const express_1 = require("express");
|
|
5
5
|
const call_controller_1 = require("./call-controller");
|
|
6
|
-
function getAppRouter(authConfig) {
|
|
6
|
+
function getAppRouter(appVersion, authConfig) {
|
|
7
7
|
return class AppRouter {
|
|
8
8
|
constructor(app, basePath) {
|
|
9
9
|
this.router = (0, express_1.Router)();
|
|
@@ -12,7 +12,7 @@ function getAppRouter(authConfig) {
|
|
|
12
12
|
setRoute(method, path, validate, ...args) {
|
|
13
13
|
const middlewares = args.slice(0, -1);
|
|
14
14
|
const controller = args[args.length - 1];
|
|
15
|
-
this.router[method](path, ...middlewares, (0, call_controller_1.callController)(controller, validate, authConfig));
|
|
15
|
+
this.router[method](path, ...middlewares, (0, call_controller_1.callController)(controller, validate, appVersion, authConfig));
|
|
16
16
|
}
|
|
17
17
|
get(path, validate, ...args) {
|
|
18
18
|
this.setRoute('get', path, validate, ...args);
|
|
@@ -2,4 +2,4 @@ import { BaseAuth } from '../authentication';
|
|
|
2
2
|
import type { AuthMap, AuthUsers } from '../authentication/authentication.types';
|
|
3
3
|
import type { RouteValidator, RouteValidate } from '../validator/validator.types';
|
|
4
4
|
import type { Controller, AuthConfig } from './router.types';
|
|
5
|
-
export declare function callController<V extends RouteValidator, AM extends AuthMap, AU extends AuthUsers<AM>, BA extends BaseAuth<AM>>(controller: Controller<V, AM, BA>, validate: RouteValidate<V>, authConfig: AuthConfig<AM, AU, BA>): (req: Req, res: Res) => Promise<void>;
|
|
5
|
+
export declare function callController<V extends RouteValidator, AM extends AuthMap, AU extends AuthUsers<AM>, BA extends BaseAuth<AM>>(controller: Controller<V, AM, BA>, validate: RouteValidate<V>, appVersion: string, authConfig: AuthConfig<AM, AU, BA>): (req: Req, res: Res) => Promise<void>;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.callController = void 0;
|
|
4
4
|
const http_status_codes_1 = require("http-status-codes");
|
|
5
5
|
// helpers
|
|
6
|
+
const helpers_1 = require("../helpers");
|
|
6
7
|
const pangea_helpers_1 = require("pangea-helpers");
|
|
7
8
|
// database
|
|
8
9
|
const database_1 = require("../database");
|
|
@@ -10,10 +11,13 @@ const database_1 = require("../database");
|
|
|
10
11
|
const authentication_1 = require("../authentication");
|
|
11
12
|
// validator
|
|
12
13
|
const validate_request_1 = require("../validator/validate-request");
|
|
13
|
-
function callController(controller, validate, authConfig) {
|
|
14
|
+
function callController(controller, validate, appVersion, authConfig) {
|
|
14
15
|
const { authMap, authCtor, accessToken } = authConfig;
|
|
15
16
|
return async function (req, res) {
|
|
16
17
|
const headers = req.headers;
|
|
18
|
+
if (appVersion !== headers['x-app-version']) {
|
|
19
|
+
helpers_1.AppError.Throw({ statusCodeName: 'BAD_REQUEST', errorCode: 'APP_VERSION_MISMATCH' });
|
|
20
|
+
}
|
|
17
21
|
const inputs = (0, validate_request_1.validateRequest)(validate, req);
|
|
18
22
|
const ctx = { headers, ...inputs, file: req.file, files: req.files };
|
|
19
23
|
const tx = await (0, database_1.getDbClient)().transaction();
|