node-server-engine 1.0.9 → 1.1.0

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,2 +1,4 @@
1
1
  import { Request, Response, NextFunction } from 'express';
2
- export declare const checkPermission: (requiredActions: string | string[]) => (req: Request, res: Response, next: NextFunction) => Response<any, Record<string, any>> | undefined;
2
+ declare const checkPermission: (requiredActions: string | string[]) => (req: Request, res: Response, next: NextFunction) => Response<any, Record<string, any>> | undefined;
3
+ export { checkPermission };
4
+ export default checkPermission;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.checkPermission = void 0;
6
+ exports.default = exports.checkPermission = void 0;
7
7
  // Middleware to check if the user has at least one of the required permissions (case-insensitive)
8
8
  const checkPermission = requiredActions => {
9
9
  return (req, res, next) => {
@@ -31,4 +31,5 @@ const checkPermission = requiredActions => {
31
31
  };
32
32
  };
33
33
  exports.checkPermission = checkPermission;
34
+ var _default = exports.default = checkPermission;
34
35
  //# sourceMappingURL=checkPermission.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"checkPermission.js","names":["checkPermission","requiredActions","req","res","next","user","permissions","status","json","message","requiredActionsArray","Array","isArray","requiredActionsLower","map","action","toLowerCase","hasPermission","some","permission","includes","exports"],"sources":["../../../src/middleware/checkPermission/checkPermission.ts"],"sourcesContent":["import { Request, Response, NextFunction } from 'express';\n\n// Middleware to check if the user has at least one of the required permissions (case-insensitive)\nexport const checkPermission = (requiredActions: string | string[]) => {\n return (req: Request, res: Response, next: NextFunction) => {\n const user = req.user;\n\n if (!user || !user.permissions) {\n return res.status(403).json({ message: 'User does not have permissions' });\n }\n\n // Normalize input to an array of strings\n const requiredActionsArray = Array.isArray(requiredActions)\n ? requiredActions\n : [requiredActions];\n\n // Normalize required actions to lowercase\n const requiredActionsLower = requiredActionsArray.map(action => action.toLowerCase());\n\n // Check if the user has any of the required permissions (case-insensitive)\n const hasPermission = user.permissions.some((permission: string) =>\n requiredActionsLower.includes(permission.toLowerCase())\n );\n\n if (!hasPermission) {\n return res.status(403).json({ message: 'Permission denied' });\n }\n\n next();\n };\n};\n"],"mappings":";;;;;;AAEA;AACO,MAAMA,eAAe,GAAIC,eAAkC,IAAK;EACrE,OAAO,CAACC,GAAY,EAAEC,GAAa,EAAEC,IAAkB,KAAK;IAC1D,MAAMC,IAAI,GAAGH,GAAG,CAACG,IAAI;IAErB,IAAI,CAACA,IAAI,IAAI,CAACA,IAAI,CAACC,WAAW,EAAE;MAC9B,OAAOH,GAAG,CAACI,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;QAAEC,OAAO,EAAE;MAAiC,CAAC,CAAC;IAC5E;;IAEA;IACA,MAAMC,oBAAoB,GAAGC,KAAK,CAACC,OAAO,CAACX,eAAe,CAAC,GACvDA,eAAe,GACf,CAACA,eAAe,CAAC;;IAErB;IACA,MAAMY,oBAAoB,GAAGH,oBAAoB,CAACI,GAAG,CAACC,MAAM,IAAIA,MAAM,CAACC,WAAW,CAAC,CAAC,CAAC;;IAErF;IACA,MAAMC,aAAa,GAAGZ,IAAI,CAACC,WAAW,CAACY,IAAI,CAAEC,UAAkB,IAC7DN,oBAAoB,CAACO,QAAQ,CAACD,UAAU,CAACH,WAAW,CAAC,CAAC,CACxD,CAAC;IAED,IAAI,CAACC,aAAa,EAAE;MAClB,OAAOd,GAAG,CAACI,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;QAAEC,OAAO,EAAE;MAAoB,CAAC,CAAC;IAC/D;IAEAL,IAAI,CAAC,CAAC;EACR,CAAC;AACH,CAAC;AAACiB,OAAA,CAAArB,eAAA,GAAAA,eAAA","ignoreList":[]}
1
+ {"version":3,"file":"checkPermission.js","names":["checkPermission","requiredActions","req","res","next","user","permissions","status","json","message","requiredActionsArray","Array","isArray","requiredActionsLower","map","action","toLowerCase","hasPermission","some","permission","includes","exports","_default","default"],"sources":["../../../src/middleware/checkPermission/checkPermission.ts"],"sourcesContent":["import { Request, Response, NextFunction } from 'express';\n\n// Middleware to check if the user has at least one of the required permissions (case-insensitive)\nconst checkPermission = (requiredActions: string | string[]) => {\n return (req: Request, res: Response, next: NextFunction) => {\n const user = req.user;\n\n if (!user || !user.permissions) {\n return res\n .status(403)\n .json({ message: 'User does not have permissions' });\n }\n\n // Normalize input to an array of strings\n const requiredActionsArray = Array.isArray(requiredActions)\n ? requiredActions\n : [requiredActions];\n\n // Normalize required actions to lowercase\n const requiredActionsLower = requiredActionsArray.map((action) =>\n action.toLowerCase()\n );\n\n // Check if the user has any of the required permissions (case-insensitive)\n const hasPermission = user.permissions.some((permission: string) =>\n requiredActionsLower.includes(permission.toLowerCase())\n );\n\n if (!hasPermission) {\n return res.status(403).json({ message: 'Permission denied' });\n }\n\n next();\n };\n};\n\nexport { checkPermission };\nexport default checkPermission;\n"],"mappings":";;;;;;AAEA;AACA,MAAMA,eAAe,GAAIC,eAAkC,IAAK;EAC9D,OAAO,CAACC,GAAY,EAAEC,GAAa,EAAEC,IAAkB,KAAK;IAC1D,MAAMC,IAAI,GAAGH,GAAG,CAACG,IAAI;IAErB,IAAI,CAACA,IAAI,IAAI,CAACA,IAAI,CAACC,WAAW,EAAE;MAC9B,OAAOH,GAAG,CACPI,MAAM,CAAC,GAAG,CAAC,CACXC,IAAI,CAAC;QAAEC,OAAO,EAAE;MAAiC,CAAC,CAAC;IACxD;;IAEA;IACA,MAAMC,oBAAoB,GAAGC,KAAK,CAACC,OAAO,CAACX,eAAe,CAAC,GACvDA,eAAe,GACf,CAACA,eAAe,CAAC;;IAErB;IACA,MAAMY,oBAAoB,GAAGH,oBAAoB,CAACI,GAAG,CAAEC,MAAM,IAC3DA,MAAM,CAACC,WAAW,CAAC,CACrB,CAAC;;IAED;IACA,MAAMC,aAAa,GAAGZ,IAAI,CAACC,WAAW,CAACY,IAAI,CAAEC,UAAkB,IAC7DN,oBAAoB,CAACO,QAAQ,CAACD,UAAU,CAACH,WAAW,CAAC,CAAC,CACxD,CAAC;IAED,IAAI,CAACC,aAAa,EAAE;MAClB,OAAOd,GAAG,CAACI,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;QAAEC,OAAO,EAAE;MAAoB,CAAC,CAAC;IAC/D;IAEAL,IAAI,CAAC,CAAC;EACR,CAAC;AACH,CAAC;AAACiB,OAAA,CAAArB,eAAA,GAAAA,eAAA;AAAA,IAAAsB,QAAA,GAAAD,OAAA,CAAAE,OAAA,GAGavB,eAAe","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-server-engine",
3
- "version": "1.0.9",
3
+ "version": "1.1.0",
4
4
  "description": "Framework used to develop backend services. This package ships with a lot of features to standardize the creation of services, letting you focus on the business logic.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,12 +1,14 @@
1
1
  import { Request, Response, NextFunction } from 'express';
2
2
 
3
3
  // Middleware to check if the user has at least one of the required permissions (case-insensitive)
4
- export const checkPermission = (requiredActions: string | string[]) => {
4
+ const checkPermission = (requiredActions: string | string[]) => {
5
5
  return (req: Request, res: Response, next: NextFunction) => {
6
6
  const user = req.user;
7
7
 
8
8
  if (!user || !user.permissions) {
9
- return res.status(403).json({ message: 'User does not have permissions' });
9
+ return res
10
+ .status(403)
11
+ .json({ message: 'User does not have permissions' });
10
12
  }
11
13
 
12
14
  // Normalize input to an array of strings
@@ -15,7 +17,9 @@ export const checkPermission = (requiredActions: string | string[]) => {
15
17
  : [requiredActions];
16
18
 
17
19
  // Normalize required actions to lowercase
18
- const requiredActionsLower = requiredActionsArray.map(action => action.toLowerCase());
20
+ const requiredActionsLower = requiredActionsArray.map((action) =>
21
+ action.toLowerCase()
22
+ );
19
23
 
20
24
  // Check if the user has any of the required permissions (case-insensitive)
21
25
  const hasPermission = user.permissions.some((permission: string) =>
@@ -29,3 +33,6 @@ export const checkPermission = (requiredActions: string | string[]) => {
29
33
  next();
30
34
  };
31
35
  };
36
+
37
+ export { checkPermission };
38
+ export default checkPermission;