@growy/strapi-plugin-encrypted-field 1.3.0 → 1.4.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.
@@ -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,8 +28,6 @@ const Input = (props) => {
28
28
  });
29
29
  };
30
30
 
31
- const charCount = value ? value.length : 0;
32
-
33
31
  return (
34
32
  <Field.Root
35
33
  name={name}
@@ -42,7 +40,7 @@ const Input = (props) => {
42
40
  {intlLabel?.id ? formatMessage(intlLabel) : intlLabel}
43
41
  </Field.Label>
44
42
  <Field.Input
45
- type="password"
43
+ type="text"
46
44
  placeholder={formatMessage({
47
45
  id: 'encrypted-field.placeholder',
48
46
  defaultMessage: 'Ingresa el texto a cifrar...',
@@ -51,11 +49,6 @@ const Input = (props) => {
51
49
  onChange={handleChange}
52
50
  disabled={disabled}
53
51
  />
54
- {charCount > 0 && (
55
- <Typography variant="pi" textColor="neutral600" marginTop={1}>
56
- {charCount} {charCount === 1 ? 'carácter' : 'caracteres'}
57
- </Typography>
58
- )}
59
52
  <Field.Hint />
60
53
  <Field.Error />
61
54
  </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.0",
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,47 @@ 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
+ result[key] = decrypt(value, strapi);
68
+ }
69
+ }
70
+ }
71
+ },
72
+
73
+ async afterFindMany(event) {
74
+ const { result } = event;
75
+ if (!result || !Array.isArray(result)) return;
76
+ if (!event.model?.uid) return;
77
+
78
+ const model = strapi.getModel(event.model.uid);
79
+
80
+ if (!model?.attributes) return;
81
+
82
+ for (const item of result) {
83
+ for (const [key, attribute] of Object.entries(model.attributes)) {
84
+ if (!isEncryptedField(attribute)) continue;
85
+ if (Object.prototype.hasOwnProperty.call(item, key)) {
86
+ const value = item[key];
87
+ if (typeof value === 'string' && value) {
88
+ item[key] = decrypt(value, strapi);
89
+ }
90
+ }
91
+ }
92
+ }
93
+ },
52
94
  });
53
95
  };