@nattyjs/core 0.0.1-beta.27 → 0.0.1-beta.29

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/index.cjs CHANGED
@@ -371,6 +371,7 @@ class BaseResult {
371
371
  }
372
372
 
373
373
  function getResponseBodyObject(body, props) {
374
+ const sensitiveProps = common.commonContainer.nattyConfig?.secure?.sensitiveProps;
374
375
  if (body instanceof common.List)
375
376
  return getResponseBodyObject(body.values, body.props);
376
377
  if (Array.isArray(body)) {
@@ -384,7 +385,8 @@ function getResponseBodyObject(body, props) {
384
385
  const keys = Object.keys(body);
385
386
  const getterProps = props ? Object.keys(props).map((key) => props[key]) : [];
386
387
  for (const key of [...keys, ...getterProps])
387
- jObject[key] = getResponseBodyObject(body[key]);
388
+ if (!sensitiveProps || sensitiveProps.filter((t) => t == key.toLowerCase()).length == 0)
389
+ jObject[key] = getResponseBodyObject(body[key]);
388
390
  return jObject;
389
391
  }
390
392
  return body;
@@ -871,6 +873,14 @@ class ActionExecutedContext extends AbstractExecutionContext {
871
873
  }
872
874
  }
873
875
 
876
+ class AuthorizationContext extends AbstractExecutionContext {
877
+ constructor(models, context, routeInfo, config) {
878
+ super(context, routeInfo);
879
+ this.models = models;
880
+ this.config = config;
881
+ }
882
+ }
883
+
874
884
  class RequestProcessor extends RouteParser {
875
885
  constructor() {
876
886
  super(...arguments);
@@ -881,9 +891,6 @@ class RequestProcessor extends RouteParser {
881
891
  case RequestPipeline.onAuthentication:
882
892
  await this.onAuthentication();
883
893
  break;
884
- case RequestPipeline.onAuthorization:
885
- await this.onAuthorization();
886
- break;
887
894
  }
888
895
  }
889
896
  resolveFilter(instance) {
@@ -909,21 +916,27 @@ class RequestProcessor extends RouteParser {
909
916
  this.httpContext.user = result;
910
917
  if (!result.isAuthenticate && !anonymousInfo.controllerConfig && !anonymousInfo.methodConfig)
911
918
  throw new UnauthorizedAccessException(authenticationFilter.onFailedResponse());
912
- await this.onAuthorization();
913
919
  }
914
920
  }
915
- async onAuthorization() {
921
+ async onAuthorization(methodParameters) {
916
922
  const authorization = common.commonContainer.globalConfig.authorization;
917
923
  const authorizationFilter = authorization ? this.resolveFilter(authorization) : void 0;
918
924
  const authorizeConfig = decoratorStateContainer.getInfo(this.routeInfo.controller.name, this.routeInfo.methodInfo.name, DecoratorType.authorize);
919
925
  const authenticationOnly = decoratorStateContainer.getInfo(this.routeInfo.controller.name, this.routeInfo.methodInfo.name, DecoratorType.authenticationOnly);
920
926
  if (this.httpContext.user?.isAuthenticate && authorizationFilter && (!authenticationOnly.controllerConfig && !authenticationOnly.methodConfig)) {
921
- const result = await authorizationFilter.onAuthorization(this.httpContext, authorizeConfig.methodConfig || authorizeConfig.controllerConfig);
927
+ const authorizationContext = new AuthorizationContext(
928
+ methodParameters.filter((t) => t instanceof ModelBindingContext),
929
+ this.httpContext,
930
+ this.routeInfo,
931
+ authorizeConfig.methodConfig || authorizeConfig.controllerConfig
932
+ );
933
+ const result = await authorizationFilter.onAuthorization(authorizationContext);
922
934
  if (!result)
923
935
  throw new ForbiddenAccessException(authorizationFilter.onFailedAuthorization());
924
936
  }
925
937
  }
926
938
  async onActionExecuting(methodParameters) {
939
+ await this.onAuthorization(methodParameters);
927
940
  let actionFilters = common.commonContainer.globalConfig.actionFilters || [];
928
941
  const actionFiltersConfig = decoratorStateContainer.getInfo(this.routeInfo.controller.name, this.routeInfo.methodInfo.name, DecoratorType.useFilter);
929
942
  actionFilters = [...actionFilters, ...actionFiltersConfig.controllerConfig?.actionFilters || [], ...actionFiltersConfig.methodConfig?.actionFilters || []];
package/dist/index.mjs CHANGED
@@ -369,6 +369,7 @@ class BaseResult {
369
369
  }
370
370
 
371
371
  function getResponseBodyObject(body, props) {
372
+ const sensitiveProps = commonContainer.nattyConfig?.secure?.sensitiveProps;
372
373
  if (body instanceof List)
373
374
  return getResponseBodyObject(body.values, body.props);
374
375
  if (Array.isArray(body)) {
@@ -382,7 +383,8 @@ function getResponseBodyObject(body, props) {
382
383
  const keys = Object.keys(body);
383
384
  const getterProps = props ? Object.keys(props).map((key) => props[key]) : [];
384
385
  for (const key of [...keys, ...getterProps])
385
- jObject[key] = getResponseBodyObject(body[key]);
386
+ if (!sensitiveProps || sensitiveProps.filter((t) => t == key.toLowerCase()).length == 0)
387
+ jObject[key] = getResponseBodyObject(body[key]);
386
388
  return jObject;
387
389
  }
388
390
  return body;
@@ -869,6 +871,14 @@ class ActionExecutedContext extends AbstractExecutionContext {
869
871
  }
870
872
  }
871
873
 
874
+ class AuthorizationContext extends AbstractExecutionContext {
875
+ constructor(models, context, routeInfo, config) {
876
+ super(context, routeInfo);
877
+ this.models = models;
878
+ this.config = config;
879
+ }
880
+ }
881
+
872
882
  class RequestProcessor extends RouteParser {
873
883
  constructor() {
874
884
  super(...arguments);
@@ -879,9 +889,6 @@ class RequestProcessor extends RouteParser {
879
889
  case RequestPipeline.onAuthentication:
880
890
  await this.onAuthentication();
881
891
  break;
882
- case RequestPipeline.onAuthorization:
883
- await this.onAuthorization();
884
- break;
885
892
  }
886
893
  }
887
894
  resolveFilter(instance) {
@@ -907,21 +914,27 @@ class RequestProcessor extends RouteParser {
907
914
  this.httpContext.user = result;
908
915
  if (!result.isAuthenticate && !anonymousInfo.controllerConfig && !anonymousInfo.methodConfig)
909
916
  throw new UnauthorizedAccessException(authenticationFilter.onFailedResponse());
910
- await this.onAuthorization();
911
917
  }
912
918
  }
913
- async onAuthorization() {
919
+ async onAuthorization(methodParameters) {
914
920
  const authorization = commonContainer.globalConfig.authorization;
915
921
  const authorizationFilter = authorization ? this.resolveFilter(authorization) : void 0;
916
922
  const authorizeConfig = decoratorStateContainer.getInfo(this.routeInfo.controller.name, this.routeInfo.methodInfo.name, DecoratorType.authorize);
917
923
  const authenticationOnly = decoratorStateContainer.getInfo(this.routeInfo.controller.name, this.routeInfo.methodInfo.name, DecoratorType.authenticationOnly);
918
924
  if (this.httpContext.user?.isAuthenticate && authorizationFilter && (!authenticationOnly.controllerConfig && !authenticationOnly.methodConfig)) {
919
- const result = await authorizationFilter.onAuthorization(this.httpContext, authorizeConfig.methodConfig || authorizeConfig.controllerConfig);
925
+ const authorizationContext = new AuthorizationContext(
926
+ methodParameters.filter((t) => t instanceof ModelBindingContext),
927
+ this.httpContext,
928
+ this.routeInfo,
929
+ authorizeConfig.methodConfig || authorizeConfig.controllerConfig
930
+ );
931
+ const result = await authorizationFilter.onAuthorization(authorizationContext);
920
932
  if (!result)
921
933
  throw new ForbiddenAccessException(authorizationFilter.onFailedAuthorization());
922
934
  }
923
935
  }
924
936
  async onActionExecuting(methodParameters) {
937
+ await this.onAuthorization(methodParameters);
925
938
  let actionFilters = commonContainer.globalConfig.actionFilters || [];
926
939
  const actionFiltersConfig = decoratorStateContainer.getInfo(this.routeInfo.controller.name, this.routeInfo.methodInfo.name, DecoratorType.useFilter);
927
940
  actionFilters = [...actionFilters, ...actionFiltersConfig.controllerConfig?.actionFilters || [], ...actionFiltersConfig.methodConfig?.actionFilters || []];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nattyjs/core",
3
- "version": "0.0.1-beta.27",
3
+ "version": "0.0.1-beta.29",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "ajayojha",
@@ -17,7 +17,7 @@
17
17
  "dependencies": {
18
18
  "tsyringe": "^4.7.0",
19
19
  "path-to-regexp": "6.2.1",
20
- "@nattyjs/common": "0.0.1-beta.27"
20
+ "@nattyjs/common": "0.0.1-beta.29"
21
21
  },
22
22
  "devDependencies": {
23
23
  "unbuild": "1.2.1"