@growy/strapi-plugin-encrypted-field 2.0.0 → 2.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.
@@ -28,7 +28,7 @@ const Input = (props) => {
28
28
  });
29
29
  };
30
30
 
31
- // Extraer solo el nombre del campo sin prefijos
31
+
32
32
  const fieldName = name.includes('.') ? name.split('.').pop() : name;
33
33
  const label = intlLabel?.id ? formatMessage(intlLabel) : (intlLabel || fieldName);
34
34
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@growy/strapi-plugin-encrypted-field",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Campo personalizado de texto cifrado para Strapi",
5
5
  "strapi": {
6
6
  "name": "encrypted-field",
@@ -2,7 +2,7 @@ const { encrypt, decrypt, validateValue, isEncryptedField } = require('./utils/c
2
2
 
3
3
  module.exports = ({ strapi }) => {
4
4
 
5
- // Obtener tanto content types como componentes
5
+
6
6
  const contentTypes = Object.values(strapi.contentTypes);
7
7
  const components = Object.values(strapi.components);
8
8
  const allModels = [...contentTypes, ...components];
@@ -6,33 +6,33 @@ module.exports = (config, { strapi }) => {
6
6
 
7
7
  if (!ctx.body) return;
8
8
 
9
- // Función recursiva para descifrar campos en cualquier nivel de anidación
9
+
10
10
  const decryptRecursive = (obj, modelUid = null) => {
11
11
  if (!obj || typeof obj !== 'object') return;
12
12
 
13
- // Si es un array, procesar cada elemento
13
+
14
14
  if (Array.isArray(obj)) {
15
15
  obj.forEach(item => decryptRecursive(item, modelUid));
16
16
  return;
17
17
  }
18
18
 
19
- // Detectar si es un componente por el campo __component
19
+
20
20
  let currentModelUid = modelUid;
21
21
  if (obj.__component) {
22
22
  currentModelUid = obj.__component;
23
23
  }
24
24
 
25
- // Obtener el modelo si tenemos un UID
25
+
26
26
  let model = null;
27
27
  if (currentModelUid) {
28
28
  try {
29
29
  model = strapi.getModel(currentModelUid) || strapi.components[currentModelUid];
30
30
  } catch (e) {
31
- // Ignorar si no se encuentra el modelo
31
+
32
32
  }
33
33
  }
34
34
 
35
- // Descifrar campos del modelo actual
35
+
36
36
  if (model?.attributes) {
37
37
  for (const [key, attribute] of Object.entries(model.attributes)) {
38
38
  if (isEncryptedField(attribute) && obj[key] && typeof obj[key] === 'string') {
@@ -45,7 +45,7 @@ module.exports = (config, { strapi }) => {
45
45
  }
46
46
  }
47
47
 
48
- // Procesar recursivamente todos los valores del objeto
48
+
49
49
  for (const value of Object.values(obj)) {
50
50
  if (value && typeof value === 'object') {
51
51
  decryptRecursive(value, currentModelUid);
@@ -53,11 +53,11 @@ module.exports = (config, { strapi }) => {
53
53
  }
54
54
  };
55
55
 
56
- // Procesar ctx.body.data si existe
56
+
57
57
  if (ctx.body.data) {
58
58
  decryptRecursive(ctx.body.data);
59
59
  } else {
60
- // Procesar ctx.body directamente
60
+
61
61
  decryptRecursive(ctx.body);
62
62
  }
63
63
  };