pangea-server 3.3.42 → 3.3.44

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.
@@ -7,5 +7,5 @@ export type AuthUsers<AM extends AuthMap> = {
7
7
  [K in keyof AM]: InstanceType<AM[K]> | null;
8
8
  };
9
9
  export interface AuthCtor<AM extends AuthMap, AU extends AuthUsers<AM>, BA extends BaseAuth<AM>> {
10
- new (authUsers: AU): BA;
10
+ new (authUsers: AU, initRes: unknown): BA;
11
11
  }
@@ -12,7 +12,7 @@ const auth_1 = require("../auth");
12
12
  // validator
13
13
  const validate_request_1 = require("../validator/validate-request");
14
14
  function callController(controller, validate, appVersion, authConfig) {
15
- const { authMap, authCtor, accessToken } = authConfig;
15
+ const { authMap, authCtor, initAuthCtor, accessToken } = authConfig;
16
16
  return async function (req, res) {
17
17
  const reqId = (0, helpers_1.getRandomString)(6);
18
18
  (0, helpers_1.printInfo)(reqId, 'request started');
@@ -24,22 +24,19 @@ function callController(controller, validate, appVersion, authConfig) {
24
24
  const ctx = { headers, ...inputs, file: req.file, files: req.files };
25
25
  (0, helpers_1.printInfo)(reqId, 'request validated');
26
26
  const tx = await (0, database_1.getDbClient)().transaction();
27
- (0, helpers_1.printInfo)(reqId, 'transaction created');
28
27
  const db = new database_1.Db(tx);
29
28
  let result;
30
29
  try {
31
30
  const authUsers = await (0, auth_1.getUsersFromToken)(headers.authorization, db, accessToken, authMap);
32
- const auth = new authCtor(authUsers);
31
+ const auth = new authCtor(authUsers, initAuthCtor ? await initAuthCtor(headers) : undefined);
33
32
  (0, helpers_1.printInfo)(reqId, 'auth resolved');
34
33
  result = await controller(ctx, db, auth);
35
34
  (0, helpers_1.printInfo)(reqId, 'controller executed');
36
35
  await tx.commit();
37
- (0, helpers_1.printInfo)(reqId, 'transaction committed');
38
36
  }
39
37
  catch (err) {
40
38
  (0, helpers_1.printInfo)(reqId, 'controller error');
41
39
  await tx.rollback();
42
- (0, helpers_1.printInfo)(reqId, 'transaction rollback completed');
43
40
  throw err;
44
41
  }
45
42
  let data = result;
@@ -53,7 +50,6 @@ function callController(controller, validate, appVersion, authConfig) {
53
50
  totalCount: typeof totalCount === 'number' ? totalCount : null,
54
51
  successCode: (0, pangea_helpers_1.camelToUpperSnake)(controller.name),
55
52
  };
56
- (0, helpers_1.printInfo)(reqId, 'response ready');
57
53
  res.status(http_status_codes_1.StatusCodes.OK).json(jsonBody);
58
54
  (0, helpers_1.printInfo)(reqId, 'request finished');
59
55
  };
@@ -10,6 +10,7 @@ export type SetRouteArgs<V extends RouteValidator, AM extends AuthMap, BA extend
10
10
  export type AuthConfig<AM extends AuthMap, AU extends AuthUsers<AM>, BA extends BaseAuth<AM>> = {
11
11
  authMap: AM;
12
12
  authCtor: AuthCtor<AM, AU, BA>;
13
+ initAuthCtor?: (headers: ReqHeaders) => Promise<unknown>;
13
14
  accessToken: AccessToken;
14
15
  };
15
16
  export type SetRoutes = (app: App) => void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pangea-server",
3
3
  "description": "",
4
- "version": "3.3.42",
4
+ "version": "3.3.44",
5
5
  "files": [
6
6
  "dist"
7
7
  ],