@growy/strapi-plugin-encrypted-field 1.4.0 → 1.5.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.
@@ -28,6 +28,10 @@ const Input = (props) => {
28
28
  });
29
29
  };
30
30
 
31
+ // Extraer solo el nombre del campo sin prefijos
32
+ const fieldName = name.includes('.') ? name.split('.').pop() : name;
33
+ const label = intlLabel?.id ? formatMessage(intlLabel) : (intlLabel || fieldName);
34
+
31
35
  return (
32
36
  <Field.Root
33
37
  name={name}
@@ -37,7 +41,7 @@ const Input = (props) => {
37
41
  required={required}
38
42
  >
39
43
  <Field.Label action={labelAction}>
40
- {intlLabel?.id ? formatMessage(intlLabel) : intlLabel}
44
+ {label}
41
45
  </Field.Label>
42
46
  <Field.Input
43
47
  type="text"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@growy/strapi-plugin-encrypted-field",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "Campo personalizado de texto cifrado para Strapi",
5
5
  "strapi": {
6
6
  "name": "encrypted-field",
@@ -14,13 +14,20 @@ module.exports = ({ strapi }) => {
14
14
  if (!isEncryptedField(attribute)) continue;
15
15
  if (Object.prototype.hasOwnProperty.call(data, key)) {
16
16
  const value = data[key];
17
- if (value === null || value === undefined) continue;
17
+ if (value === null || value === undefined || value === '') continue;
18
+
19
+ // No cifrar si ya está cifrado (formato: iv:authTag:encrypted)
20
+ if (typeof value === 'string' && value.split(':').length === 3) {
21
+ strapi.log.info(`Campo ${key} ya está cifrado, saltando cifrado`);
22
+ continue;
23
+ }
18
24
 
19
25
  const validation = validateValue(value, attribute);
20
26
  if (!validation.valid) {
21
27
  throw new Error(`Validación fallida para el campo "${key}": ${validation.error}`);
22
28
  }
23
29
 
30
+ strapi.log.info(`Cifrando campo ${key} en ${event.model.uid}`);
24
31
  data[key] = encrypt(value, strapi);
25
32
  }
26
33
  }
@@ -38,13 +45,20 @@ module.exports = ({ strapi }) => {
38
45
  if (!isEncryptedField(attribute)) continue;
39
46
  if (Object.prototype.hasOwnProperty.call(data, key)) {
40
47
  const value = data[key];
41
- if (value === null || value === undefined) continue;
48
+ if (value === null || value === undefined || value === '') continue;
49
+
50
+ // No cifrar si ya está cifrado (formato: iv:authTag:encrypted)
51
+ if (typeof value === 'string' && value.split(':').length === 3) {
52
+ strapi.log.info(`Campo ${key} ya está cifrado, saltando cifrado`);
53
+ continue;
54
+ }
42
55
 
43
56
  const validation = validateValue(value, attribute);
44
57
  if (!validation.valid) {
45
58
  throw new Error(`Validación fallida para el campo "${key}": ${validation.error}`);
46
59
  }
47
60
 
61
+ strapi.log.info(`Cifrando campo ${key} en ${event.model.uid}`);
48
62
  data[key] = encrypt(value, strapi);
49
63
  }
50
64
  }
@@ -64,6 +78,7 @@ module.exports = ({ strapi }) => {
64
78
  if (Object.prototype.hasOwnProperty.call(result, key)) {
65
79
  const value = result[key];
66
80
  if (typeof value === 'string' && value) {
81
+ strapi.log.info(`Descifrando campo ${key} en ${event.model.uid}`);
67
82
  result[key] = decrypt(value, strapi);
68
83
  }
69
84
  }