aloux-iam 0.0.146 → 1.0.1

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.
@@ -79,6 +79,23 @@ self.escapeRegex = (str) => {
79
79
  return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
80
80
  };
81
81
 
82
+ // Sanitiza un objeto de filtros del cliente: solo permite keys sin $ y valores primitivos o anidados seguros
83
+ self.sanitizeFilters = (obj, depth = 0) => {
84
+ if (depth > 4 || obj === null || typeof obj !== 'object' || Array.isArray(obj)) return {};
85
+ const safe = {};
86
+ for (const [key, val] of Object.entries(obj)) {
87
+ if (key.startsWith('$')) continue;
88
+ if (val === null || val === undefined) continue;
89
+ if (typeof val === 'object' && !Array.isArray(val)) {
90
+ const nested = self.sanitizeFilters(val, depth + 1);
91
+ if (Object.keys(nested).length > 0) safe[key] = nested;
92
+ } else if (typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean') {
93
+ safe[key] = val;
94
+ }
95
+ }
96
+ return safe;
97
+ };
98
+
82
99
  self.hashToken = (token) => {
83
100
  const crypto = require('crypto');
84
101
  return crypto.createHash('sha256').update(String(token)).digest('hex');
@@ -158,7 +158,7 @@ self.get = async (req, res) => {
158
158
 
159
159
  self.retrieve = async (req, res) => {
160
160
  try {
161
- const { page, itemsPerPage, search } = req.query
161
+ const { page, itemsPerPage, search, filters: filtersRaw } = req.query
162
162
  const paginate = page != null && itemsPerPage != null
163
163
  const attributes = { pwd: 0, tokens: 0 }
164
164
  let query = {}
@@ -167,14 +167,28 @@ self.retrieve = async (req, res) => {
167
167
  const s = utils.escapeRegex(String(search))
168
168
  query.$or = [
169
169
  { name: { $regex: s, $options: 'i' } },
170
- { lastName: { $regex: s, $options: 'i' } }
170
+ { lastName: { $regex: s, $options: 'i' } },
171
+ { email: { $regex: s, $options: 'i' } },
172
+ { phone: { $regex: s, $options: 'i' } },
173
+ { 'phoneObj.e164': { $regex: s, $options: 'i' } },
174
+ { 'phoneObj.international': { $regex: s, $options: 'i' } },
171
175
  ]
172
176
  }
173
177
 
178
+ if (filtersRaw) {
179
+ try {
180
+ const parsed = typeof filtersRaw === 'string' ? JSON.parse(filtersRaw) : filtersRaw
181
+ Object.assign(query, utils.sanitizeFilters(parsed))
182
+ } catch (_) {}
183
+ }
184
+
174
185
  if (paginate) {
175
186
  const perPage = Math.min(Number(itemsPerPage), 100)
176
187
  const count = await User.countDocuments(query)
177
188
  const items = await User.find(query, attributes)
189
+ .populate({ path: '_functions', select: 'name' })
190
+ .populate({ path: '_business', select: 'name' })
191
+ .populate({ path: '_company', select: 'name' })
178
192
  .skip(perPage * (Number(page) - 1))
179
193
  .limit(perPage)
180
194
  .sort({ createdAt: -1 })
@@ -188,7 +202,9 @@ self.retrieve = async (req, res) => {
188
202
  }
189
203
 
190
204
  const result = await User.find(query, attributes)
191
- .populate([{ path: '_functions' }, { path: '_company' }, { path: '_business' }])
205
+ .populate({ path: '_functions', select: 'name' })
206
+ .populate({ path: '_business', select: 'name' })
207
+ .populate({ path: '_company', select: 'name' })
192
208
  .sort({ createdAt: -1 })
193
209
  .lean()
194
210
  res.status(200).send(result)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aloux-iam",
3
- "version": "0.0.146",
3
+ "version": "1.0.1",
4
4
  "description": "Aloux IAM for APIs ",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -17,7 +17,7 @@
17
17
  ],
18
18
  "author": "Aloux",
19
19
  "license": "MIT",
20
- "homepage": "https://github.com/alouxDeveloper/aloux-sdk#readme",
20
+ "homepage": "https://docs.aloux.mx/iam",
21
21
  "dependencies": {
22
22
  "bcryptjs": "^3.0.3",
23
23
  "cookie-parser": "^1.4.6",