@growy/strapi-plugin-encrypted-field 1.7.1 → 1.7.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@growy/strapi-plugin-encrypted-field",
3
- "version": "1.7.1",
3
+ "version": "1.7.3",
4
4
  "description": "Campo personalizado de texto cifrado para Strapi",
5
5
  "strapi": {
6
6
  "name": "encrypted-field",
@@ -4,40 +4,69 @@ module.exports = ({ strapi }) => {
4
4
 
5
5
  const models = Object.values(strapi.contentTypes);
6
6
 
7
+ strapi.log.info(`Total de modelos encontrados: ${models.length}`);
8
+
7
9
  models.forEach((model) => {
8
- const hasEncryptedFields = Object.values(model.attributes || {}).some(isEncryptedField);
10
+ const attributes = model.attributes || {};
11
+
12
+ // Debug: mostrar todos los campos del modelo
13
+ strapi.log.debug(`Modelo ${model.uid}: ${Object.keys(attributes).length} atributos`);
14
+
15
+ const encryptedFields = Object.entries(attributes)
16
+ .filter(([key, attr]) => {
17
+ const isEncrypted = isEncryptedField(attr);
18
+ if (attr.customField) {
19
+ strapi.log.debug(` - ${key}: customField = ${attr.customField}, isEncrypted = ${isEncrypted}`);
20
+ }
21
+ return isEncrypted;
22
+ })
23
+ .map(([key]) => key);
9
24
 
10
- if (!hasEncryptedFields) return;
25
+ if (encryptedFields.length === 0) return;
11
26
 
12
27
  const uid = model.uid;
13
28
 
14
- strapi.log.info(`Registrando lifecycles de cifrado para ${uid}`);
29
+ strapi.log.info(`✓ Registrando lifecycles de cifrado para ${uid} - Campos: ${encryptedFields.join(', ')}`);
15
30
 
16
31
 
17
32
  strapi.db.lifecycles.subscribe({
18
33
  models: [uid],
19
34
 
20
35
  async beforeCreate(event) {
36
+ const { data } = event.params;
37
+
38
+ strapi.log.info(`[beforeCreate] Evento recibido para ${event.model?.uid}`);
39
+ strapi.log.info(`[beforeCreate] Data recibida: ${JSON.stringify(data)}`);
40
+
21
41
  if (!event.model?.uid) return;
22
42
 
23
- const { data } = event.params;
24
43
  const currentModel = strapi.getModel(event.model.uid);
25
44
 
26
45
  if (!currentModel?.attributes) return;
27
46
 
28
47
  for (const [key, attribute] of Object.entries(currentModel.attributes)) {
29
48
  if (!isEncryptedField(attribute)) continue;
49
+
50
+ strapi.log.info(`[beforeCreate] Campo cifrado detectado: ${key}`);
51
+
30
52
  if (Object.prototype.hasOwnProperty.call(data, key)) {
31
53
  const value = data[key];
32
- if (value === null || value === undefined || value === '') continue;
54
+
55
+ strapi.log.info(`[beforeCreate] Valor del campo ${key}: ${value}`);
56
+
57
+ if (value === null || value === undefined || value === '') {
58
+ strapi.log.info(`[beforeCreate] Valor vacío, saltando cifrado`);
59
+ continue;
60
+ }
33
61
 
34
62
  const validation = validateValue(value, attribute);
35
63
  if (!validation.valid) {
36
64
  throw new Error(`Validación fallida para el campo "${key}": ${validation.error}`);
37
65
  }
38
66
 
39
- strapi.log.info(`Cifrando campo ${key} en ${event.model.uid}`);
67
+ strapi.log.info(`✓ Cifrando campo ${key} con valor: ${value}`);
40
68
  data[key] = encrypt(value, strapi);
69
+ strapi.log.info(`✓ Campo ${key} cifrado exitosamente`);
41
70
  }
42
71
  }
43
72
  },