@modernlock/common 1.0.66 → 1.0.68

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/build/index.d.ts CHANGED
@@ -42,3 +42,4 @@ export * from "./mqtt/mqtt-wrapper";
42
42
  export * from "./things/commands";
43
43
  export * from "./@types/notification";
44
44
  export * from "./@types/express";
45
+ export * from "./middlewares/serviceAuth";
package/build/index.js CHANGED
@@ -58,3 +58,4 @@ __exportStar(require("./mqtt/mqtt-wrapper"), exports);
58
58
  __exportStar(require("./things/commands"), exports);
59
59
  __exportStar(require("./@types/notification"), exports);
60
60
  __exportStar(require("./@types/express"), exports);
61
+ __exportStar(require("./middlewares/serviceAuth"), exports);
@@ -1,4 +1,4 @@
1
1
  import { Request, Response, NextFunction } from "express";
2
2
  type Role = "superAdmin" | "developer" | "supportAgent";
3
- declare const verifyPermission: (role: Role[]) => (req: Request, res: Response, next: NextFunction) => void;
4
- export { verifyPermission };
3
+ declare const verifyAdminPermission: (role: Role[]) => (req: Request, res: Response, next: NextFunction) => void;
4
+ export { verifyAdminPermission };
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.verifyPermission = void 0;
3
+ exports.verifyAdminPermission = void 0;
4
4
  const authorization_error_1 = require("../errors/authorization-error");
5
- const verifyPermission = (role) => {
5
+ const verifyAdminPermission = (role) => {
6
6
  return (req, res, next) => {
7
7
  var _a;
8
8
  // if (!role.includes(req.user.role)) throw new AuthenticationError();
@@ -12,4 +12,4 @@ const verifyPermission = (role) => {
12
12
  next();
13
13
  };
14
14
  };
15
- exports.verifyPermission = verifyPermission;
15
+ exports.verifyAdminPermission = verifyAdminPermission;
@@ -0,0 +1,3 @@
1
+ import { NextFunction, Request, Response } from "express";
2
+ declare const authenticateTokenServices: (req: Request, res: Response, next: NextFunction) => Response<any, Record<string, any>> | undefined;
3
+ export { authenticateTokenServices };
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.authenticateTokenServices = void 0;
4
+ const jwtEncryption_1 = require("../utils/jwtEncryption");
5
+ const authenticateTokenServices = (req, res, next) => {
6
+ const authHeader = req.headers.authorization;
7
+ if (!authHeader || !authHeader.startsWith("Bearer ")) {
8
+ return res.status(401).json({ message: "Unauthorized: No token provided" });
9
+ }
10
+ const token = authHeader.split(" ")[1];
11
+ try {
12
+ const decoded = (0, jwtEncryption_1.jwtDecrypt)(token);
13
+ req.user = decoded; // attach user info to request
14
+ next();
15
+ }
16
+ catch (err) {
17
+ return res.status(403).json({ message: "Forbidden: Invalid or expired token" });
18
+ }
19
+ };
20
+ exports.authenticateTokenServices = authenticateTokenServices;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modernlock/common",
3
- "version": "1.0.66",
3
+ "version": "1.0.68",
4
4
  "main": "./build/index.js",
5
5
  "types": "./build/index.d.ts",
6
6
  "files": [