@growy/strapi-plugin-encrypted-field 1.3.0 → 1.4.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.
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { useIntl } from 'react-intl';
3
- import { Field, Typography } from '@strapi/design-system';
3
+ import { Field } from '@strapi/design-system';
4
4
 
5
5
  const Input = (props) => {
6
6
  const {
@@ -28,7 +28,7 @@ const Input = (props) => {
28
28
  });
29
29
  };
30
30
 
31
- const charCount = value ? value.length : 0;
31
+ const label = intlLabel?.id ? formatMessage(intlLabel) : (intlLabel || name);
32
32
 
33
33
  return (
34
34
  <Field.Root
@@ -39,10 +39,10 @@ const Input = (props) => {
39
39
  required={required}
40
40
  >
41
41
  <Field.Label action={labelAction}>
42
- {intlLabel?.id ? formatMessage(intlLabel) : intlLabel}
42
+ {label}
43
43
  </Field.Label>
44
44
  <Field.Input
45
- type="password"
45
+ type="text"
46
46
  placeholder={formatMessage({
47
47
  id: 'encrypted-field.placeholder',
48
48
  defaultMessage: 'Ingresa el texto a cifrar...',
@@ -51,11 +51,6 @@ const Input = (props) => {
51
51
  onChange={handleChange}
52
52
  disabled={disabled}
53
53
  />
54
- {charCount > 0 && (
55
- <Typography variant="pi" textColor="neutral600" marginTop={1}>
56
- {charCount} {charCount === 1 ? 'carácter' : 'caracteres'}
57
- </Typography>
58
- )}
59
54
  <Field.Hint />
60
55
  <Field.Error />
61
56
  </Field.Root>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@growy/strapi-plugin-encrypted-field",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
4
  "description": "Campo personalizado de texto cifrado para Strapi",
5
5
  "strapi": {
6
6
  "name": "encrypted-field",
@@ -1,4 +1,4 @@
1
- const { encrypt, validateValue, isEncryptedField } = require('./utils/crypto');
1
+ const { encrypt, decrypt, validateValue, isEncryptedField } = require('./utils/crypto');
2
2
 
3
3
  module.exports = ({ strapi }) => {
4
4
  strapi.db.lifecycles.subscribe({
@@ -49,5 +49,48 @@ module.exports = ({ strapi }) => {
49
49
  }
50
50
  }
51
51
  },
52
+
53
+ async afterFindOne(event) {
54
+ const { result } = event;
55
+ if (!result) return;
56
+ if (!event.model?.uid) return;
57
+
58
+ const model = strapi.getModel(event.model.uid);
59
+
60
+ if (!model?.attributes) return;
61
+
62
+ for (const [key, attribute] of Object.entries(model.attributes)) {
63
+ if (!isEncryptedField(attribute)) continue;
64
+ if (Object.prototype.hasOwnProperty.call(result, key)) {
65
+ const value = result[key];
66
+ if (typeof value === 'string' && value) {
67
+ strapi.log.info(`Descifrando campo ${key} en ${event.model.uid}`);
68
+ result[key] = decrypt(value, strapi);
69
+ }
70
+ }
71
+ }
72
+ },
73
+
74
+ async afterFindMany(event) {
75
+ const { result } = event;
76
+ if (!result || !Array.isArray(result)) return;
77
+ if (!event.model?.uid) return;
78
+
79
+ const model = strapi.getModel(event.model.uid);
80
+
81
+ if (!model?.attributes) return;
82
+
83
+ for (const item of result) {
84
+ for (const [key, attribute] of Object.entries(model.attributes)) {
85
+ if (!isEncryptedField(attribute)) continue;
86
+ if (Object.prototype.hasOwnProperty.call(item, key)) {
87
+ const value = item[key];
88
+ if (typeof value === 'string' && value) {
89
+ item[key] = decrypt(value, strapi);
90
+ }
91
+ }
92
+ }
93
+ }
94
+ },
52
95
  });
53
96
  };