@aldb2b/common 1.0.696 → 1.0.697

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.
@@ -1,5 +1,6 @@
1
- import { Feature } from '../types/feature.interface';
2
- export declare function getEndpoint(features: Feature[], method: string, path: string): {
1
+ import { Feature } from "../types/feature.interface";
2
+ export declare function getEndpoint(features: Feature[], method: string, path: string, fromMiddleware?: boolean): {
3
3
  endpoint: any;
4
4
  feature: any;
5
+ exceptionResp: any;
5
6
  };
@@ -3,16 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getEndpoint = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
5
  const feature_mappings_1 = require("../types/feature-mappings");
6
- function getEndpoint(features, method, path) {
6
+ function getEndpoint(features, method, path, fromMiddleware) {
7
7
  let matchedEndpoint = undefined;
8
8
  let matchedFeature = undefined;
9
- features.find(feature => {
9
+ features.find((feature) => {
10
10
  const featureMappings = feature_mappings_1.FeatureMapping[feature.featureType];
11
- const hasPath = featureMappings?.findIndex(mapping => path.includes(mapping));
11
+ const hasPath = featureMappings?.findIndex((mapping) => {
12
+ return path.includes(mapping);
13
+ });
12
14
  if (hasPath > -1) {
13
15
  matchedFeature = feature;
14
- const endpoint = feature.endpoints.find(endpoint => {
15
- return endpoint.method === method && path.endsWith(endpoint.path);
16
+ const endpoint = feature.endpoints.find((endpoint) => {
17
+ return (endpoint.method === method &&
18
+ (path.endsWith(endpoint.path) ||
19
+ path.endsWith(endpoint.path.replace(/\/$/, ''))));
16
20
  });
17
21
  if (endpoint) {
18
22
  matchedEndpoint = endpoint;
@@ -21,24 +25,30 @@ function getEndpoint(features, method, path) {
21
25
  }
22
26
  });
23
27
  console.log('matchedFeature: ', matchedFeature);
28
+ console.log('matchedEndpoint: ', matchedEndpoint);
29
+ let exceptionResp = undefined;
24
30
  if (!matchedFeature) {
25
- throw new common_1.ForbiddenException({
31
+ exceptionResp = {
32
+ code: 'C-101',
26
33
  statusCode: 403,
27
34
  message: 'Forbidden feature',
28
35
  error: 'Forbidden',
29
36
  description: 'Please upgrade your subscription',
30
- });
37
+ };
31
38
  }
32
- if (matchedFeature.isActive === false ||
33
- matchedFeature.isActive === 'false') {
34
- throw new common_1.ForbiddenException({
39
+ if (matchedFeature.isActive === false) {
40
+ exceptionResp = {
41
+ code: 'C-102',
35
42
  statusCode: 403,
36
43
  message: 'Inactive feature',
37
44
  error: 'Forbidden',
38
45
  description: 'Please upgrade your subscription',
39
- });
46
+ };
47
+ }
48
+ if (fromMiddleware && exceptionResp) {
49
+ throw new common_1.ForbiddenException(exceptionResp);
40
50
  }
41
- return { endpoint: matchedEndpoint, feature: matchedFeature };
51
+ return { endpoint: matchedEndpoint, feature: matchedFeature, exceptionResp };
42
52
  }
43
53
  exports.getEndpoint = getEndpoint;
44
54
  //# sourceMappingURL=getEndpoint.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getEndpoint.js","sourceRoot":"","sources":["../../src/utils/getEndpoint.ts"],"names":[],"mappings":";;;AAAA,2CAAmD;AAEnD,gEAA0D;AAE1D,SAAgB,WAAW,CAAC,QAAmB,EAAE,MAAc,EAAE,IAAY;IAC3E,IAAI,eAAe,GAAG,SAAS,CAAA;IAC/B,IAAI,cAAc,GAAG,SAAS,CAAA;IAC9B,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;QACtB,MAAM,eAAe,GAAG,iCAAc,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;QAC3D,MAAM,OAAO,GAAG,eAAe,EAAE,SAAS,CAAC,OAAO,CAAC,EAAE,CACnD,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CACvB,CAAA;QACD,IAAI,OAAO,GAAG,CAAC,CAAC,EAAE,CAAC;YACjB,cAAc,GAAG,OAAO,CAAA;YACxB,MAAM,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;gBACjD,OAAO,QAAQ,CAAC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K,EAAE,WAAW;YAClB,WAAW,EAAE,kCAAkC;SAChD,CAAC;IACJ,CAAC;IAED,IAAI,cAAc,IAAI,aAAa,EAAE,CAAC;QACpC,MAAM,IAAI,2BAAkB,CAAC,aAAa,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,CAAC;AAC/E,CAAC;AAzDD,kCAyDC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aldb2b/common",
3
- "version": "1.0.696",
3
+ "version": "1.0.697",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",