aloux-iam 0.0.106 → 0.0.108

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.
@@ -16,15 +16,18 @@ self.create = async (data) => {
16
16
  }
17
17
  };
18
18
 
19
- self.response = async (_history, response, _createdBy) => {
19
+ self.response = async (_history, response, _createdBy, permission) => {
20
20
  try {
21
21
  if (_createdBy) {
22
22
  await History.updateOne(
23
23
  { _id: _history },
24
- { response: response, _createdBy: _createdBy }
24
+ { response: response, _createdBy: _createdBy, permission: permission }
25
25
  );
26
26
  } else {
27
- await History.updateOne({ _id: _history }, { response: response });
27
+ await History.updateOne(
28
+ { _id: _history },
29
+ { response: response, permission: permission }
30
+ );
28
31
  }
29
32
  return true;
30
33
  } catch (error) {
package/lib/middleware.js CHANGED
@@ -24,8 +24,15 @@ const auth = async (req, res, next) => {
24
24
  try {
25
25
  let newHistory;
26
26
  if (process.env.HISTORY === "true") {
27
- //Guardar registro en la colección del Historial
28
- newHistory = await historyController.create(req);
27
+ const endpoints = process.env.HISTORY_ENDPOINTS.split(",");
28
+ const urlToCheck = req.route.path;
29
+ const exists = endpoints.some((endpoint) =>
30
+ new RegExp(`^${endpoint}(/|\\?|$)`).test(urlToCheck)
31
+ );
32
+ if (exists) {
33
+ newHistory = await historyController.create(req);
34
+ req.history = newHistory._id.toString();
35
+ }
29
36
  }
30
37
 
31
38
  let token =
@@ -123,7 +130,7 @@ const auth = async (req, res, next) => {
123
130
 
124
131
  req.user = user;
125
132
  req.token = token;
126
- req.history = newHistory._id.toString();
133
+ req.permission = resource ? resource.description : "Recurso indefinido";
127
134
  next();
128
135
  } catch (error) {
129
136
  let obj = error;
@@ -3,7 +3,8 @@ const ObjectId = mongoose.Schema.Types.ObjectId;
3
3
 
4
4
  const historySchema = mongoose.Schema({
5
5
  method: { type: String, default: false },
6
- path: { type: String, default: true },
6
+ path: { type: String },
7
+ permission: { type: String },
7
8
  payload: { type: Object, default: {} }, // Guarda cualquier estructura JSON
8
9
  response: { type: Object, default: {} }, // Guarda cualquier estructura JSON
9
10
  _createdBy: { type: ObjectId, required: false, ref: "User" },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aloux-iam",
3
- "version": "0.0.106",
3
+ "version": "0.0.108",
4
4
  "description": "Aloux IAM for APIs ",
5
5
  "main": "index.js",
6
6
  "scripts": {